Skip to content

Commit b302f71

Browse files
authored
Move dev dependencies to pyproject.toml (#199)
With this we have only one central place where dependencies are declared, so we can make sure we have a consistent view on the dependencies. As a side effect, the `formatting` session will install some extra unneded dependencies (the package dependencies), but this allow us to pin the tools versions and be sure everyone will use the same version. A new alias is also added, so users wanting to setup a local development enviroment can now just do a `pip install .[dev]` and that's it. The CONTRIBUTING guide is updated to reflect this.
2 parents 0bcf61c + 5975225 commit b302f71

File tree

4 files changed

+74
-33
lines changed

4 files changed

+74
-33
lines changed

.github/workflows/ci.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
- name: Install build dependencies
8686
run: |
8787
python -m pip install -U pip
88-
python -m pip install .[docs]
88+
python -m pip install .[docs-gen]
8989
9090
- name: Generate the documentation
9191
env:
@@ -163,7 +163,7 @@ jobs:
163163
if: steps.mike-metadata.outputs.version
164164
run: |
165165
python -m pip install -U pip
166-
python -m pip install .[docs]
166+
python -m pip install .[docs-gen]
167167
168168
- name: Fetch the gh-pages branch
169169
if: steps.mike-metadata.outputs.version

CONTRIBUTING.md

+29-7
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,55 @@ all the dependencies too):
1818
python -m pip install -e .
1919
```
2020

21-
You can also use `nox` to run the tests and other checks:
21+
Or you can install all development dependencies (`mypy`, `pylint`, `pytest`,
22+
etc.) in one go too:
23+
```sh
24+
python -m pip install -e .[dev]
25+
```
26+
27+
If you don't want to install all the dependencies, you can also use `nox` to
28+
run the tests and other checks creating its own virtual environments:
2229

2330
```sh
24-
python -m pip install nox toml tomli
31+
python -m pip install nox toml
2532
nox
2633
```
2734

2835
You can also use `nox -R` to reuse the current testing environment to speed up
2936
test at the expense of a higher chance to end up with a dirty test environment.
3037

31-
### Running tests individually
38+
### Running tests / checks individually
3239

3340
For a better development test cycle you can install the runtime and test
3441
dependencies and run `pytest` manually.
3542

3643
```sh
37-
python -m pip install .
38-
python -m pip install pytest pytest-asyncio pytest-mock time_machine async_solipsism
44+
python -m pip install .[pytest] # included in .[dev] too
3945

