A cross-platform compatibility checker for Python code - detects Windows/Linux/macOS incompatibilities
Project description
PyCrossCheck
A cross-platform compatibility checker for Python code
PyCrossCheck automatically detects platform-specific code that may cause issues on Windows, Linux, or macOS, and provides intelligent suggestions for cross-platform alternatives.
Features
- Cross-Platform Detection: Identifies Windows, Linux, and macOS-specific code that may break on other platforms
- Smart Suggestions: Provides clear, actionable recommendations with cross-platform alternatives
- Comprehensive Analysis: 56+ rules organized in 10 categories covering file system, process management, user operations, and more
- Easy Integration: Simple CLI interface and JSON output for CI/CD pipelines
- Bandit Plugin: Extends Bandit static analysis with platform compatibility checks
Installation
From PyPI (Recommended)
pip install pycrosscheck
From Source
# Clone the repository
git clone https://github.com/yourusername/pycrosscheck.git
cd pycrosscheck
# Install in development mode
pip install -e .
Quick Start
Basic Usage
After installation, you can use the pycrosscheck or pycc command:
# Check a single file
pycrosscheck detect myfile.py
# Check an entire project recursively
pycrosscheck detect -r myproject/
# Check with different output formats
pycrosscheck detect --format json myfile.py
pycrosscheck detect --format csv myfile.py
View All Rules
# Display all available compatibility rules
pycrosscheck rules
📖 Usage Examples
Example 1: Check a Python File
pycrosscheck detect script.py
Sample output:
🔍 Detecting Windows compatibility issues...
💡 This tool will provide suggestions for cross-platform alternatives.
Test results:
>> Issue: [PTB001:os_windows_incompatible_functions] Windows-incompatible function: os.getuid()
Severity: Medium Confidence: High
Location: script.py:15
More Info: https://bandit.readthedocs.io/en/latest/
💡 Suggestion: Replace with getpass.getuser() - Works on Windows, Linux, and macOS.
Example 2: Check Entire Project
pycc detect -r ./myproject
Example 3: CI/CD Integration
# Generate JSON report for automated processing
pycrosscheck detect -r . --format json > compatibility_report.json
Example 4: Using with Bandit Directly
Since PyCrossCheck is a Bandit plugin, you can also use it with Bandit:
bandit -r myproject/ -t PTB001
📋 Compatibility Rules Categories
PyCrossCheck includes 56+ rules organized into 10 categories:
| Category | Description | Rules |
|---|---|---|
| 02 | Process Management | 14 rules |
| 03 | User and Group Management | 11 rules |
| 04 | File System Operations | 11 rules |
| 05 | Signal Handling | 5 rules |
| 06 | Inter-Process Communication | 3 rules |
| 07 | System Information | 4 rules |
| 08 | Terminal Control | 1 rule |
| 09 | Device-Specific Operations | 4 rules |
| 10 | Priority and Scheduling | 3 rules |
Examples of Detected Issues
User Management Functions
Problematic code:
import os
# Will fail on Windows
user_id = os.getuid()
effective_user = os.geteuid()
✅ PyCrossCheck suggestion:
💡 Replace with getpass.getuser() - Works on Windows, Linux, and macOS.
Import: 'import getpass'
Fixed code:
import getpass
# Cross-platform solution
username = getpass.getuser()
❌ System Information
Problematic code:
import os
# Will fail on Windows
system_info = os.uname()
PyCrossCheck suggestion:
💡 Replace with platform.uname() for cross-platform system information.
Import: 'import platform'
Fixed code:
import platform
# Cross-platform solution
system_info = platform.uname()
❌ Process Management
Problematic code:
import os
# Will fail on Windows
pid = os.fork()
PyCrossCheck suggestion:
💡 Replace with multiprocessing.Process() for cross-platform process creation.
Import: 'from multiprocessing import Process'
Fixed code:
from multiprocessing import Process
def worker():
# Your code here
pass
# Cross-platform solution
process = Process(target=worker)
process.start()
🛡️ CI/CD Integration
GitHub Actions Example
name: Compatibility Check
on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: Install PyCrossCheck
run: pip install pycrosscheck
- name: Run compatibility check
run: pycrosscheck detect -r . --format json
Pre-commit Hook
Add to .pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: pycrosscheck
name: PyCrossCheck
entry: pycrosscheck detect
language: system
types: [python]
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
This project is licensed under the BSD 2-Clause License - see the LICENSE file for details.
🙏 Acknowledgments
- Built on top of Bandit security analysis tool
- Inspired by the need for better cross-platform Python code
📞 Support
- Issues: GitHub Issues
- Documentation: GitHub README
Made with ❤️ for the Python community
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycrosscheck-1.0.1.tar.gz.
File metadata
- Download URL: pycrosscheck-1.0.1.tar.gz
- Upload date:
- Size: 32.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c6ccafbed8f5d98243ea659e12d2e7dbd63bf07d51676627ef777613d3137e6
|
|
| MD5 |
69ecd68004db32e459ad20176ce8e862
|
|
| BLAKE2b-256 |
8501afa22bd5a3e3ba4ac8643c9c4894a6f95e19d6853001d96ba11bb7d13fe5
|
File details
Details for the file pycrosscheck-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pycrosscheck-1.0.1-py3-none-any.whl
- Upload date:
- Size: 38.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a51bd8b4e09fe0fa416838578930e4cdbc3c0ec65de80a6dcbe2a04f3d455b6
|
|
| MD5 |
dd074e67353e77be5cb09ddcaf2cad0c
|
|
| BLAKE2b-256 |
c86d4952c68ce6ade026b528cc609d0403bbc7efa415640a8e5f0777f59f986b
|