Skip to content

Commit 34a0921

Browse files
apply minor edits
1 parent 1ed6db6 commit 34a0921

File tree

6 files changed

+70
-59
lines changed

6 files changed

+70
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ node_modules/
6969

7070
# Generated docs
7171
docs/_build/
72+
docs/_autosummary/
7273

7374
# Ignore build artifacts created by editable installs
7475
*.egg-link

CHANGELOG.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

CITATION.cff

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cff-version: 1.2.0
2+
message: "If you use this software, please cite it using the following metadata."
3+
title: "python-project-template"
4+
authors:
5+
- family-names: "Scaglioni"
6+
given-names: "Andrea"
7+
# affiliation: "YourInstitution"
8+
orcid: "https://orcid.org/0000-0002-8601-5902"
9+
date-released: "2025-10-14"
10+
version: "0.1.0"
11+
# doi: "10.5281/zenodo.1234567"
12+
license: "MIT"
13+
repository-code: "https://github.com/andreascaglioni/python-project-template"
14+
url: "https://github.com/andreascaglioni/python-project-template"

README.md

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,42 @@
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
55

66
# python-project-template — showcasing good software practices
7-
A minimal Python project demonstrating best practices for testing, documentation, CI/CD, packaging, examples.
8-
The library provides a tiny Calculator API that can register and compose simple mathematical operations.
7+
The library provides a small dependence-free Calculator API (Operation, OperationRegistry, Calculator) that can register and compose simple mathematical operations.
8+
This simple code is used to showcase some good coding practices.
99

