|
14 | 14 |
|
15 | 15 | ## `nox` |
16 | 16 |
|
| 17 | +### Writing the `noxfile.py` |
| 18 | +
|
17 | 19 | Projects wanting to use `nox` to run lint checkers and other utilities can use |
18 | 20 | the [`frequenz.repo.config.nox`][] package. |
19 | 21 |
|
20 | | -Make sure to add this package as `dev` dependency to your project's |
21 | | -`pyproject.tom` file, for example: |
22 | | -
|
23 | | -```toml |
24 | | -[project.optional-dependencies] |
25 | | -nox = [ |
26 | | - "nox == 2022.11.21", |
27 | | - "frequenz-repo-config[lib] == 0.1.0", |
28 | | -] |
29 | | -``` |
30 | | -
|
31 | | -Please note the `lib` optional dependency. Make sure you specify the correct |
32 | | -one based on the type of your project (`api`, `actor`, `app`, `lib`). Also make |
33 | | -sure to adjust the versions. |
34 | | -
|
35 | 22 | When writing the `noxfile.py` you should import the `nox` module from this |
36 | 23 | package and use the [`frequenz.repo.config.nox.configure`][] function, |
37 | 24 | which will configure all nox sessions. |
|
40 | 27 | in the [`frequenz.repo.config.nox.default`][] module. For example: |
41 | 28 |
|
42 | 29 | ```python |
43 | | -from frequenz.repo import config |
| 30 | +from frequenz.repo.config import nox |
44 | 31 |
|
45 | | -config.nox.configure(config.nox.default.lib_config) |
| 32 | +nox.configure(nox.default.lib_config) |
46 | 33 | ``` |
47 | 34 |
|
48 | 35 | Again, make sure to pick the correct default configuration based on the type of |
|
53 | 40 | [`copy()`][frequenz.repo.config.nox.config.Config.copy] method: |
54 | 41 |
|
55 | 42 | ```python |
56 | | -from frequenz.repo import config |
| 43 | +from frequenz.repo.config import nox |
57 | 44 |
|
58 | | -conf = config.nox.default.lib_config.copy() |
59 | | -conf.opts.black.append("--diff") |
60 | | -config.nox.configure(conf) |
| 45 | +config = nox.default.lib_config.copy() |
| 46 | +config.opts.black.append("--diff") |
| 47 | +nox.configure(config) |
61 | 48 | ``` |
62 | 49 |
|
63 | 50 | If you need further customization or to define new sessions, you can use the |
|
73 | 60 |
|
74 | 61 | - [`frequenz.repo.config.nox.util`][]: General purpose utility functions. |
75 | 62 |
|
| 63 | +### `pyproject.toml` configuration |
| 64 | +
|
| 65 | +All sessions configured by this package expect the `pyproject.toml` file to |
| 66 | +define specific *dev* dependencies that will be used by the different `nox` |
| 67 | +sessions. |
| 68 | +
|
| 69 | +The following optional dependencies are used and must be defined: |
| 70 | +
|
| 71 | +- `dev-docstrings`: Dependencies to lint the documentation. |
| 72 | +
|
| 73 | + At least these packages should be included: |
| 74 | +
|
| 75 | + - `pydocstyle`: To check the docstrings' format. |
| 76 | + - `darglint`: To check the docstrings' content. |
| 77 | +
|
| 78 | +- `dev-formatting`: Dependencies to check the code's formatting. |
| 79 | +
|
| 80 | + At least these packages should be included: |
| 81 | +
|
| 82 | + - `black`: To check the code's formatting. |
| 83 | + - `isort`: To check the imports' formatting. |
| 84 | +
|
| 85 | +- `dev-mypy`: Dependencies to run `mypy` to check the code's type annotations. |
| 86 | +
|
| 87 | + At least these packages should be included: |
| 88 | +
|
| 89 | + - `mypy`: To check the code's type annotations. |
| 90 | +
|
| 91 | +- `dev-pylint`: Dependencies to run `pylint` to lint the code. |
| 92 | +
|
| 93 | + At least these packages should be included: |
| 94 | +
|
| 95 | + - `pylint`: To lint the code. |
| 96 | +
|
| 97 | +- `dev-pytest`: Dependencies to run the tests using `pytest`. |
| 98 | +
|
| 99 | + At least these packages should be included: |
| 100 | +
|
| 101 | + - `pytest`: To run the tests. |
| 102 | +
|
| 103 | +For some of these you should install too any other dependencies that are used |
| 104 | +by the project. For example, if the project uses `pytest-asyncio`, you should |
| 105 | +include it in the `dev-pytest` optional dependency. |
| 106 | +
|
| 107 | +It is also recommended, but not required, to provide a global `dev` optional |
| 108 | +dependency that includes all the other optional dependencies, so users can |
| 109 | +install all the dependencies needed while developing the project without having |
| 110 | +to run `nox`, which might be a bit slow if you want to do quick iterations. |
| 111 | +
|
| 112 | +```console |
| 113 | +$ pip install -e .[dev] |
| 114 | +... |
| 115 | +$ pytest |
| 116 | +... |
| 117 | +``` |
| 118 | +
|
| 119 | +Here is a sample `pyproject.toml` file that defines all the optional |
| 120 | +dependencies: |
| 121 | +
|
| 122 | +```toml |
| 123 | +[project] |
| 124 | +name = "my-package" |
| 125 | +# ... |
| 126 | +
|
| 127 | +[project.optional-dependencies] |
| 128 | +dev-docstrings = ["pydocstyle == 6.3.0", "darglint == 1.8.1"] |
| 129 | +dev-formatting = ["black == 23.3.0", "isort == 5.12.0"] |
| 130 | +dev-mypy = [ |
| 131 | + "mypy == 1.1.1", |
| 132 | + # For checking tests |
| 133 | + "my-package[dev-pytest]", |
| 134 | +] |
| 135 | +dev-pylint = [ |
| 136 | + "pylint == 2.17.1", |
| 137 | + "pylint-google-style-guide-imports-enforcing == 1.3.0", |
| 138 | + # For checking tests |
| 139 | + "my-package[dev-pytest]", |
| 140 | +] |
| 141 | +dev-pytest = [ |
| 142 | + "pytest == 7.2.2", |
| 143 | + "pytest-asyncio == 0.21.0", |
| 144 | + "pytest-mock == 3.10.0", |
| 145 | +] |
| 146 | +dev = [ |
| 147 | + "my-package[dev-docstrings,dev-formatting,dev-mypy,dev-nox,dev-pylint,dev-pytest]", |
| 148 | +] |
| 149 | +``` |
76 | 150 |
|
77 | 151 | # APIs |
78 | 152 |
|
|
0 commit comments