refactor
This commit is contained in:
@@ -16,7 +16,7 @@ uv sync
|
||||
### Code Quality
|
||||
- **Linting and formatting**: `uv run ruff check --fix` and `uv run ruff format`
|
||||
- **Type checking**: `uv run mypy .`
|
||||
- **Combined linting**: `uv run invoke lint` (runs ruff check, ruff format --check, and mypy)
|
||||
- **Combined linting**: `uv run invoke lint`
|
||||
|
||||
### Testing
|
||||
- **Run tests**: `uv run pytest`
|
||||
@@ -26,18 +26,7 @@ uv sync
|
||||
- **Clean untracked files**: `uv run invoke clean` (interactive)
|
||||
- **Version bumping**: `uv run bump-my-version bump [patch|minor|major]`
|
||||
|
||||
## Code Architecture
|
||||
|
||||
### Core Components (`src/{{ cookiecutter.package_name }}/core.py`)
|
||||
|
||||
The library implements the main functionality in the core module. Update this section with:
|
||||
|
||||
1. **Key Classes**: Describe main classes and their responsibilities
|
||||
2. **Core Functions**: Document important functions and their purpose
|
||||
3. **Data Flow**: Explain how data flows through the system
|
||||
4. **Dependencies**: List and explain key dependencies
|
||||
|
||||
### Project Structure
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
src/{{ cookiecutter.package_name }}/
|
||||
@@ -54,16 +43,7 @@ tests/
|
||||
|
||||
## Development Notes
|
||||
|
||||
- Uses Python {{ cookiecutter.python_version }}+ with modern type hints (PEP 604)
|
||||
- Uses Python {{ cookiecutter.python_version }}+ with modern type hints
|
||||
- Configured with ruff for linting/formatting and mypy for type checking
|
||||
- Built with uv for dependency management
|
||||
- Includes invoke tasks for common operations
|
||||
- Version {{ cookiecutter.version }} ({{ cookiecutter.year }})
|
||||
|
||||
## Implementation Guidelines
|
||||
|
||||
- Follow test-driven development practices
|
||||
- Use descriptive function names and one-liner docstrings for non-trivial functions
|
||||
- Keep files between 300–500 lines where possible
|
||||
- Don't duplicate code; build upon existing implementations
|
||||
- Always use type hints as supported by Python {{ cookiecutter.python_version }}+
|
||||
- Includes invoke tasks for common operations
|
||||
@@ -45,9 +45,10 @@ uv run pytest
|
||||
## Usage
|
||||
|
||||
```python
|
||||
from {{ cookiecutter.package_name }} import hello
|
||||
from {{ cookiecutter.package_name }}.core import say_hello
|
||||
|
||||
print(hello())
|
||||
say_hello() # prints: Hello, World!
|
||||
say_hello("Alice") # prints: Hello, Alice!
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
"""Basic usage example for {{ cookiecutter.project_name }}."""
|
||||
|
||||
from {{ cookiecutter.package_name }} import hello
|
||||
from {{ cookiecutter.package_name }}.core import process_data, {{ cookiecutter.project_name.replace(' ', '').replace('-', '') }}
|
||||
from {{ cookiecutter.package_name }}.core import say_hello
|
||||
|
||||
|
||||
def main():
|
||||
"""Demonstrate basic usage."""
|
||||
# Basic hello
|
||||
print(hello())
|
||||
|
||||
# Process some data
|
||||
result = process_data("example data")
|
||||
print(result)
|
||||
|
||||
# Use main class
|
||||
instance = {{ cookiecutter.project_name.replace(' ', '').replace('-', '') }}("example")
|
||||
print(instance.run())
|
||||
say_hello()
|
||||
|
||||
# Hello with a name
|
||||
say_hello("{{ cookiecutter.project_name }}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
"""{{ cookiecutter.project_name }} - {{ cookiecutter.description }}"""
|
||||
|
||||
__version__ = "{{ cookiecutter.version }}"
|
||||
|
||||
|
||||
def hello() -> str:
|
||||
"""Return a hello message."""
|
||||
return "Hello from {{ cookiecutter.project_name }}!"
|
||||
__version__ = "{{ cookiecutter.version }}"
|
||||
@@ -1,17 +1,6 @@
|
||||
"""Core functionality for {{ cookiecutter.project_name }}."""
|
||||
|
||||
|
||||
def process_data(data: str) -> str:
|
||||
"""Process input data and return result."""
|
||||
return f"Processed: {data}"
|
||||
|
||||
|
||||
class {{ cookiecutter.project_name.replace(' ', '').replace('-', '') }}:
|
||||
"""Main class for {{ cookiecutter.project_name }}."""
|
||||
|
||||
def __init__(self, name: str = "default") -> None:
|
||||
self.name = name
|
||||
|
||||
def run(self) -> str:
|
||||
"""Run the main functionality."""
|
||||
return f"Running {{ cookiecutter.project_name }} with {self.name}"
|
||||
def say_hello(name: str = "World") -> None:
|
||||
"""Print a hello message."""
|
||||
print(f"Hello, {name}!")
|
||||
@@ -1,25 +1,24 @@
|
||||
"""Tests for {{ cookiecutter.package_name }}."""
|
||||
|
||||
import pytest
|
||||
from io import StringIO
|
||||
import sys
|
||||
|
||||
from {{ cookiecutter.package_name }} import hello
|
||||
from {{ cookiecutter.package_name }}.core import process_data, {{ cookiecutter.project_name.replace(' ', '').replace('-', '') }}
|
||||
from {{ cookiecutter.package_name }}.core import say_hello
|
||||
|
||||
|
||||
def test_hello():
|
||||
"""Test hello function."""
|
||||
result = hello()
|
||||
assert "Hello from {{ cookiecutter.project_name }}" in result
|
||||
def test_say_hello():
|
||||
"""Test say_hello function."""
|
||||
captured_output = StringIO()
|
||||
sys.stdout = captured_output
|
||||
say_hello()
|
||||
sys.stdout = sys.__stdout__
|
||||
assert captured_output.getvalue() == "Hello, World!\n"
|
||||
|
||||
|
||||
def test_process_data():
|
||||
"""Test process_data function."""
|
||||
result = process_data("test")
|
||||
assert result == "Processed: test"
|
||||
|
||||
|
||||
def test_main_class():
|
||||
"""Test main class."""
|
||||
instance = {{ cookiecutter.project_name.replace(' ', '').replace('-', '') }}("test")
|
||||
result = instance.run()
|
||||
assert "Running {{ cookiecutter.project_name }} with test" in result
|
||||
def test_say_hello_with_name():
|
||||
"""Test say_hello function with custom name."""
|
||||
captured_output = StringIO()
|
||||
sys.stdout = captured_output
|
||||
say_hello("Alice")
|
||||
sys.stdout = sys.__stdout__
|
||||
assert captured_output.getvalue() == "Hello, Alice!\n"
|
||||
Reference in New Issue
Block a user