@@ -8,7 +8,8 @@ of the most elementary pieces.
8
8
9
9
.. seealso ::
10
10
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 `.
12
13
13
14
14
15
The directory structure
@@ -26,7 +27,9 @@ The following directory tree is an example of how a project can be set up.
26
27
│ ├────config.py
27
28
│ └────...
28
29
│
29
- ├───setup.py
30
+ ├───setup.cfg
31
+ │
32
+ ├───pyproject.toml
30
33
│
31
34
├───.pytask.sqlite3
32
35
│
@@ -94,50 +97,68 @@ The build directory ``bld`` is created automatically during the execution. It is
94
97
to store the products of tasks and can be deleted to rebuild the entire project.
95
98
96
99
97
- `` setup.py ``
98
- ~~~~~~~~~~~~
100
+ Install the project
101
+ ~~~~~~~~~~~~~~~~~~~
99
102
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 ``.
102
106
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.
104
109
105
- .. code-block :: python
110
+ .. code-block :: ini
106
111
107
- # Content of setup.py
112
+ # Content of setup.cfg
108
113
109
- from setuptools import setup
114
+ [metadata]
115
+ name = my_project
116
+ version = 0.0.1
110
117
118
+ [options]
119
+ packages = find:
120
+ package_dir =
121
+ =src
111
122
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
118
125
119
- Then, install the package into your environment with
126
+ Secondly, you need a `` pyproject.toml `` with this content:
120
127
121
- .. code-block :: console
128
+ .. code-block :: toml
129
+
130
+ # Content of pyproject.toml
122
131
123
- $ conda develop .
132
+ [build-system]
133
+ requires = ["setuptools"]
134
+ build-backend = "setuptools.build_meta"
124
135
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
126
144
127
145
$ pip install -e .
128
146
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.
131
150
132
- .. tip ::
151
+ .. important ::
133
152
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
135
154
environment.
136
155
137
156
.. tip ::
138
157
139
158
For a more sophisticated setup where versions are managed via tags on the
140
159
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> `_.
141
162
142
163
143
164
Further Reading
0 commit comments