terry.King

Python包鸿蒙兼容性测试技能

开发编程v1.0.1
作者:terry.King更新于 2026-05-18共 2 个版本 · 最新版本发布于 2026-03-09python-harmony-compatibility-checker@clawhub_terryking1992/python-harmony-compatibility-checker
测试生成脚本工具#GitHub

据 AlphaMoat 统计,截至 2026-09,Python包鸿蒙兼容性测试技能 累计下载 1,615 次、获 0 个星标,在全部 5,078 个 AI 技能中排名第 4,694 位,在「开发编程」分类(577 个)中排名第 553 位。

累计安装
214
累计下载
1,615
星标
-
全站排名
#4,694
全站前 93% · 「开发编程」前 96%
平台累计安装累计下载星标评论
ClawHub ↗341,274--
SkillHub ↗2141,615-—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

该技能描述从 GitHub 或 PyPI 获取源码、检测平台相关依赖并运行测试,随后生成兼容性报告。结果取决于项目、测试和运行环境;本简介不表示某个库已通过验证。

资料发布于 2026-10-27

可以用来做什么

  • 检查 Python 包的系统兼容性
  • 为迁移前整理依赖与测试结果

什么时候用

  • 需要评估 Python 包能否在 HarmonyOS 使用时
  • 部署或迁移前需要检查依赖兼容性时

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

检查这个 Python 包在 HarmonyOS 上的兼容性
列出可能依赖 Windows 专用接口的部分

月度数据趋势

累计下载1,615
3851,0461,7062026-03 · 累计下载 4762026-05 · 累计下载 8122026-06 · 累计下载 9482026-07 · 累计下载 1,1532026-08 · 累计下载 1,3142026-09 · 累计下载 1,61526-0326-09
星标-
0112026-03 · 星标 -2026-05 · 星标 -2026-06 · 星标 -2026-07 · 星标 -2026-08 · 星标 -2026-09 · 星标 -26-0326-09

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-091,615—-
2026-081,314+14.0%-
2026-071,153+21.6%-
2026-06948+16.7%-
2026-05812—-
2026-03476—-

SKILL.md 原文

以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。

6.3 KB · ClawHub v1.0.1
---
name: python-harmony-compatibility-checker
description: Check Python library compatibility with HarmonyOS. Downloads source from GitHub/PyPI, detects Windows-specific dependencies, runs pytest with per-test-case reporting, and generates detailed compatibility reports.
---

# Python HarmonyOS Compatibility Checker

## When to Use

- Check if a Python package works on HarmonyOS
展开全部(共 217 行)
- Validate multiple packages before deployment
- Migrate a Python project to HarmonyOS
- Detect Windows-specific API dependencies (win32api, pythoncom, pywin32, etc.)

## Usage

```bash
# Single package
python scripts/check_compatibility.py requests

# Multiple packages (parallel, 4 workers default)
python scripts/check_compatibility.py requests numpy pandas flask

# Specify workers
python scripts/check_compatibility.py --workers 8 requests numpy pandas

# From requirements file
python scripts/check_compatibility.py -r requirements.txt
python scripts/check_compatibility.py -w 8 -r requirements.txt

# Sequential mode (debugging)
python scripts/check_compatibility.py --sequential requests numpy

# Keep downloaded source for verification
python scripts/check_compatibility.py --keep-source numpy
```

### Options

| Option | Description | Default |
|--------|-------------|---------|
| `-w, --workers N` | Number of parallel workers | 4 |
| `--sequential` | Run checks one at a time | False |
| `-r, --requirements FILE` | Check packages from requirements file | - |
| `--keep-source` | Keep downloaded source code for verification | False |

## Output

Reports saved to current directory:
- `compatibility_report_*.md` - Markdown with summary and details
- `compatibility_report_*.json` - Machine-readable with per-test-case results

Timestamps use **东八区时间 (UTC+8/北京时间)**.

### Example (numpy)

```
📦 numpy v2.2.1
   Status: ✅ Compatible
   Test Pass Rate: 88.9%
   Total: 45 tests | Passed: 40 | Failed: 5
```

### Metrics

| Metric | Description |
|--------|-------------|
| **Total Tests** | Individual test functions run |
| **Passed** | Successfully completed |
| **Failed** | Failed due to code issues |
| **Environment Issues** | Permission/temp dir failures (not counted) |
| **Pass Rate** | `passed / total` |
| **Valid Pass Rate** | `passed / (passed + failed)` - excludes environment issues |

