Skip to content

Commit ae96ad4

Browse files
update docs, README, example_2
1 parent 1193f13 commit ae96ad4

File tree

7 files changed

+48
-72
lines changed

7 files changed

+48
-72
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Virtual environments
22
.venv/
33
venv/
4+
.venv_test/
45
ENV/
56
env/
67

README.md

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,49 @@
88

99

1010
# python-project-template — showcasing good software practices
11-
The library provides a small dependence-free Calculator API (Operation, OperationRegistry, Calculator) that can register and compose simple mathematical operations.
12-
This simple code is used to showcase some good coding practices.
11+
12+
`python-project-template` is a small python project to showcase good programming and software practices such as testing, documentation, CI/CD.
13+
14+
This project implements a small dependence-free Calculator API (Operation, OperationRegistry, Calculator) that can register and compose simple mathematical operations.
1315

1416
## Table of contents
1517
- [Features](#features)
1618
- [Installation](#installation)
17-
- [Quick usage](#quick-usage)
19+
- [Usage and Testing](#Usage-and-Testing)
1820
- [Examples & experiments](#examples--experiments)
1921
- [Documentation](#documentation)
20-
- [Running tests](#running-tests)
2122
- [Contributing](#contributing)
2223
- [License](#license)
2324

24-
## Features
25+
## Features Highlights
2526

26-
- **Argument validation** with type annotations and runtime checking using the ``typing`` module.
27-
- **Consistent error messages** for invalid operations and inputs via custom ``Exceptions``.
28-
- **Unit tests** with ``pytest``. Global testing variables set in `tests/convtest.py`.
29-
- **Example notebooks and scripts** for demonstration and exploration.
30-
- **Google-style documentation** generated with ``sphinx``.
31-
- **Pre-commit routine** configured in `.pre-commit-config.yaml`:
27+
- **Type-annotated API** with runtime argument validation.
28+
- **Custom exceptions** for clear error reporting.
29+
- **Comprehensive unit tests** using `pytest`.
30+
- **Google-style documentation** auto-generated with Sphinx.
31+
- **Pre-commit checks** and code formatting tools.
32+
- **CI/CD pipelines** for testing and docs via GitHub Actions.
3233

33-
- Code formatting with ``black``
34-
- Linting with ``ruff-pre-commit``
35-
- Type checking with ``mypy``
36-
- Additional checks and fixes (trailing whitespace removal, enforcing empty line at EOF, YAML syntax checks, blocking large files) via ``pre-commit-hooks``
3734

38-
- **Modern packaging** and easy installation using `pyproject.toml`.
39-
- **Automated test suite and coverage reporting** integrated with GitHub Actions; coverage reports can be published to GitHub Pages. Setup in `.github/workflows/tests.yml`.
40-
- **Automatic documentation build and deployment** to GitHub Pages with GitHub Actions. Setup in `.github/workflows/docs.yml`.
41-
- **Easy contribution workflow** for new features and improvements.
35+
See the [Documentation](#documentation) for a detailed list of features.
4236

4337
## Installation
4438

4539
To install the latest release from TestPyPI, use:
4640

4741
```bash
48-
python3 -m venv .venv
49-
source .venv/bin/activate
50-
python -m pip install --upgrade pip
5142
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple python-project-template-AS
5243
```
5344

54-
Alternatively, you can clone the repository, create a virtual environment (recommended), and install dependencies and an editable installation of `python-project-template`:
45+
Alternatively, you can clone the repository and install dependencies and an editable installation of `python-project-template-AS` with:
5546

5647
```bash
57-
git clone <https://github.com/andreascaglioni/python-project-template>
48+
git clone <https://github.com/andreascaglioni/python-project-template-AS>
5849
cd python-project-template
5950
pip install -e ".[dev]"
6051
```
6152

62-
## Quick usage
53+
## Usage and Testing
6354

6455
The following is a quick example for the Calculator API.
6556

@@ -74,7 +65,7 @@ print(calc.apply('add', 2, 3)) # -> 5
7465

7566
# Compose unary operations into a Callable
7667
f = calc.compose(['neg', 'sqr'])
77-
print(f(3)) # -> 9
68+
print(f(-3)) # -> 9
7869

7970
# Register a custom operation
8071
def inc(x):
@@ -84,28 +75,20 @@ calc.register(Operation('inc', inc, arity=1), replace=True)
8475
print(calc.apply('inc', 4)) # -> 5
8576
```
8677

87-
- `experiments/` — short runnable demos.
88-
- `notebooks/` — exploratory notebooks.
89-
90-
## Documentation
91-
92-
For detailed documentation, please visit our [GitHub Pages](https://andreascaglioni.github.io/your-repo-name/).
93-
94-
To build the documentation locally:
78+
Find more examples in `examples/`.
9579

96-
1. Ensure all dependencies for documentation (e.g., Sphinx) generation are installed, for example running ``pip install -e ".[docs]"``.
97-
2. Run the documentation build command (for example, ``make html``).
98-
3. Review the generated HTML in ``docs/_build/html``.
99-
100-
## Running tests
101-
102-
Run the full PyTest test suite with coverage:
80+
To run the tests:
10381

10482
```bash
105-
pytest -q --cov=python_project_template_AS --cov-report=term --cov-report=html
83+
pytest tests/
84+
pytest -v tests/ # verbose output
85+
pytest --cov=python_project_template_AS tests/ # show test coverage
10686
```
10787

108-
Open `htmlcov/index.html` to view the coverage report.
88+
## Documentation
89+
90+
For detailed documentation, please visit our [GitHub Pages](https://andreascaglioni.github.io/your-repo-name/).
91+
10992

11093
## Contributing
11194

@@ -121,7 +104,7 @@ git push --set-upstream origin feat/your-feature
121104
```
122105

123106
Run `pip install -e .[dev]` to get development tools (pre-commit, black, ruff, mypy, pytest, ...).
124-
The pre-commit routine is called with `pre-commit run --all-files` before committing.
107+
Run the pre-commit routine with `pre-commit run --all-files` before committing.
125108

126109
## License
127110

docs/docs_github.rst

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,7 @@ Repository setup (one-time)
1818

1919
Local testing
2020
-------------
21-
To build the docs locally (recommended before pushing):
22-
23-
.. code-block:: bash
24-
25-
# create and activate a venv
26-
python -m venv .venv
27-
source .venv/bin/activate
28-
python -m pip install --upgrade pip
29-
# install docs dependencies
30-
pip install -e ".[docs]"
31-
# build
32-
cd docs
33-
sphinx-build -b html -a -E -W -T . _build/html
21+
See the previous page :doc:`Local documentation <docs_local>` for additional local setup and testing instructions.
3422

3523
Autosummary and generated files
3624
-------------------------------
@@ -42,4 +30,4 @@ Troubleshooting
4230
- If builds fail due to missing packages, ensure :file:`pyproject.toml` contains the correct ``docs`` extras and that ``pip install -e ".[docs]"`` succeeds.
4331
- If the site does not appear after the workflow succeeds, check Settings → Pages to ensure the site is not blocked by organization policy.
4432

45-
That's it — the workflow will publish your Sphinx docs automatically when you push to ``main``.
33+
The workflow will attempt to publish your Sphinx docs automatically when you push to ``main``.

docs/docs_local.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Good documentation is essential for code sustainability. It ensures that others
55

66
To build the documentation for this project, follow these steps:
77

8-
1. Ensure all dependencies for documentation generation are installed, for example with ``pip install -e ".[docs]"``.
9-
2. Run the documentation build command (for example, ``make html``).
10-
3. Review the generated HTML in ``docs/_build/html``.
8+
1. Install documentation dependencies with ``pip install -e ".[docs]"``.
9+
2. Move to ``docs/`` (``cd docs``) and build the documentation ``make html``.
10+
11+
The generated HTML is in ``docs/_build/html``.

docs/usage.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ The following is a quick example for the Calculator API. It shows how to:
1616
print(calc.apply('add', 2, 3)) # -> 5
1717
1818
f = calc.compose(['neg', 'sqr'])
19-
print(f(3)) # -> 9
19+
print(f(-3)) # -> 9
2020
2121
def inc(x):
2222
return x + 1
2323
2424
calc.register(Operation('inc', inc, arity=1), replace=True)
2525
print(calc.apply('inc', 4))
2626
27-
Find additional examples in:
28-
29-
- ``experiments/`` — short demos
30-
- ``notebooks/`` — exploratory notebooks
27+
Find additional examples in ``examples/``.

examples/example_2_replace_operation.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ def add_v1(a, b):
1616
def add_v2(a, b):
1717
return (a + b) * 10
1818

19-
calc.register(Operation(name="add", func=add_v1))
20-
assert calc.apply("add", 1, 2) == 3
21-
22-
# replace existing operation
23-
calc.register(Operation(name="add", func=add_v2), replace=True)
24-
assert calc.apply("add", 1, 2) == 30
19+
op_v1 = Operation(name="add", func=add_v1, arity=2)
20+
calc.register(op_v1)
21+
sum_1 = calc.apply("add", 1, 2)
22+
print("calc.apply('add', 1, 2) =", sum_1)
23+
24+
# Replace existing operation adn recompute the sum
25+
op_v2 = Operation(name="add", func=add_v2, arity=2)
26+
calc.register(op_v2, replace=True)
27+
sum_2 = calc.apply("add", 1, 2)
28+
print("calc.apply('add', 1, 2) = ", sum_2)

src/python_project_template_AS/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .registry import OperationRegistry
2121
from .calculator import Calculator
2222
from .utils import is_number
23+
from importlib.metadata import version
2324

2425
__all__ = [
2526
"CalculatorError",
@@ -37,6 +38,7 @@
3738
"is_number",
3839
]
3940

41+
__version__ = version("python-project-template-AS")
4042

4143
# Default registry pre-populated with a few convenience operations.
4244
_default_registry = OperationRegistry()

0 commit comments

Comments
 (0)