Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ But you might still need to adapt your code:
- `dco-merge-queue.yml`: `DCO`
- `labeler.yml`: `Label`

- Added the [`flake8-datetimez`](https://github.com/pjknkda/flake8-datetimez) plugin to the `flake8` session. This plugin prevents accidental use of naive `datetime` objects by flagging calls that create or return datetimes without timezone information.

## Bug Fixes

<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
Expand Down
37 changes: 37 additions & 0 deletions cookiecutter/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def main() -> None:
print("Migrating pyproject license metadata to SPDX format...")
migrate_pyproject_license()
print("=" * 72)
print("Adding flake8-datetimez plugin to dev-flake8 dependencies...")
migrate_add_flake8_datetimez()
print("=" * 72)
print()

if _manual_steps:
Expand Down Expand Up @@ -298,6 +301,40 @@ def migrate_pyproject_license() -> None: # pylint: disable=too-many-branches
print(" Updated pyproject.toml: migrated license metadata")


def migrate_add_flake8_datetimez() -> None:
"""Add the flake8-datetimez plugin to dev-flake8 dependencies."""
pyproject_path = Path("pyproject.toml")
if not pyproject_path.exists():
print(" Skipping pyproject.toml (file not found)")
return

content = pyproject_path.read_text(encoding="utf-8")

if "flake8-datetimez" in content:
print(" Skipped pyproject.toml (flake8-datetimez already present)")
return

# Look for a pinned flake8 dependency line (e.g. "flake8 == 7.3.0") and
# insert flake8-datetimez right after it.
match = re.search(r'( "flake8\s*==.*",?\n)', content)
if not match:
manual_step(
"Could not find a flake8 pin in pyproject.toml. "
'Please add `"flake8-datetimez == 20.10.0"` to the '
"`dev-flake8` optional dependencies."
)
return

flake8_line = match.group(1)
new_content = content.replace(
flake8_line,
flake8_line + ' "flake8-datetimez == 20.10.0",\n',
1,
)
replace_file_contents_atomically(pyproject_path, content, new_content, count=1)
print(" Updated pyproject.toml: added flake8-datetimez plugin")


def read_project_type() -> str | None:
"""Read the cookiecutter project type from the replay file."""
replay_path = Path(".cookiecutter-replay.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ email = "{{cookiecutter.author_email}}"
[project.optional-dependencies]
dev-flake8 = [
"flake8 == 7.3.0",
"flake8-datetimez == 20.10.0",
"flake8-docstrings == 1.7.0",
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
"pydoclint == 0.6.10",
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extra-lint-examples = [
]
dev-flake8 = [
"flake8 == 7.3.0",
"flake8-datetimez == 20.10.0",
"flake8-docstrings == 1.7.0",
"flake8-pyproject == 1.2.4", # For reading the flake8 config from pyproject.toml
"pydoclint == 0.8.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ email = "floss@frequenz.com"
[project.optional-dependencies]
dev-flake8 = [
"flake8 == 7.3.0",
"flake8-datetimez == 20.10.0",
"flake8-docstrings == 1.7.0",
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
"pydoclint == 0.6.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ email = "floss@frequenz.com"
[project.optional-dependencies]
dev-flake8 = [
"flake8 == 7.3.0",
"flake8-datetimez == 20.10.0",
"flake8-docstrings == 1.7.0",
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
"pydoclint == 0.6.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ email = "floss@frequenz.com"
[project.optional-dependencies]
dev-flake8 = [
"flake8 == 7.3.0",
"flake8-datetimez == 20.10.0",
"flake8-docstrings == 1.7.0",
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
"pydoclint == 0.6.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ email = "floss@frequenz.com"
[project.optional-dependencies]
dev-flake8 = [
"flake8 == 7.3.0",
"flake8-datetimez == 20.10.0",
"flake8-docstrings == 1.7.0",
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
"pydoclint == 0.6.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ email = "floss@frequenz.com"
[project.optional-dependencies]
dev-flake8 = [
"flake8 == 7.3.0",
"flake8-datetimez == 20.10.0",
"flake8-docstrings == 1.7.0",
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
"pydoclint == 0.6.10",
Expand Down