## Test Workflow

1. **Download Source** - GitHub (preferred) or PyPI
2. **Windows Check** - Scan for Windows-specific imports (win32api, pythoncom, pywin32, ctypes.windll)
   - Found → **Incompatible** (no further testing)
3. **Find Tests** - From installed package (preferred) or source
4. **Run Tests** - pytest with verbose output, per-function reporting
5. **Analyze** - Categorize: environment issues vs code issues
6. **Report** - Markdown + JSON with detailed results

### Status

| Status | Criteria |
|--------|----------|
| **✅ Compatible** | Installs + valid pass rate ≥ 80% + no Windows deps |
| **⚠️ Partial** | Installs + valid pass rate 50-79% |
| **❌ Incompatible** | Cannot install OR valid pass rate < 50% OR Windows deps detected |

### Error Classification

| Type | Description | Counts Against |
|------|-------------|----------------|
| **Environment** | Permission errors, temp dir issues | ❌ No |
| **Code** | Import errors, API incompatibilities | ✅ Yes |
| **Platform** | Windows/macOS/X11 dependencies | ✅ Yes |

## Known Issues

### Platform Dependencies

| Platform | Problematic Packages | Alternative |
|----------|---------------------|-------------|
| Windows | pywin32, wmi, pythoncom, **xlwings** | Cross-platform libs |
| macOS | applescript, quartz, cocoa | - |
| X11 | python-xlib, xcb | pynput |

### Windows Module Detection

Scans for: `win32api`, `win32con`, `win32gui`, `win32com`, `pythoncom`, `pywintypes`, `ctypes.windll`, `winsound`, `msvcrt`

**Detection includes:**
- Direct imports: `import win32api`, `from win32com import ...`
- Dynamic imports: `importlib.import_module('pythoncom')`
- ctypes Windows DLL: `ctypes.windll`, `ctypes.WinDLL`
- References in setup.py, pyproject.toml

### Compatible Packages

- `requests`, `numpy` (45 tests, 88.9%), `pandas`, `flask`, `django`, `pytest`, `beautifulsoup4`, `pillow`

## Scripts

### check_compatibility.py

**Features:**
- Source download from GitHub/PyPI
- Windows dependency detection
- Test discovery from installed package or source
- pytest integration with per-test-case reporting
- Environment issue detection
- Source code retention (`--keep-source`)

**pytest Integration:**
- Uses `pytest -v --tb=short --import-mode=importlib`
- Runs from `/tmp` to avoid source import conflicts
- Parses output for individual test function results
- Limits to 15 test files, shows progress every 5 files

## Troubleshooting

### Permission Errors

```bash
# Clean up pytest temp directories
rm -rf pytest-of-*
```

### Source Verification

```bash
# Keep source for inspection
python scripts/check_compatibility.py --keep-source xlwings

# Check Windows imports
grep -r "import win32" /path/to/source/
```

### False Positives

Some failures may be due to:
- Missing optional system libraries
- Network-dependent tests
- pytest configuration issues

Review detailed reports to distinguish real incompatibilities from environment issues.

## Integration

### CI/CD

```yaml
- name: HarmonyOS Compatibility
  run: python scripts/check_compatibility.py -r requirements.txt --keep-source
```

### Programmatic

```python
from scripts.check_compatibility import check_package
result = check_package("requests")
print(f"Compatible: {result.compatible}, Issues: {result.issues}")
```

## Limitations

- Binary dependencies may fail to compile
- Some packages require system-level dependencies
- Pure HarmonyOS (NEXT) has stricter security policies
- Not all packages have unit tests
- Network required for source download

## Related

- `references/python-env-setup.md` - Python setup on HarmonyOS
- `references/compatibility-database.md` - Known package status

## Best Practices

### For Users

1. Review error classifications (environment vs code)
2. Use `--keep-source` to verify tested code
3. Run multiple times for transient failures
4. Check Windows dependencies first

### For Authors

1. Include tests in your package
2. Use pytest
3. Avoid platform-specific tests (or use `@pytest.mark.skipif`)
4. Document system dependencies
5. Use conditional imports: `if sys.platform == 'win32'`

「开发编程」分类下的热门技能

数据月份:2026-09 · 下载/星标/安装数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。