4046
# And for example
4147
pytest tests/test_sdk.py
4248
```
4349

44-
To build the documentation, first install the dependencies:
50+
Or you can use `nox`:
51+
52+
```sh
53+
nox -R -s pytest -- test/test_sdk.py
54+
```
55+
56+
The same appliest to `pylint` or `mypy` for example:
57+
58+
```sh
59+
nox -R -s pylint -- test/test_sdk.py
60+
nox -R -s mypy -- test/test_sdk.py
61+
```
62+
63+
### Building the documentation
64+
65+
To build the documentation, first install the dependencies (if you didn't
66+
install all `dev` dependencies):
4567

4668
```sh
47-
python -m pip install -e .[docs]
69+
python -m pip install -e .[docs-gen]
4870
```
4971

5072
Then you can build the documentation (it will be written in the `site/`

noxfile.py

+7-23
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,6 @@ def min_dependencies() -> List[str]:
8484
return min_deps
8585

8686

87-
FMT_DEPS = ["black", "isort"]
88-
DOCSTRING_DEPS = ["pydocstyle", "darglint"]
89-
PYTEST_DEPS = [
90-
"pytest",
91-
"pytest-cov",
92-
"pytest-mock",
93-
"pytest-asyncio",
94-
"time-machine",
95-
"async-solipsism",
96-
]
97-
MYPY_DEPS = ["mypy", "pandas-stubs", "grpc-stubs"]
98-
MIN_DEPS = min_dependencies()
99-
100-
10187
def _source_file_paths(session: nox.Session) -> List[str]:
10288
"""Return the file paths to run the checks on.
10389
@@ -145,9 +131,7 @@ def ci_checks_max(session: nox.Session) -> None:
145131
Args:
146132
session: the nox session.
147133
"""
148-
session.install(
149-
".[docs]", "pylint", "nox", *PYTEST_DEPS, *FMT_DEPS, *DOCSTRING_DEPS, *MYPY_DEPS
150-
)
134+
session.install(".[dev]")
151135

152136
formatting(session, False)
153137
mypy(session, False)
@@ -165,7 +149,7 @@ def formatting(session: nox.Session, install_deps: bool = True) -> None:
165149
install_deps: True if dependencies should be installed.
166150
"""
167151
if install_deps:
168-
session.install(*FMT_DEPS)
152+
session.install(".[format]")
169153

170154
paths = _source_file_paths(session)
171155
session.run("black", "--check", *paths)
@@ -183,7 +167,7 @@ def mypy(session: nox.Session, install_deps: bool = True) -> None:
183167
if install_deps:
184168
# install the package itself as editable, so that it is possible to do
185169
# fast local tests with `nox -R -e mypy`.
186-
session.install("-e", ".[docs]", "nox", *MYPY_DEPS, *PYTEST_DEPS)
170+
session.install("-e", ".[mypy]")
187171

188172
common_args = [
189173
"--install-types",
@@ -228,7 +212,7 @@ def pylint(session: nox.Session, install_deps: bool = True) -> None:
228212
if install_deps:
229213
# install the package itself as editable, so that it is possible to do
230214
# fast local tests with `nox -R -e pylint`.
231-
session.install("-e", ".[docs]", "pylint", "nox", *PYTEST_DEPS)
215+
session.install("-e", ".[pylint]")
232216

233217
paths = _source_file_paths(session)
234218
session.run(
@@ -250,7 +234,7 @@ def docstrings(session: nox.Session, install_deps: bool = True) -> None:
250234
install_deps: True if dependencies should be installed.
251235
"""
252236
if install_deps:
253-
session.install(*DOCSTRING_DEPS, "toml")
237+
session.install(".[docs-lint]")
254238

255239
paths = _source_file_paths(session)
256240
session.run("pydocstyle", *paths)
@@ -281,7 +265,7 @@ def pytest_max(session: nox.Session, install_deps: bool = True) -> None:
281265
if install_deps:
282266
# install the package itself as editable, so that it is possible to do
283267
# fast local tests with `nox -R -e pytest_max`.
284-
session.install("-e", ".", *PYTEST_DEPS)
268+
session.install("-e", ".[pytest]")
285269

286270
_pytest_impl(session, "max")
287271

@@ -297,7 +281,7 @@ def pytest_min(session: nox.Session, install_deps: bool = True) -> None:
297281
if install_deps:
298282
# install the package itself as editable, so that it is possible to do
299283
# fast local tests with `nox -R -e pytest_min`.
300-
session.install("-e", ".", *PYTEST_DEPS, *MIN_DEPS)
284+
session.install("-e", ".[pytest]", *min_dependencies())
301285

302286
_pytest_impl(session, "min")
303287

pyproject.toml

+36-1
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,49 @@ name ="Frequenz Energy-as-a-Service GmbH"
4848
4949

5050
[project.optional-dependencies]
51-
docs = [
51+
docs-gen = [
5252
"mike >= 1.1.2, < 2",
5353
"mkdocs-gen-files >= 0.4.0, < 0.5.0",
5454
"mkdocs-literate-nav >= 0.4.0, < 0.5.0",
5555
"mkdocs-material >= 8.5.7, < 9",
5656
"mkdocs-section-index >= 0.3.4, < 0.4.0",
5757
"mkdocstrings[python] >= 0.19.0, < 0.20.0",
5858
]
59+
docs-lint = [
60+
"pydocstyle",
61+
"darglint",
62+
]
63+
format = [
64+
"black",
65+
"isort",
66+
]
67+
nox = [
68+
"nox",
69+
"toml",
70+
]
71+
pytest = [
72+
"pytest",
73+
"pytest-cov",
74+
"pytest-mock",
75+
"pytest-asyncio",
76+
"time-machine",
77+
"async-solipsism",
78+
]
79+
mypy = [
80+
"mypy",
81+
"pandas-stubs",
82+
"grpc-stubs",
83+
# For checking the noxfile, docs/ script, and tests
84+
"frequenz-sdk[docs-gen,nox,pytest]",
85+
]
86+
pylint = [
87+
"pylint",
88+
# For checking the noxfile, docs/ script, and tests
89+
"frequenz-sdk[docs-gen,nox,pytest]",
90+
]
91+
dev = [
92+
"frequenz-sdk[docs-gen,docs-lint,format,nox,pytest,mypy,pylint]",
93+
]
5994

6095
[project.urls]
6196
Changelog = "https://github.com/frequenz-floss/frequenz-sdk-python/releases"

0 commit comments

Comments
 (0)