1010
## Table of contents
1111
- [Features](#features)
1212
- [Installation](#installation)
1313
- [Quick usage](#quick-usage)
1414
- [Examples & experiments](#examples--experiments)
15+
- [Documentation](#documentation)
1516
- [Running tests](#running-tests)
1617
- [Project structure](#project-structure)
1718
- [Contributing](#contributing)
1819
- [License](#license)
1920

2021
## Features
21-
- Small, dependency-free core API: Operation, OperationRegistry, Calculator
22-
- Example operations (add, sub, mul, div, neg, sqr)
23-
- Utilities and clear error handling
24-
- Tests (pytest) and CI workflow included
22+
23+
- **Argument validation** with type annotations and runtime checking using the ``typing`` module.
24+
- **Consistent error messages** for invalid operations and inputs via custom ``Exceptions``.
25+
- **Unit tests** with ``pytest``. Global testing variables set in :file:`tests/convtest.py`.
26+
- **Example notebooks and scripts** for demonstration and exploration.
27+
- **Google-style documentation** generated with ``sphinx``.
28+
- **Pre-commit routine** configured in :file:`.pre-commit-config.yaml`:
29+
30+
- Code formatting with ``black``
31+
- Linting with ``ruff-pre-commit``
32+
- Type checking with ``mypy``
33+
- Additional checks and fixes (trailing whitespace removal, enforcing empty line at EOF, YAML syntax checks, blocking large files) via ``pre-commit-hooks``
34+
35+
- **Modern packaging** and easy installation using ``pyproject.toml``.
36+
- **Automated test suite and coverage reporting** integrated with GitHub Actions; coverage reports can be published to GitHub Pages. Setup in :file:`.github/workflows/tests.yml`.
37+
- **Automatic documentation deployment** to GitHub Pages with GitHub Actions. Setup in :file:`.github/workflows/docs.yml` [TODO].
38+
- **Easy contribution workflow** for new features and improvements.
2539

2640
## Installation
2741

28-
Clone the repository and create a virtual environment (recommended):
42+
Clone the repository, create a virtual environment (recommended), and install dependencies and an editable installation of `python-project-template`:
2943

3044
```bash
3145
git clone <repo-url>
@@ -36,12 +50,11 @@ python -m pip install --upgrade pip setuptools wheel
3650
pip install -e ".[dev]"
3751
```
3852

39-
This installs the package in editable mode and the development extras (pytest,
40-
pre-commit, formatting and linting tools) so you can run tests and linters.
53+
This installs the package in editable mode and the development extras (pytest, pre-commit, formatting and linting tools) so you can run tests and linters.
4154

4255
## Quick usage
4356

44-
Interactive example using the package API:
57+
The following is a quick example for the Calculator API.
4558

4659
```python
4760
from python_project_template import default_calculator, Operation
@@ -66,9 +79,12 @@ print(calc.apply('inc', 4)) # -> 5
6679

6780
## Examples & experiments
6881

69-
- `experiments/` — short runnable demos. Each experiment should include a
70-
`README.md` explaining inputs and expected outputs.
71-
- `notebooks/` — exploratory notebooks (keep final versions small).
82+
- `experiments/` — short runnable demos.
83+
- `notebooks/` — exploratory notebooks.
84+
85+
## Documentation
86+
87+
For detailed documentation, please visit our [GitHub Pages](https://andreascaglioni.github.io/your-repo-name/).
7288

7389
## Running tests
7490

@@ -83,21 +99,24 @@ Open `htmlcov/index.html` to view the coverage report.
8399
## Project structure
84100

85101
```
86-
src/python_project_template/ # library code
87-
- calculator.py # Calculator API
88-
- operations.py # Operation dataclass and example ops
89-
- registry.py # OperationRegistry
90-
- exceptions.py # custom exceptions
91-
- utils.py # small helpers
92-
experiments/ # short runnable demos
93-
notebooks/ # interactive exploration
94-
tests/ # pytest test suite
95-
docs/ # docs site (mkdocs)
96-
pyproject.toml # build & project config
97-
.github/workflows/ # CI workflows
98-
README.md
99-
LICENSE
100-
CITATION.cff
102+
src/python_project_template/ # Core library package
103+
- calculator.py # Calculator API
104+
- operations.py # Built-in operations
105+
- registry.py # Operation registry
106+
- exceptions.py # Custom error types
107+
- utils.py # Utility functions
108+
experiments/ # Example scripts
109+
notebooks/ # Jupyter notebooks
110+
tests/ # Test suite
111+
docs/ # Documentation
112+
.github/
113+
workflows/
114+
tests.yml # GitHub Actions workflow for automated testing and coverage reporting
115+
docs.yml # GitHub Actions workflow for automated documentation and deployment
116+
pyproject.toml # Build/config file
117+
README.md # Project overview
118+
LICENSE # License info
119+
CITATION.cff # Citation metadata
101120
```
102121

103122
## Contributing

src/python_project_template/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
_default_registry.register(op)
3333

3434

35-
# Convenience constructor using default registry
35+
# Convenience Calculator constructor using default registry
3636
def default_calculator() -> Calculator:
3737
return Calculator(registry=_default_registry)

src/python_project_template/calculator.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ class Calculator:
1111
"""A tiny calculator that uses an OperationRegistry.
1212
1313
Features:
14+
1415
- register operations (via registry or helper)
1516
- apply a named operation to arguments
1617
- compose a sequence of operations into a single callable
1718
"""
1819

1920
def __init__(self, registry: Optional[OperationRegistry] = None):
20-
self.registry = registry or OperationRegistry()
21+
if registry is None:
22+
self.registry = OperationRegistry()
23+
else:
24+
self.registry = registry
2125

2226
def register(self, op: Operation, *, replace: bool = False) -> None:
2327
self.registry.register(op, replace=replace)
2428

25-
def apply(self, op_name: str, *args) -> Any:
29+
def apply(self, op_name: str, *args: Any) -> Any:
2630
op = self.registry.get(op_name)
2731
try:
2832
return op(*args)
@@ -76,7 +80,7 @@ def chain(self, sequence: Iterable[str], initial: Any) -> Any:
7680
For binary operations, the operation consumes (current_value, next_input)
7781
and returns a new current_value. To support binary ops in a chain, the
7882
sequence should alternate between operation names and provided literals
79-
(which are interpreted as inputs). Example:
83+
(which are interpreted as inputs). Example::
8084
8185
sequence = ['add', 5, 'sqr']
8286
chain(sequence, initial=2) -> sqr(add(2,5)) = (2+5)^2

0 commit comments

Comments
 (0)