Skip to content

Commit a353b1a

Browse files
committed
fix
1 parent 27a502a commit a353b1a

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

src/pkgmt/assets/template/src/package_name/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def hello(name):
2222
@click.argument("name")
2323
def log(name):
2424
"""Log a message"""
25+
# flake8: noqa
2526
from $package_name.log import configure_file_and_print_logger, get_logger
2627

2728
configure_file_and_print_logger()

src/pkgmt/assets/template/src/package_name/log.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"""
1414

1515
import logging
16-
import structlog
1716
from typing import Any, TextIO
1817
import os
1918

src/pkgmt/new.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,23 @@ def package(name, use_setup_py=False):
5353
(root / "MANIFEST.in").unlink()
5454
(root / "pyproject-setup.toml").rename(root / "pyproject.toml")
5555
(root / "src" / package_name / "__init__.py").write_text("")
56+
57+
# Remove flake8: noqa comments from Python files, we added them because
58+
# they contain $TAG, which raises a warning when linting
59+
for py_file in root.rglob("*.py"):
60+
content = py_file.read_text()
61+
lines = content.splitlines()
62+
63+
# Process each line
64+
new_lines = []
65+
for line in lines:
66+
# Skip lines that only contain the noqa comment
67+
if line.strip() == "# flake8: noqa":
68+
continue
69+
# Remove the noqa substring from other lines
70+
new_line = line.replace("# flake8: noqa", "").rstrip()
71+
if new_line:
72+
new_lines.append(new_line)
73+
74+
# Write back the cleaned content
75+
py_file.write_text("\n".join(new_lines) + "\n")

tests/test_new.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_package_setup_py(tmp_empty, uninstall):
2323
ci = Path("some-cool-pkg", ".github", "workflows", "ci.yml").read_text()
2424
manifest = Path("some-cool-pkg", "MANIFEST.in").read_text()
2525
init = Path("some-cool-pkg", "src", "some_cool_pkg", "__init__.py").read_text()
26-
26+
cli = Path("some-cool-pkg", "src", "some_cool_pkg", "cli.py").read_text()
2727
assert '__version__ = "0.1dev"\n' == init
2828
assert 'github = "ploomber/some-cool-pkg"' in pyproject
2929
assert 'package_name = "some_cool_pkg"' in pyproject
@@ -32,6 +32,7 @@ def test_package_setup_py(tmp_empty, uninstall):
3232
assert "src/some_cool_pkg/__init__.py" in setup
3333
assert 'python -c "import some_cool_pkg"' in ci
3434
assert "graft src/some_cool_pkg/assets" in manifest
35+
assert "# flake8: noqa" not in cli
3536

3637
subprocess.check_call(["some-cool-pkg", "log", "user"])
3738
assert json.loads(Path("app.log").read_text()) == {
@@ -50,12 +51,12 @@ def test_package_pyproject_toml(tmp_empty, uninstall):
5051
pyproject = Path("some-cool-pkg", "pyproject.toml").read_text()
5152
ci = Path("some-cool-pkg", ".github", "workflows", "ci.yml").read_text()
5253
init = Path("some-cool-pkg", "src", "some_cool_pkg", "__init__.py").read_text()
53-
54+
cli = Path("some-cool-pkg", "src", "some_cool_pkg", "cli.py").read_text()
5455
assert not Path("some-cool-pkg", "setup.py").exists()
5556
assert not Path("some-cool-pkg", "MANIFEST.in").exists()
5657
assert not Path("some-cool-pkg", "pyproject-setup.toml").exists()
5758

58-
assert init == ""
59+
assert init == "\n"
5960

6061
assert 'github = "ploomber/some-cool-pkg"' in pyproject
6162
assert 'package_name = "some_cool_pkg"' in pyproject
@@ -66,6 +67,7 @@ def test_package_pyproject_toml(tmp_empty, uninstall):
6667
assert 'package-data = { "some_cool_pkg" = ["assets/*", "*.md"] }' in pyproject
6768

6869
assert 'python -c "import some_cool_pkg"' in ci
70+
assert "# flake8: noqa" not in cli
6971

7072
subprocess.check_call(["some-cool-pkg", "log", "user"])
7173
assert json.loads(Path("app.log").read_text()) == {

0 commit comments

Comments
 (0)