Skip to content

Commit aeb2d4a

Browse files
authored
Add rye and use pixi for template. (#43)
1 parent f16e115 commit aeb2d4a

23 files changed

+346
-450
lines changed

.github/workflows/main.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ jobs:
3333
python-version: ${{ matrix.python-version }}
3434
cache: pip
3535
allow-prereleases: true
36-
- run: pip install tox
36+
- uses: prefix-dev/[email protected]
37+
with:
38+
pixi-version: v0.20.1
39+
run-install: false
40+
41+
- run: pip install tox-uv
3742

3843
- name: Run tests.
3944
shell: bash -l {0}

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,10 @@ _generated
144144
*.egg-info
145145
.eggs
146146

147-
.pytask.sqlite3
147+
.pytask
148148

149149
build
150150
dist
151151

152-
version.py
152+
.ruff_cache
153+
.mypy_cache

.python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.2

README.md

+6-68
Original file line numberDiff line numberDiff line change
@@ -5,79 +5,17 @@
55
[![image](https://img.shields.io/github/actions/workflow/status/pytask-dev/cookiecutter-pytask-project/main.yml?branch=main)](https://github.com/pytask-dev/cookiecutter-pytask-project/actions?query=branch%3Amain)
66
[![image](https://codecov.io/gh/pytask-dev/cookiecutter-pytask-project/branch/main/graph/badge.svg)](https://codecov.io/gh/pytask-dev/cookiecutter-pytask-project)
77
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/pytask-dev/cookiecutter-pytask-project/main.svg)](https://results.pre-commit.ci/latest/github/pytask-dev/cookiecutter-pytask-project/main)
8-
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
8+
[![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)
99

1010
This repository contains a minimal cookiecutter template for a project with
1111
[pytask](https://github.com/pytask-dev/pytask).
1212

13-
## Usage
14-
15-
First, install cookiecutter.
16-
17-
```console
18-
$ pip install cookiecutter
19-
20-
$ conda install -c conda-forge cookiecutter
21-
```
22-
23-
Then, set up the template with
24-
25-
```console
26-
$ cookiecutter https://github.com/pytask-dev/cookiecutter-pytask-project
27-
```
28-
2913
## Documentation
3014

31-
If you are new to pytask, just follow the
32-
[tutorials](https://pytask-dev.readthedocs.io/en/stable/tutorials/index.html) which will
33-
help you with your first steps like how to write the first task.
34-
35-
If you are already familiar with pytask, the
36-
[how-to guides](https://pytask-dev.readthedocs.io/en/stable/how_to_guides/index.html)
37-
offer more in-depth guidance on complex projects.
38-
39-
In general, you will find most guidance in the
40-
[documentation](https://pytask-dev.readthedocs.io/en/stable/index.html) and some advice
41-
in the FAQ below.
42-
43-
## FAQ
44-
45-
Q: Why are the source files nested in `src/<project_slug>`?
46-
47-
A: This is called the src layout and the advantages are discussed in this
48-
[article by Hynek Schlawack](https://hynek.me/articles/testing-packaging/).
49-
50-
Although the article discusses the src layout in terms of Python packages, it is also
51-
beneficial to structure a project the same way. Next to the reasons discussed there, it
52-
is possible to use a single Python environment for multiple projects without messing
53-
with your PYTHONPATH (via `pip install -e .` or `conda develop .`) each time and still
54-
import modules.
55-
56-
Q: My project is a Python package, but it does not seem to have a version. Where is it?
57-
58-
A: The cookiecutter uses [setuptools_scm](https://github.com/pypa/setuptools_scm/) to
59-
manage the version number. When you install your created project as a Python package
60-
with `pip install -e .`, setuptools_scm tries to infer the version number from the tags
61-
created on the repo.
62-
63-
For example, if you have switched to a commit associated with the tag `v0.2.0`,
64-
setuptools_scm will create a `src/<package_slug>/_version.py` with a variable containing
65-
`version = '0.2.0'` which you can use in your `src/<package_slug>/__init__.py`. If you
66-
are one commit ahead of the tag, you version will be something like `0.2.0.dev1+...`
67-
indicating you are one commit ahead of the tag `v0.2.0`.
68-
69-
If you want to switch to the tradition setup, replace the following code in your
70-
`pyproject.toml`
71-
72-
```toml
73-
[build-system]
74-
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
75-
```
15+
You find the documentation at <https://cookiecutter-pytask-project.readthedocs.io>.
7616

77-
with
17+
## Changes
7818

79-
```toml
80-
[build-system]
81-
requires = ["setuptools"]
82-
build-backend = "setuptools.build_meta"
83-
```
19+
Consult the
20+
[release notes](https://cookiecutter-pytask-project.readthedocs.io/en/latest/changes.html)
21+
to find out about what is new.

cookiecutter.json

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,5 @@
2020
"Not open source"
2121
],
2222
"make_initial_commit": ["no", "yes"],
23-
"conda_environment_name": "{{ cookiecutter.project_slug }}",
24-
"create_conda_environment_at_finish": ["no", "yes"],
2523
"_copy_without_render": [".github/workflows/main.yml"]
2624
}

docs/source/faq.md

-41
This file was deleted.

docs/source/index.md

+70-17
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,94 @@
1010
This repository contains a minimal cookiecutter template for a project with
1111
[pytask](https://github.com/pytask-dev/pytask).
1212

13-
## Usage
13+
## Installation
1414

15-
First, install cookiecutter.
15+
The template uses [pixi](https://pixi.sh/) as the package and environment manager which
16+
is the successor of conda/mamba/micromamba. Please, install it.
17+
18+
```{note}
19+
Of course, the template can be used with any other package manager. But, we recommend
20+
pixi which can install packages from conda, PyPI, etc.. or [rye](https://rye-up.com/)
21+
for PyPI-only projects.
22+
```
23+
24+
Then, install cookiecutter.
1625

1726
```console
18-
$ pip install cookiecutter
27+
pixi global install cookiecutter
28+
```
29+
30+
Now, set up the template with
1931

20-
$ conda install -c conda-forge cookiecutter
32+
```console
33+
pixi run cookiecutter https://github.com/pytask-dev/cookiecutter-pytask-project
2134
```
2235

23-
Then, set up the template with
36+
Many formatting issues exist after the project is created. Run pre-commit to polish the
37+
template.
2438

2539
```console
26-
$ cookiecutter https://github.com/pytask-dev/cookiecutter-pytask-project
40+
pixi global install pre-commit
41+
pixi run pre-commit run -a
2742
```
2843

29-
## Documentation
44+
## Features
45+
46+
Here is a feature list of the template.
47+
48+
- [pixi](https://pixi.sh/latest/) as the environment and package manager.
49+
- Supports pre-commit and some popular hooks like ruff and refurb.
50+
- Initialized documentation in `docs`.
51+
- Preconfigured GitHub actions and dependabot.
52+
- Preconfigured readthedocs.
53+
- Preconfigured CodeCov.
54+
55+
## FAQ
3056

31-
If you are new to pytask, just follow the
32-
[tutorials](https://pytask-dev.readthedocs.io/en/stable/tutorials/index.html) which will
33-
help you with your first steps like how to write the first task.
57+
Q: Why are the source files nested in `src/<project_slug>`?
3458

35-
If you are already familiar with pytask, the
36-
[how-to guides](https://pytask-dev.readthedocs.io/en/stable/how_to_guides/index.html)
37-
offer more in-depth guidance on complex projects.
59+
A: This is called the src layout and the advantages are discussed in this
60+
[article by Hynek Schlawack](https://hynek.me/articles/testing-packaging/).
3861

39-
In general, you will find most guidance in the
40-
[documentation](https://pytask-dev.readthedocs.io/en/stable/index.html) and some advice
41-
in the FAQ below.
62+
Although the article discusses the src layout in terms of Python packages, it is also
63+
beneficial to structure a project the same way. Next to the reasons discussed there, it
64+
is possible to use a single Python environment for multiple projects without messing
65+
with your PYTHONPATH (via `pip install -e .` or `conda develop .`) each time and still
66+
import modules.
67+
68+
Q: My project is a Python package, but it does not seem to have a version. Where is it?
69+
70+
A: The cookiecutter uses [setuptools_scm](https://github.com/pypa/setuptools_scm/) to
71+
manage the version number. When you install your created project as a Python package
72+
with `pip install -e .`, setuptools_scm tries to infer the version number from the tags
73+
created on the repo.
74+
75+
For example, if you have switched to a commit associated with the tag `v0.2.0`,
76+
setuptools_scm will create a `src/<package_slug>/_version.py` with a variable containing
77+
`version = '0.2.0'` which you can use in your `src/<package_slug>/__init__.py`. If you
78+
are one commit ahead of the tag, you version will be something like `0.2.0.dev1+...`
79+
indicating you are one commit ahead of the tag `v0.2.0`.
80+
81+
If you want to switch to the tradition setup, replace the following code in your
82+
`pyproject.toml`
83+
84+
```toml
85+
[build-system]
86+
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
87+
```
88+
89+
with
90+
91+
```toml
92+
[build-system]
93+
requires = ["setuptools"]
94+
build-backend = "setuptools.build_meta"
95+
```
4296

4397
```{toctree}
4498
---
4599
caption: 'Contents:'
46100
maxdepth: 1
47101
---
48-
faq
49102
changes
50103
```

environment.yml

-38
This file was deleted.

hooks/post_gen_project.py

-51
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import shutil
66
import subprocess
7-
import warnings
87
from contextlib import suppress
98
from pathlib import Path
109

@@ -62,56 +61,6 @@ def main() -> None:
6261
capture_output=True,
6362
)
6463

65-
if "{{ cookiecutter.create_conda_environment_at_finish }}" == "yes":
66-
if shutil.which("mamba") is not None:
67-
conda_exe = shutil.which("mamba")
68-
else:
69-
conda_exe = shutil.which("conda")
70-
71-
if conda_exe:
72-
subprocess.run(
73-
(
74-
conda_exe,
75-
"env",
76-
"create",
77-
"-f",
78-
(project_path / "environment.yml").absolute().as_posix(),
79-
"--force",
80-
),
81-
check=True,
82-
capture_output=True,
83-
)
84-
# Install pre-commit hooks and run them.
85-
subprocess.run( # noqa: PLW1510
86-
(
87-
conda_exe,
88-
"run",
89-
"-n",
90-
"{{ cookiecutter.conda_environment_name }}",
91-
"pre-commit",
92-
"install",
93-
),
94-
capture_output=True,
95-
)
96-
subprocess.run( # noqa: PLW1510
97-
(
98-
conda_exe,
99-
"run",
100-
"-n",
101-
"{{ cookiecutter.conda_environment_name }}",
102-
"pre-commit",
103-
"run",
104-
"--all-files",
105-
),
106-
capture_output=True,
107-
)
108-
else:
109-
warnings.warn(
110-
"conda environment could not be created since no conda or mamba "
111-
"executable was found.",
112-
stacklevel=1,
113-
)
114-
11564

11665
if __name__ == "__main__":
11766
main()

0 commit comments

Comments
 (0)