Skip to content

Commit e86859d

Browse files
authored
Fix several bugs (frequenz-floss#114)
- Don't add discovered extra path if it's a source path - Fix copying of `Config` and `CommandOptions` - Fix `defaults.api_config` documentation - Remove hack to account for the `pytests` directory - Sort `mkdocs.yml` import inventories - cookiecutter: Fix adding of an empty keyword - editorconfig: Use 4 spaces identation for Markdown files - Remove unnecessary py.typed file - Don't ship development files in source distribution - cookiecutter: Don't ship devel files in source distribution
2 parents 5e860c1 + 1620ac6 commit e86859d

File tree

20 files changed

+90
-27
lines changed

20 files changed

+90
-27
lines changed

.editorconfig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ indent_style = space
1515
trim_trailing_whitespace = true
1616

1717
# 4 space indentation
18-
[*.{py,pyi}]
18+
[*.{md,py,pyi}]
1919
indent_size = 4
2020

2121
# 2 space indentation
2222
[{.editorconfig,CODEOWNERS,LICENSE,*.{in,json,proto,toml,yaml,yml}}]
2323
indent_size = 2
24-
25-
# No indentation size specified for *.md because different blocks have
26-
# different indentation rules

MANIFEST.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
exclude .cookiecutter-replay.json
2+
exclude .darglint
3+
exclude .editorconfig
4+
exclude .gitignore
15
exclude CODEOWNERS
6+
exclude CONTRIBUTING.md
7+
exclude mkdocs.yml
28
exclude noxfile.py
39
recursive-exclude .github *
10+
recursive-exclude cookiecutter *
11+
recursive-exclude docs *
412
recursive-exclude tests *
513
recursive-exclude tests_golden *
614
recursive-include py *.pyi

RELEASE_NOTES.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
## Upgrading
88

9+
- nox: Now the default configuration for API repositories will not automatically add `pytests` as an `extra_path`
10+
11+
The `pytests` directory is not a standard directory that will be auto-discovered by `pytest`, so it should always be included in the `pyproject.toml` file, in the `tool.pytest.ini_options.testpaths` array. Please check your API project is properly configured.
12+
913
### Cookiecutter template
1014

1115
- To make the new workflow to check if release notes were updated you should add the check to the branch protection rules of your repository to require this check to pass. You should also add a new label *"cmd:skip-release-notes"* to be able to override the check. You can use the following script to do it:
@@ -52,6 +56,16 @@
5256

5357
- The distribution package doesn't include tests and other useless files anymore.
5458

59+
- nox
60+
61+
* When discovering path *extra paths*, now paths will not be added if they are also *source paths*, as we don't want any duplicates.
62+
63+
* Fix copying of `Config` and `CommandOptions` objects.
64+
5565
### Cookiecutter template
5666

5767
- Now the CI workflow will checkout the submodules.
68+
69+
- Fix adding of an empty keyword.
70+
71+
- Don't distribute development files in the source distribution.

cookiecutter/local_extensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def keywords(cookiecutter: dict[str, str]) -> str:
172172
cookiecutter_keywords = cookiecutter["keywords"]
173173
if cookiecutter_keywords == default:
174174
cookiecutter_keywords = ""
175-
extended_keywords.extend(k.strip() for k in cookiecutter_keywords.split(","))
175+
extended_keywords.extend(k.strip() for k in cookiecutter_keywords.split(",") if k)
176176
return _json.dumps(extended_keywords)
177177

178178

cookiecutter/{{cookiecutter.github_repo_name}}/MANIFEST.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
exclude .cookiecutter-replay.json
2+
exclude .darglint
3+
exclude .editorconfig
14
exclude .gitignore
25
{%- if cookiecutter.type == "api" %}
36
exclude .gitmodules
47
{%- endif %}
58
exclude CODEOWNERS
9+
exclude CONTRIBUTING.md
10+
exclude mkdocs.yml
611
exclude noxfile.py
712
recursive-exclude .github *
13+
recursive-exclude docs *
814
{%- if cookiecutter.type == "api" %}
915
recursive-exclude pytests *
1016
{%- else %}

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ plugins:
107107
- https://docs.python.org/3/objects.inv
108108
- https://mkdocstrings.github.io/objects.inv
109109
- https://nox.thea.codes/en/stable/objects.inv
110-
- https://setuptools.pypa.io/en/latest/objects.inv
111110
- https://oprypin.github.io/mkdocs-gen-files/objects.inv
111+
- https://setuptools.pypa.io/en/latest/objects.inv
112112
- https://typing-extensions.readthedocs.io/en/stable/objects.inv
113113
- search
114114
- section-index

src/frequenz/repo/config/nox/config.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@ def copy(self) -> Self:
5353
Returns:
5454
The copy of self.
5555
"""
56-
return _dataclasses.replace(self)
56+
return _dataclasses.replace(
57+
self,
58+
black=self.black.copy(),
59+
darglint=self.darglint.copy(),
60+
isort=self.isort.copy(),
61+
mypy=self.mypy.copy(),
62+
pydocstyle=self.pydocstyle.copy(),
63+
pylint=self.pylint.copy(),
64+
pytest=self.pytest.copy(),
65+
)
5766

5867

5968
@_dataclasses.dataclass(kw_only=True, slots=True)
@@ -92,7 +101,7 @@ def __post_init__(self) -> None:
92101
This will add extra paths discovered in config files and other sources.
93102
"""
94103
for path in _util.discover_paths():
95-
if path not in self.extra_paths:
104+
if path not in self.extra_paths and path not in self.source_paths:
96105
self.extra_paths.append(path)
97106

98107
def copy(self, /) -> Self:
@@ -101,7 +110,13 @@ def copy(self, /) -> Self:
101110
Returns:
102111
The copy of self.
103112
"""
104-
return _dataclasses.replace(self)
113+
return _dataclasses.replace(
114+
self,
115+
opts=self.opts.copy(),
116+
sessions=self.sessions.copy(),
117+
source_paths=self.source_paths.copy(),
118+
extra_paths=self.extra_paths.copy(),
119+
)
105120

106121
def path_args(self, session: _nox.Session, /) -> list[str]:
107122
"""Return the file paths to run the checks on.

src/frequenz/repo/config/nox/default.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
method.
2525
"""
2626

27-
import dataclasses
28-
2927
from . import config as _config
30-
from . import util as _util
3128

3229
common_command_options: _config.CommandsOptions = _config.CommandsOptions(
3330
black=[
@@ -87,20 +84,16 @@
8784
api_command_options: _config.CommandsOptions = common_command_options.copy()
8885
"""Default command-line options for APIs."""
8986

90-
api_config: _config.Config = dataclasses.replace(
91-
common_config,
92-
opts=api_command_options,
93-
# We don't check the sources at all because they are automatically generated.
94-
source_paths=[],
95-
# We adapt the path to the tests.
96-
extra_paths=list(_util.replace(common_config.extra_paths, {"tests": "pytests"})),
97-
)
87+
api_config: _config.Config = common_config.copy()
9888
"""Default configuration for APIs.
9989
100-
Same as `common_config`, but with `source_paths` replacing `"src"` with `"py"`
101-
and `extra_paths` replacing `"tests"` with `"pytests"`.
90+
Same as `common_config`, but with an empty `source_paths` (as the sources are
91+
automatically generated, we don't want to test anything in there).
10292
"""
10393

94+
# We don't check the sources at all because they are automatically generated.
95+
api_config.source_paths = []
96+
10497
app_command_options: _config.CommandsOptions = common_command_options.copy()
10598
"""Default command-line options for applications."""
10699

src/frequenz/repo/config/py.typed

Whitespace-only changes.
File renamed without changes.

0 commit comments

Comments
 (0)