Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: pip
allow-prereleases: true
- run: pip install tox
- uses: prefix-dev/[email protected]
with:
pixi-version: v0.20.1
run-install: false

- run: pip install tox-uv

- name: Run tests.
shell: bash -l {0}
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ _generated
*.egg-info
.eggs

.pytask.sqlite3
.pytask

build
dist

version.py
.ruff_cache
.mypy_cache
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.2
74 changes: 6 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,17 @@
[![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)
[![image](https://codecov.io/gh/pytask-dev/cookiecutter-pytask-project/branch/main/graph/badge.svg)](https://codecov.io/gh/pytask-dev/cookiecutter-pytask-project)
[![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)
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![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)

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

## Usage

First, install cookiecutter.

```console
$ pip install cookiecutter

$ conda install -c conda-forge cookiecutter
```

Then, set up the template with

```console
$ cookiecutter https://github.com/pytask-dev/cookiecutter-pytask-project
```

## Documentation

If you are new to pytask, just follow the
[tutorials](https://pytask-dev.readthedocs.io/en/stable/tutorials/index.html) which will
help you with your first steps like how to write the first task.

If you are already familiar with pytask, the
[how-to guides](https://pytask-dev.readthedocs.io/en/stable/how_to_guides/index.html)
offer more in-depth guidance on complex projects.

In general, you will find most guidance in the
[documentation](https://pytask-dev.readthedocs.io/en/stable/index.html) and some advice
in the FAQ below.

## FAQ

Q: Why are the source files nested in `src/<project_slug>`?

A: This is called the src layout and the advantages are discussed in this
[article by Hynek Schlawack](https://hynek.me/articles/testing-packaging/).

Although the article discusses the src layout in terms of Python packages, it is also
beneficial to structure a project the same way. Next to the reasons discussed there, it
is possible to use a single Python environment for multiple projects without messing
with your PYTHONPATH (via `pip install -e .` or `conda develop .`) each time and still
import modules.

Q: My project is a Python package, but it does not seem to have a version. Where is it?

A: The cookiecutter uses [setuptools_scm](https://github.com/pypa/setuptools_scm/) to
manage the version number. When you install your created project as a Python package
with `pip install -e .`, setuptools_scm tries to infer the version number from the tags
created on the repo.

For example, if you have switched to a commit associated with the tag `v0.2.0`,
setuptools_scm will create a `src/<package_slug>/_version.py` with a variable containing
`version = '0.2.0'` which you can use in your `src/<package_slug>/__init__.py`. If you
are one commit ahead of the tag, you version will be something like `0.2.0.dev1+...`
indicating you are one commit ahead of the tag `v0.2.0`.

If you want to switch to the tradition setup, replace the following code in your
`pyproject.toml`

```toml
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
```
You find the documentation at <https://cookiecutter-pytask-project.readthedocs.io>.

with
## Changes

```toml
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
```
Consult the
[release notes](https://cookiecutter-pytask-project.readthedocs.io/en/latest/changes.html)
to find out about what is new.
2 changes: 0 additions & 2 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
"Not open source"
],
"make_initial_commit": ["no", "yes"],
"conda_environment_name": "{{ cookiecutter.project_slug }}",
"create_conda_environment_at_finish": ["no", "yes"],
"_copy_without_render": [".github/workflows/main.yml"]
}
41 changes: 0 additions & 41 deletions docs/source/faq.md

This file was deleted.

87 changes: 70 additions & 17 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,94 @@
This repository contains a minimal cookiecutter template for a project with
[pytask](https://github.com/pytask-dev/pytask).

## Usage
## Installation

First, install cookiecutter.
The template uses [pixi](https://pixi.sh/) as the package and environment manager which
is the successor of conda/mamba/micromamba. Please, install it.

```{note}
Of course, the template can be used with any other package manager. But, we recommend
pixi which can install packages from conda, PyPI, etc.. or [rye](https://rye-up.com/)
for PyPI-only projects.
```

Then, install cookiecutter.

```console
$ pip install cookiecutter
pixi global install cookiecutter
```

Now, set up the template with

$ conda install -c conda-forge cookiecutter
```console
pixi run cookiecutter https://github.com/pytask-dev/cookiecutter-pytask-project
```

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

```console
$ cookiecutter https://github.com/pytask-dev/cookiecutter-pytask-project
pixi global install pre-commit
pixi run pre-commit run -a
```

## Documentation
## Features

Here is a feature list of the template.

- [pixi](https://pixi.sh/latest/) as the environment and package manager.
- Supports pre-commit and some popular hooks like ruff and refurb.
- Initialized documentation in `docs`.
- Preconfigured GitHub actions and dependabot.
- Preconfigured readthedocs.
- Preconfigured CodeCov.

## FAQ

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

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

In general, you will find most guidance in the
[documentation](https://pytask-dev.readthedocs.io/en/stable/index.html) and some advice
in the FAQ below.
Although the article discusses the src layout in terms of Python packages, it is also
beneficial to structure a project the same way. Next to the reasons discussed there, it
is possible to use a single Python environment for multiple projects without messing
with your PYTHONPATH (via `pip install -e .` or `conda develop .`) each time and still
import modules.

Q: My project is a Python package, but it does not seem to have a version. Where is it?

A: The cookiecutter uses [setuptools_scm](https://github.com/pypa/setuptools_scm/) to
manage the version number. When you install your created project as a Python package
with `pip install -e .`, setuptools_scm tries to infer the version number from the tags
created on the repo.

For example, if you have switched to a commit associated with the tag `v0.2.0`,
setuptools_scm will create a `src/<package_slug>/_version.py` with a variable containing
`version = '0.2.0'` which you can use in your `src/<package_slug>/__init__.py`. If you
are one commit ahead of the tag, you version will be something like `0.2.0.dev1+...`
indicating you are one commit ahead of the tag `v0.2.0`.

If you want to switch to the tradition setup, replace the following code in your
`pyproject.toml`

```toml
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"]
```

with

```toml
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
```

```{toctree}
---
caption: 'Contents:'
maxdepth: 1
---
faq
changes
```
38 changes: 0 additions & 38 deletions environment.yml

This file was deleted.

51 changes: 0 additions & 51 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import shutil
import subprocess
import warnings
from contextlib import suppress
from pathlib import Path

Expand Down Expand Up @@ -62,56 +61,6 @@ def main() -> None:
capture_output=True,
)

if "{{ cookiecutter.create_conda_environment_at_finish }}" == "yes":
if shutil.which("mamba") is not None:
conda_exe = shutil.which("mamba")
else:
conda_exe = shutil.which("conda")

if conda_exe:
subprocess.run(
(
conda_exe,
"env",
"create",
"-f",
(project_path / "environment.yml").absolute().as_posix(),
"--force",
),
check=True,
capture_output=True,
)
# Install pre-commit hooks and run them.
subprocess.run( # noqa: PLW1510
(
conda_exe,
"run",
"-n",
"{{ cookiecutter.conda_environment_name }}",
"pre-commit",
"install",
),
capture_output=True,
)
subprocess.run( # noqa: PLW1510
(
conda_exe,
"run",
"-n",
"{{ cookiecutter.conda_environment_name }}",
"pre-commit",
"run",
"--all-files",
),
capture_output=True,
)
else:
warnings.warn(
"conda environment could not be created since no conda or mamba "
"executable was found.",
stacklevel=1,
)


if __name__ == "__main__":
main()
Loading