Skip to content

Commit aaf5473

Browse files
authored
refactor: logging and enhance configuration management (#212)
2 parents 285dab9 + af787f2 commit aaf5473

31 files changed

+4467
-1626
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
plan
12
# ignore appimages
23
*AppImage
34
*.AppImage*

AGENTS.md

Lines changed: 147 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,165 @@ This file provides guidance to agents when working with code in this repository.
44

55
## General Guidelines
66

7-
1. Modern Python First: Use Python 3.12+ features extensively - built-in generics, pattern matching, and dataclasses.
8-
2. KISS Principle: Aim for simplicity and clarity. Avoid unnecessary abstractions or metaprogramming.
9-
3. DRY with Care: Reuse code appropriately but avoid over-engineering. Each command handler has single responsibility.
7+
1. Simple is better than complex.
8+
2. KISS (Keep It Simple, Stupid): Aim for simplicity and clarity. Avoid unnecessary abstractions or metaprogramming.
9+
3. DRY (Don't Repeat Yourself): Reuse code appropriately but avoid over-engineering. Each command handler has single responsibility.
10+
4. YAGNI (You Aren't Gonna Need It): Always implement things when you actually need them, never when you just foresee that you need them.
11+
5. Confirm understanding before making changes: If you're unsure about the purpose of a piece of code, ask for clarification rather than making assumptions.
1012

11-
## Test after any change
13+
## Project Overview
1214

13-
1. Activate venv before any test execution:
15+
**My Unicorn** is a Python 3.12+ CLI tool for managing AppImages on Linux. It installs, updates, and verifies AppImage applications from GitHub repositories with hash verification (SHA256/SHA512).
16+
17+
**Key Technologies:**
18+
19+
- Python 3.12+ with asyncio/aiohttp for async operations
20+
- Virtual environment (venv) for dependency isolation
21+
- pytest for testing with async support
22+
23+
**Architecture:**
24+
25+
- Command pattern: Each CLI command has a dedicated handler in `my_unicorn/commands/`
26+
- Catalog system: App definitions in `my_unicorn/catalog/` as JSON files
27+
28+
## Development Workflow
29+
30+
**Running the application:**
31+
32+
```bash
33+
# Direct execution (development mode)
34+
python run.py --help
35+
python run.py install appflowy
36+
python run.py update appflowy
37+
```
38+
39+
**Available commands:**
40+
41+
- `install <app>` - Install an AppImage
42+
- `update <app>` - Update an installed AppImage
43+
- `remove <app>` - Remove an installed AppImage
44+
- `list` - List installed AppImages
45+
- `upgrade` - Upgrade all installed AppImages
46+
- `backup` - Backup configuration
47+
- `config` - Manage configuration
48+
- `cache` - Manage cache
49+
50+
## Testing Instructions
51+
52+
**Always activate venv before testing:**
1453

1554
```bash
1655
source .venv/bin/activate
1756
```
1857

19-
2. Run pytest with following command to ensure all tests pass:
58+
**Run all tests:**
2059

2160
```bash
2261
pytest -v -q --strict-markers
2362
```
2463

25-
## Run the application
64+
**Run specific test file:**
2665

2766
```bash
28-
python run.py --help
29-
python run.py install appflowy
30-
python run.py update appflowy
67+
pytest tests/test_config.py -v
68+
```
69+
70+
**Run specific test function:**
71+
72+
```bash
73+
pytest tests/test_config.py::test_function_name -v
3174
```
75+
76+
**Test patterns:**
77+
78+
- Test files: `tests/test_*.py`
79+
- Test functions: `def test_*()`
80+
- Async tests: Use `pytest-asyncio` with `@pytest.mark.asyncio`
81+
- Mock external calls: Use `pytest-mock` and `aioresponses`
82+
83+
**Critical: Run tests after any change to ensure nothing breaks.**
84+
85+
## Code Style Guidelines
86+
87+
**Language:** Python 3.12+
88+
89+
**Code Formatting (Ruff):**
90+
91+
```bash
92+
# Check formatting
93+
ruff check .
94+
95+
# Auto-fix issues
96+
ruff check --fix .
97+
98+
# Format code
99+
ruff format .
100+
```
101+
102+
**Style Rules:**
103+
104+
- Follow PEP 8 strictly
105+
- Max line length: 79 characters
106+
- Use double quotes for strings
107+
- Use spaces (not tabs) for indentation
108+
- Include type hints for all functions
109+
- Use Google-style docstrings
110+
111+
**Type Annotations:**
112+
113+
- Use built-in types: `list[str]`, `dict[str, int]` (not `List`, `Dict`)
114+
- Use `from typing import TYPE_CHECKING` for imports only used in type hints
115+
116+
**Docstring Format (Google Style):**
117+
118+
```python
119+
def function_name(param1: str, param2: int) -> bool:
120+
"""Brief description.
121+
122+
Longer description if needed.
123+
124+
Args:
125+
param1: Description of param1.
126+
param2: Description of param2.
127+
128+
Returns:
129+
Description of return value.
130+
131+
Raises:
132+
ValueError: When something goes wrong.
133+
"""
134+
```
135+
136+
**Logging:**
137+
138+
- Use `%s` style formatting in logging: `logger.info("Message: %s", value)`
139+
- Never use f-strings in logging statements
140+
141+
**Project Conventions:**
142+
143+
- Each command handler inherits from `BaseCommand`
144+
- Services handle business logic, commands handle CLI interaction
145+
- Use async/await for I/O operations (network, file system)
146+
- my-unicorn source code stored in `~/.local/share/my-unicorn/`
147+
- Configuration stored in `~/.config/my-unicorn/`
148+
149+
## Common Development Tasks
150+
151+
**Adding a new command:**
152+
153+
1. Create handler in `my_unicorn/commands/`
154+
2. Inherit from `BaseCommand`
155+
3. Implement `execute()` method
156+
4. Register in CLI parser
157+
5. Add tests in `tests/commands/`
158+
159+
**Debugging:**
160+
161+
- Check logs in `~/.config/my-unicorn/logs/`
162+
- Use `--verbose` flag for detailed output
163+
164+
## Additional Notes
165+
166+
**External dependencies:** Managed via `pyproject.toml`
167+
168+
**Binary location:** `~/.local/bin/my-unicorn`

0 commit comments

Comments
 (0)