|
| 1 | +# cookiecutter-pytask-project |
| 2 | + |
| 3 | +[](https://github.com/pytask-dev/cookiecutter-pytask-project) |
| 4 | +[](https://cookiecutter-pytask-project.readthedocs.io/en/latest) |
| 5 | +[](https://github.com/pytask-dev/cookiecutter-pytask-project/actions?query=branch%3Amain) |
| 6 | +[](https://codecov.io/gh/pytask-dev/cookiecutter-pytask-project) |
| 7 | +[](https://results.pre-commit.ci/latest/github/pytask-dev/cookiecutter-pytask-project/main) |
| 8 | +[](https://github.com/psf/black) |
| 9 | + |
| 10 | +This repository contains a minimal cookiecutter template for a project with |
| 11 | +[pytask](https://github.com/pytask-dev/pytask). |
| 12 | + |
| 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 | + |
| 29 | +## Documentation |
| 30 | + |
| 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 | +``` |
| 76 | + |
| 77 | +with |
| 78 | + |
| 79 | +```toml |
| 80 | +[build-system] |
| 81 | +requires = ["setuptools"] |
| 82 | +build-backend = "setuptools.build_meta" |
| 83 | +``` |
0 commit comments