Skip to content

Commit 20bf6ff

Browse files
expand readme and make various fixes
1 parent 805993c commit 20bf6ff

File tree

10 files changed

+133
-14
lines changed

10 files changed

+133
-14
lines changed

.markdownlint-cli2.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
config:
2+
MD013: false

.pre-commit-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,3 @@ repos:
1515
rev: v0.17.2
1616
hooks:
1717
- id: markdownlint-cli2
18-
- repo: https://github.com/KyleKing/copier-template-tester
19-
rev: "2.1.4"
20-
hooks:
21-
- id: copier-template-tester

README.md

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,104 @@
1-
# felixgwilliams python-copier-template
1+
# Python Copier Template for Data Science
22

3+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
34
[![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)
5+
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
6+
7+
This is a template built with [Copier](https://github.com/copier-org/copier) to generate a data science focused python project.
8+
9+
Get started with the following command:
10+
11+
```shell
12+
copier copy gh:felixgwilliams/python-copier-template-ds path/to/destination
13+
```
14+
15+
## Features
16+
17+
### Project structure
18+
19+
It is assumed that most of the work will be done in Jupyter Notebooks.
20+
However, the template also includes a python project, in which you can put functions and classes shared across notebooks.
21+
The repository is set up to use [Pytest](https://docs.pytest.org/en/stable/) for unit testing this module code.
22+
23+
The template also includes a `data` directory whose contents will be ignored by git.
24+
You can use this folder to store data that you do not commit.
25+
You may also put a readme file in which you can document the source datasets you use and how to acquire them.
26+
27+
### [just](https://github.com/casey/just)
28+
29+
`just` is a command runner that allows you to easily to run project-specific commands.
30+
In fact, you can use `just` to run all the setup commands listed below:
31+
32+
```shell
33+
just setup
34+
```
35+
36+
### [uv](https://github.com/astral-sh/uv)
37+
38+
The repository is set up to use [uv](https://github.com/astral-sh/uv) for package or project management.
39+
You may set up your python environment with
40+
41+
```shell
42+
uv sync --all-groups --all-extras
43+
```
44+
45+
### [Ruff](https://github.com/astral-sh/ruff)
46+
47+
The repository is configured to use [Ruff](https://github.com/astral-sh/ruff) for linting and formatting.
48+
By default, all lints are enabled except
49+
50+
- [`COM`](https://docs.astral.sh/ruff/rules/#flake8-commas-com) Enforces trailing commas
51+
- [`ERA`](https://docs.astral.sh/ruff/rules/#eradicate-era) Disallows commented-out code
52+
- [`ISC001`](https://docs.astral.sh/ruff/rules/single-line-implicit-string-concatenation/#flake8-executable-exe) (conflicts with the formatter).
53+
54+
In addition, the following rules are only enforced for module code as they are inappropriate or too strict for unit tests and notebooks:
55+
56+
- [`D`](https://docs.astral.sh/ruff/rules/#pydocstyle-d) Requires docstrings on functions, classes and modules
57+
- [`ANN`](https://docs.astral.sh/ruff/rules/#flake8-annotations-ann) Requires type annotations on functions and methods
58+
- [`S101`](https://docs.astral.sh/ruff/rules/assert/) Disallows use of `assert`
59+
- [`PLR2004`](https://docs.astral.sh/ruff/rules/magic-value-comparison/) Disallows "magic" values in comparisons
60+
- [`T20`](https://docs.astral.sh/ruff/rules/#flake8-print-t20) Disallows print statements
61+
62+
The target line length is 120 and the docstring convention is google.
63+
64+
### [pre-commit](https://github.com/pre-commit/pre-commit)
65+
66+
pre-commit is a tool that runs checks on your files before you commit them with git, thereby helping ensure code quality.
67+
Enable it with the following command:
68+
69+
```shell
70+
pre-commit install --install-hooks
71+
```
72+
73+
The configuration is stored in `.pre-commit-config.yaml`.
74+
75+
### [nbwipers](https://github.com/felixgwilliams/nbwipers)
76+
77+
`nbwipers` is a tool written in rust to ensure Jupyter notebooks are clean.
78+
Committing notebooks that are not clean makes diffs more confusing, can degrade performance and increases the risk of leaking sensitive information.
79+
You can set it up as a git filter with the following command.
80+
81+
```shell
82+
nbwipers install local
83+
```
84+
85+
### [pytest](https://docs.pytest.org/en/stable/)
86+
87+
The repository comes configured to use `pytest` for unit testing the module code.
88+
Feel free to ignore it if you do not write module code.
89+
90+
### Github Actions
91+
92+
You may optionally add a github workflow file which checks the following:
93+
94+
- uses ruff to check files are formatted and linted
95+
- Runs unit tests and checks coverage
96+
- Checks any markdown files are formatted with [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2)
97+
- Checks that all jupyter notebooks are clean
98+
99+
### [Typos](https://github.com/crate-ci/typos)
100+
101+
Typos checks for common typos in code, aiming for a low false positive rate.
102+
The repository is configured not to use it for Jupyter notebook files, as it tends to find errors in cell outputs.
4103

5104
Test with [Copier](https://github.com/copier-org/copier) and [copier-template-tester](https://github.com/KyleKing/copier-template-tester).

copier.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ python_version:
1515

1616
github_actions:
1717
type: bool
18-
help: Include github directory
18+
help: Add github actions
1919
default: false

template/.markdownlint-cli2.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
config:
2+
MD013: false

template/.pre-commit-config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ repos:
55
- id: trailing-whitespace
66
- id: end-of-file-fixer
77
- id: check-yaml
8-
# - id: check-added-large-files
98
- id: check-merge-conflict
109
- repo: https://github.com/astral-sh/ruff-pre-commit
1110
# Ruff version.
12-
rev: v0.9.2
11+
rev: v0.9.3
1312
hooks:
1413
# Run the linter.
1514
- id: ruff

template/README.md.jinja

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
11
# {{project_name}}
2+
3+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
4+
[![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)
5+
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
6+
7+
Get started by running the following with [just](https://github.com/casey/just):
8+
9+
```shell
10+
just setup
11+
```

template/justfile.jinja

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module_name := "{{module_name}}"
22

3+
# list commands
34
default:
45
@just --list
56

@@ -8,7 +9,7 @@ setup: install git-setup
89

910
# install the packages
1011
install:
11-
{% raw %}{{if path_exists("uv.lock") != "true" {"uv sync --dev --all-extras --inexact"} else {"uv sync --dev --all-extras --locked --inexact"} }}{% endraw %}
12+
{% raw %}{{if path_exists("uv.lock") != "true" {"uv sync --all-groups --all-extras --inexact"} else {"uv sync --dev --all-extras --locked --inexact"} }}{% endraw %}
1213

1314
# ensure code quality before git commit via pre-commit and nbwipers
1415
git-setup: install
@@ -34,8 +35,12 @@ lint:
3435

3536
# update packages and uv lock file
3637
update:
37-
uv sync -U --dev --all-extras --inexact
38+
uv sync -U --all-groups --all-extras --inexact
3839

3940
# update pre-commit file
4041
pc-update:
4142
uvx pre-commit-update
43+
44+
# check for typos
45+
typos:
46+
uv run typos .

template/pyproject.toml.jinja

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ convention = "google"
2929
files.extend-exclude = ["*.ipynb"]
3030

3131
[tool.uv]
32-
dev-dependencies = [
32+
default-groups = ["dev", "lint"]
33+
34+
[dependency-groups]
35+
dev = [
3336
"nbwipers>=0.6.0",
34-
"ruff>=0.9.2",
3537
"pytest>=8",
3638
"pytest-cov>=6.0.0",
3739
"pre-commit>=4.1.0",
40+
"typos>=1.29.4",
41+
]
42+
lint = [
43+
"ruff>=0.9.3",
3844
]

template/{% if github_actions %}.github{% endif %}/workflows/ci.yml.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
python-version-file: ".python-version"
2929
- name: Install the project
30-
run: uv sync --all-extras --dev
30+
run: uv sync --only-group lint
3131
- name: check format
3232
run: uv run ruff format --check --diff .
3333
- name: check lints
@@ -43,7 +43,7 @@ jobs:
4343
with:
4444
python-version-file: ".python-version"
4545
- name: Install the project
46-
run: uv sync --all-extras --dev
46+
run: uv sync --all-extras --all-groups
4747
- name: unit tests
4848
run: |
4949
set -o pipefail && \

0 commit comments

Comments
 (0)