Skip to content

Commit 0d7be2d

Browse files
authored
Enhance the tutorial on how to set up a project. (#217)
1 parent 0641f39 commit 0d7be2d

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

docs/source/changes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
1414
exception as an input. Closes :gh:`145`.
1515
- :gh:`213` improves coverage and reporting.
1616
- :gh:`215` makes the help pages of the CLI prettier.
17+
- :gh:`217` enhances the tutorial on how to set up a project.
1718

1819

1920
0.1.7 - 2022-01-28

docs/source/tutorials/how_to_set_up_a_project.rst

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ of the most elementary pieces.
88

99
.. seealso::
1010

11-
If you want to start from a template or take inspiration from previous projects, look at :doc:`../how_to_guides/bp_templates_and_projects`.
11+
If you want to start from a template or take inspiration from previous projects,
12+
look at :doc:`../how_to_guides/bp_templates_and_projects`.
1213

1314

1415
The directory structure
@@ -26,7 +27,9 @@ The following directory tree is an example of how a project can be set up.
2627
│ ├────config.py
2728
│ └────...
2829
29-
├───setup.py
30+
├───setup.cfg
31+
32+
├───pyproject.toml
3033
3134
├───.pytask.sqlite3
3235
@@ -94,50 +97,68 @@ The build directory ``bld`` is created automatically during the execution. It is
9497
to store the products of tasks and can be deleted to rebuild the entire project.
9598

9699

97-
``setup.py``
98-
~~~~~~~~~~~~
100+
Install the project
101+
~~~~~~~~~~~~~~~~~~~
99102

100-
The ``setup.py`` is useful to turn the source directory into a Python package. It allows
101-
to perform imports from ``src``. E.g., ``from src.config import SRC``.
103+
Two files are necessary to turn the source directory into a Python package. It allows to
104+
perform imports from ``my_project``. E.g., ``from my_project.config import SRC``. We
105+
also need ``pip >= 21.1``.
102106

103-
Here is the content of the file.
107+
First, we need a ``setup.cfg`` which contains the name and version of the package and
108+
where the source code can be found.
104109

105-
.. code-block:: python
110+
.. code-block:: ini
106111
107-
# Content of setup.py
112+
# Content of setup.cfg
108113
109-
from setuptools import setup
114+
[metadata]
115+
name = my_project
116+
version = 0.0.1
110117
118+
[options]
119+
packages = find:
120+
package_dir =
121+
=src
111122
112-
setup(
113-
name="my_project",
114-
version="0.0.1",
115-
packages=find_packages(where="src"),
116-
package_dir={"": "src"},
117-
)
123+
[options.packages.find]
124+
where = src
118125
119-
Then, install the package into your environment with
126+
Secondly, you need a ``pyproject.toml`` with this content:
120127

121-
.. code-block:: console
128+
.. code-block:: toml
129+
130+
# Content of pyproject.toml
122131
123-
$ conda develop .
132+
[build-system]
133+
requires = ["setuptools"]
134+
build-backend = "setuptools.build_meta"
124135
125-
# or
136+
.. seealso::
137+
138+
You find this and more information in the documentation for `setuptools
139+
<https://setuptools.pypa.io/en/latest/userguide/quickstart.html>`_.
140+
141+
Now, you can install the package into your environment with
142+
143+
.. code-block:: console
126144
127145
$ pip install -e .
128146
129-
Both commands will produce an editable install of the project which means any changes in
130-
the source files of the package are reflected in the installed version of the package.
147+
This command will trigger an editable install of the project which means any changes in
148+
the source files of the package are immediately reflected in the installed version of
149+
the package.
131150

132-
.. tip::
151+
.. important::
133152

134-
Do not forget to rerun the editable install every time you recreate your Python
153+
Do not forget to rerun the editable install should you recreate your Python
135154
environment.
136155

137156
.. tip::
138157

139158
For a more sophisticated setup where versions are managed via tags on the
140159
repository, check out `setuptools_scm <https://github.com/pypa/setuptools_scm>`_.
160+
The tool is also used in `cookiecutter-pytask-project
161+
<https://github.com/pytask-dev/cookiecutter-pytask-project>`_.
141162

142163

143164
Further Reading

0 commit comments

Comments
 (0)