Skip to content

Commit f0b62ce

Browse files
GeneAIclaude
authored andcommitted
feat: Add Windows compatibility support
Add cross-platform utilities and guidelines to ensure the Empathy Framework works correctly on Windows, macOS, and Linux. Changes: - Add platform_utils.py module with: - Platform detection (is_windows, is_macos, is_linux) - Platform-appropriate directories (logs, data, config, cache) - Asyncio Windows event loop policy handling - UTF-8 file utilities - Path normalization helpers - Fix hardcoded Unix paths: - audit_logger.py: Use platform-appropriate default log directory - cli.py: Call setup_asyncio_policy() at startup - Add cross-platform coding guidelines to python-standards.md: - File path handling with pathlib - UTF-8 encoding for text files - Asyncio policy setup for Windows - Testing guidance for multi-platform - Add check_platform_compat.py script for CI integration: - Detects hardcoded paths, missing encoding, asyncio issues - JSON output for CI parsing - --strict mode for blocking builds - Add comprehensive tests (40 tests in test_platform_utils.py) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 7d7a4e7 commit f0b62ce

File tree

6 files changed

+1169
-12
lines changed

6 files changed

+1169
-12
lines changed

.claude/python-standards.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,80 @@
44
- Follow PEP 8
55
- Write docstrings
66
- Target 90%+ test coverage
7+
8+
## Cross-Platform Compatibility
9+
10+
The Empathy Framework must work on Windows, macOS, and Linux. Follow these guidelines:
11+
12+
### File Paths
13+
14+
- **Always use `pathlib.Path`** instead of string concatenation for paths
15+
- **Never hardcode path separators** (`/` or `\`)
16+
- **Use `empathy_os.platform_utils`** for OS-specific directories:
17+
18+
```python
19+
from empathy_os.platform_utils import get_default_log_dir, get_default_data_dir
20+
21+
# Good: Platform-appropriate paths
22+
log_dir = get_default_log_dir() # ~/Library/Logs/empathy on macOS, %APPDATA%/empathy/logs on Windows
23+
24+
# Bad: Hardcoded Unix path
25+
log_dir = Path("/var/log/empathy")
26+
```
27+
28+
### File Encoding
29+
30+
- **Always specify `encoding="utf-8"`** when opening text files:
31+
32+
```python
33+
# Good
34+
with open(path, "r", encoding="utf-8") as f:
35+
content = f.read()
36+
37+
# Bad (Windows defaults to cp1252)
38+
with open(path, "r") as f:
39+
content = f.read()
40+
```
41+
42+
- Use `empathy_os.platform_utils.read_text_file()` and `write_text_file()` for convenience
43+
44+
### Asyncio
45+
46+
- **Call `setup_asyncio_policy()`** before any `asyncio.run()` in CLI entry points:
47+
48+
```python
49+
from empathy_os.platform_utils import setup_asyncio_policy
50+
51+
def main():
52+
setup_asyncio_policy() # Required for Windows compatibility
53+
asyncio.run(async_main())
54+
```
55+
56+
- Windows requires `WindowsSelectorEventLoopPolicy` for compatibility with many libraries
57+
58+
### Line Endings
59+
60+
- Git handles line endings via `.gitattributes`
61+
- When writing files programmatically, use `\n` (Git will convert on checkout)
62+
63+
### Environment Variables
64+
65+
- Use `os.environ.get()` with sensible defaults
66+
- Remember Windows uses different variable names (`%APPDATA%` vs `$HOME`)
67+
68+
### Subprocess Calls
69+
70+
- Use `subprocess.run()` with `shell=False` when possible
71+
- Avoid shell-specific syntax (pipes, redirects) in subprocess calls
72+
- Use `shlex.split()` on Unix, but note it doesn't work on Windows
73+
74+
### Testing
75+
76+
- Mock `platform.system()` to test all OS paths:
77+
78+
```python
79+
with patch("platform.system", return_value="Windows"):
80+
assert is_windows() is True
81+
```
82+
83+
- Run tests on all platforms via CI (see `.github/workflows/tests.yml` - runs on ubuntu, macos, windows)

0 commit comments

Comments
 (0)