Skip to content

Commit 31e54cd

Browse files
committed
apply precommit suggested fixes
1 parent fc4373c commit 31e54cd

8 files changed

+119
-77
lines changed

.github/dependabot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ updates:
1010
groups:
1111
python-packages:
1212
patterns:
13-
- "*"
13+
- "*"

_tasks.py

+47-37
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ def validate_manifest(module_name, project_directory):
2727
"""Validate the new plugin repository against napari requirements."""
2828
try:
2929
from npe2 import PluginManifest
30-
except ImportError as e:
30+
except ImportError:
3131
logger.error("npe2 is not installed. Skipping manifest validation.")
3232
return True
3333

34-
current_directory = Path('.').absolute()
35-
if (current_directory.match(project_directory) and not Path(project_directory).is_absolute()):
34+
current_directory = Path(".").absolute()
35+
if (
36+
current_directory.match(project_directory)
37+
and not Path(project_directory).is_absolute()
38+
):
3639
project_directory = current_directory
3740

38-
path=Path(project_directory) / "src" / Path(module_name) / "napari.yaml"
41+
path = Path(project_directory) / "src" / Path(module_name) / "napari.yaml"
3942

4043
valid = False
4144
try:
@@ -56,18 +59,18 @@ def validate_manifest(module_name, project_directory):
5659

5760

5861
def initialize_new_repository(
59-
install_precommit=False,
60-
plugin_name="napari-foobar",
61-
github_repository_url="provide later",
62-
github_username_or_organization="githubuser",
63-
):
62+
install_precommit=False,
63+
plugin_name="napari-foobar",
64+
github_repository_url="provide later",
65+
github_username_or_organization="githubuser",
66+
):
6467
"""Initialize new plugin repository with git, and optionally pre-commit."""
6568

6669
msg = ""
6770

6871
# Configure git line ending settings
6972
# https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
70-
if os.name == 'nt': # if on Windows, configure git line ending characters
73+
if os.name == "nt": # if on Windows, configure git line ending characters
7174
subprocess.run(["git", "config", "--global", "core.autocrlf", "true"])
7275
else: # for Linux and Mac
7376
subprocess.run(["git", "config", "--global", "core.autocrlf", "input"])
@@ -83,7 +86,10 @@ def initialize_new_repository(
8386
# try to install and update pre-commit
8487
try:
8588
print("install pre-commit ...")
86-
subprocess.run(["python", "-m", "pip", "install", "pre-commit"], stdout=subprocess.DEVNULL)
89+
subprocess.run(
90+
["python", "-m", "pip", "install", "pre-commit"],
91+
stdout=subprocess.DEVNULL,
92+
)
8793
print("updating pre-commit...")
8894
subprocess.run(["pre-commit", "autoupdate"], stdout=subprocess.DEVNULL)
8995
subprocess.run(["git", "add", "."])
@@ -108,15 +114,15 @@ def initialize_new_repository(
108114
pip install -e .
109115
"""
110116
else:
111-
msg +=f"""
117+
msg += f"""
112118
Your plugin template is ready! Next steps:
113119
1. `cd` into your new directory
114120
cd {plugin_name}
115121
# you probably want to install your new package into your env
116122
pip install -e .
117123
"""
118124
# Ensure full reqd/write/execute permissions for .git files
119-
if os.name == 'nt': # if on Windows OS
125+
if os.name == "nt": # if on Windows OS
120126
# Avoid permission denied errors on Github Actions CI
121127
subprocess.run(["attrib", "-h", "rr", ".git", "/s", "/d"])
122128

@@ -129,7 +135,7 @@ def initialize_new_repository(
129135
except Exception:
130136
logger.error("Error at pre-commit install, skipping pre-commit")
131137

132-
if github_repository_url != 'provide later':
138+
if github_repository_url != "provide later":
133139
msg += f"""
134140
2. Create a github repository with the name '{plugin_name}':
135141
https://github.com/{github_username_or_organization}/{plugin_name}.git
@@ -172,31 +178,35 @@ def initialize_new_repository(
172178
return msg
173179

174180

175-
if __name__=="__main__":
181+
if __name__ == "__main__":
176182
logging.basicConfig(level=logging.DEBUG)
177183
logger = logging.getLogger("pre_gen_project")
178184
parser = ArgumentParser()
179-
parser.add_argument("--plugin_name",
180-
dest="plugin_name",
181-
help="The name of your plugin")
182-
parser.add_argument("--module_name",
183-
dest="module_name",
184-
help="Plugin module name")
185-
parser.add_argument("--project_directory",
186-
dest="project_directory",
187-
help="Project directory")
188-
parser.add_argument("--install_precommit",
189-
dest="install_precommit",
190-
help="Install pre-commit",
191-
default="False")
192-
parser.add_argument("--github_repository_url",
193-
dest="github_repository_url",
194-
help="Github repository URL",
195-
default='provide later')
196-
parser.add_argument("--github_username_or_organization",
197-
dest="github_username_or_organization",
198-
help="Github user or organisation name",
199-
default='githubuser')
185+
parser.add_argument(
186+
"--plugin_name", dest="plugin_name", help="The name of your plugin"
187+
)
188+
parser.add_argument("--module_name", dest="module_name", help="Plugin module name")
189+
parser.add_argument(
190+
"--project_directory", dest="project_directory", help="Project directory"
191+
)
192+
parser.add_argument(
193+
"--install_precommit",
194+
dest="install_precommit",
195+
help="Install pre-commit",
196+
default="False",
197+
)
198+
parser.add_argument(
199+
"--github_repository_url",
200+
dest="github_repository_url",
201+
help="Github repository URL",
202+
default="provide later",
203+
)
204+
parser.add_argument(
205+
"--github_username_or_organization",
206+
dest="github_username_or_organization",
207+
help="Github user or organisation name",
208+
default="githubuser",
209+
)
200210
args = parser.parse_args()
201211

202212
# Since bool("False") returns True, we need to check the actual string value
@@ -213,4 +223,4 @@ def initialize_new_repository(
213223
github_repository_url=args.github_repository_url,
214224
github_username_or_organization=args.github_username_or_organization,
215225
)
216-
print(msg)
226+
print(msg)

copier.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@ _tasks:
114114
"--install_precommit={{ install_precommit }}",
115115
"--github_repository_url={{ github_repository_url }}",
116116
"--github_username_or_organization={{ github_username_or_organization }}",
117-
]
117+
]

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ jinja2-time
33
npe2
44
pytest
55
pytest-copie
6-
tox
6+
tox

template/.github/workflows/test_and_deploy.yml.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ jobs:
8989
git tag
9090
python -m build .
9191
twine upload dist/*
92-
{% endraw %}
92+
{% endraw %}

template/.github/{% if install_dependabot %}dependabot.yml{% endif %}.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ updates:
1212
python-packages:
1313
patterns:
1414
- "*"
15-
{% endraw %}
15+
{% endraw %}

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pytest_plugins = 'pytester'
1+
pytest_plugins = "pytester"

tests/test_create_template.py

+66-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
--------------------
44
"""
55

6-
76
import os
87
import subprocess
98

@@ -16,34 +15,43 @@ def run_tox(plugin):
1615
subprocess.check_call(
1716
["tox", "-c", os.path.join(plugin, "tox.ini"), "-e", "py", "--", plugin]
1817
)
19-
except subprocess.CalledProcessError as e:
18+
except subprocess.CalledProcessError:
2019
pytest.fail("Subprocess fail", pytrace=True)
2120

2221

2322
@pytest.mark.parametrize("include_reader_plugin", [True, False])
2423
@pytest.mark.parametrize("include_writer_plugin", [True, False])
2524
@pytest.mark.parametrize("include_sample_data_plugin", [True, False])
2625
@pytest.mark.parametrize("include_widget_plugin", [True, False])
27-
def test_run_plugin_tests(copie, capsys, include_reader_plugin, include_writer_plugin, include_sample_data_plugin, include_widget_plugin):
26+
def test_run_plugin_tests(
27+
copie,
28+
capsys,
29+
include_reader_plugin,
30+
include_writer_plugin,
31+
include_sample_data_plugin,
32+
include_widget_plugin,
33+
):
2834
"""Create a new plugin with the napari plugin template and run its tests."""
29-
result = copie.copy(extra_answers={
30-
"plugin_name": "foo-bar",
31-
"display_name": "Foo Bar",
32-
"module_name": "foo_bar",
33-
"short_description": "Super fast foo for all the bars",
34-
"full_name": "napari bot",
35-
"email": "[email protected]",
36-
"github_username_or_organization": "napari",
37-
"include_reader_plugin": include_reader_plugin,
38-
"include_writer_plugin": include_writer_plugin,
39-
"include_sample_data_plugin": include_sample_data_plugin,
40-
"include_widget_plugin": include_widget_plugin,
41-
})
35+
result = copie.copy(
36+
extra_answers={
37+
"plugin_name": "foo-bar",
38+
"display_name": "Foo Bar",
39+
"module_name": "foo_bar",
40+
"short_description": "Super fast foo for all the bars",
41+
"full_name": "napari bot",
42+
"email": "[email protected]",
43+
"github_username_or_organization": "napari",
44+
"include_reader_plugin": include_reader_plugin,
45+
"include_writer_plugin": include_writer_plugin,
46+
"include_sample_data_plugin": include_sample_data_plugin,
47+
"include_widget_plugin": include_widget_plugin,
48+
}
49+
)
4250

4351
assert result.exit_code == 0
4452
assert result.exception is None
4553
assert result.project_dir.is_dir()
46-
with open(result.project_dir/"README.md") as f:
54+
with open(result.project_dir / "README.md") as f:
4755
assert f.readline() == "# foo-bar\n"
4856
assert result.project_dir.joinpath("src").is_dir()
4957
assert result.project_dir.joinpath("src", "foo_bar", "__init__.py").is_file()
@@ -59,31 +67,40 @@ def test_run_plugin_tests(copie, capsys, include_reader_plugin, include_writer_p
5967
assert (test_path / "test_widget.py").is_file()
6068

6169
# if all are False there are no modules or tests
62-
if True in {include_reader_plugin, include_writer_plugin, include_sample_data_plugin, include_widget_plugin}:
70+
if True in {
71+
include_reader_plugin,
72+
include_writer_plugin,
73+
include_sample_data_plugin,
74+
include_widget_plugin,
75+
}:
6376
run_tox(str(result.project_dir))
6477

6578

6679
def test_run_plugin_tests_with_napari_prefix(copie, capsys):
6780
"""make sure it's also ok to use napari prefix."""
6881
name = "napari-foo"
69-
result = copie.copy(extra_answers={
70-
"plugin_name": name,
71-
"display_name": "napari Foo",
72-
"module_name": "napari_foo",
73-
"short_description": "Super fast foo for all the bars",
74-
"full_name": "napari bot",
75-
"email": "[email protected]",
76-
"github_username_or_organization": "napari",
77-
})
82+
result = copie.copy(
83+
extra_answers={
84+
"plugin_name": name,
85+
"display_name": "napari Foo",
86+
"module_name": "napari_foo",
87+
"short_description": "Super fast foo for all the bars",
88+
"full_name": "napari bot",
89+
"email": "[email protected]",
90+
"github_username_or_organization": "napari",
91+
}
92+
)
7893

7994
assert result.exit_code == 0
8095
assert result.exception is None
8196
assert result.project_dir.is_dir()
82-
with open(result.project_dir/"README.md") as f:
97+
with open(result.project_dir / "README.md") as f:
8398
assert f.readline() == f"# {name}\n"
8499
assert result.project_dir.joinpath("src").is_dir()
85100
assert result.project_dir.joinpath("src", "napari_foo", "__init__.py").is_file()
86-
assert result.project_dir.joinpath("src", "napari_foo", "_tests", "test_reader.py").is_file()
101+
assert result.project_dir.joinpath(
102+
"src", "napari_foo", "_tests", "test_reader.py"
103+
).is_file()
87104

88105

89106
def test_run_select_plugins(copie, capsys):
@@ -106,11 +123,13 @@ def test_run_select_plugins(copie, capsys):
106123
assert result.exit_code == 0
107124
assert result.exception is None
108125
assert result.project_dir.is_dir()
109-
with open(result.project_dir/"README.md") as f:
126+
with open(result.project_dir / "README.md") as f:
110127
assert f.readline() == f"# {name}\n"
111128
assert result.project_dir.joinpath("src").is_dir()
112129
assert result.project_dir.joinpath("src", name, "__init__.py").is_file()
113-
assert result.project_dir.joinpath("src", name, "_tests", "test_reader.py").is_file()
130+
assert result.project_dir.joinpath(
131+
"src", name, "_tests", "test_reader.py"
132+
).is_file()
114133

115134
assert not result.project_dir.joinpath("src", "anything", "_widget.py").is_file()
116135
assert not result.project_dir.joinpath(
@@ -126,7 +145,13 @@ def test_run_select_plugins(copie, capsys):
126145
@pytest.mark.parametrize("include_writer_plugin", [True, False])
127146
@pytest.mark.parametrize("include_sample_data_plugin", [True, False])
128147
@pytest.mark.parametrize("include_widget_plugin", [True, False])
129-
def test_pre_commit_validity(copie, include_reader_plugin, include_writer_plugin, include_sample_data_plugin, include_widget_plugin):
148+
def test_pre_commit_validity(
149+
copie,
150+
include_reader_plugin,
151+
include_writer_plugin,
152+
include_sample_data_plugin,
153+
include_widget_plugin,
154+
):
130155
result = copie.copy(
131156
extra_answers={
132157
"plugin_name": "anything",
@@ -145,6 +170,13 @@ def test_pre_commit_validity(copie, include_reader_plugin, include_writer_plugin
145170
)
146171
result.project_dir.joinpath("setup.cfg").is_file()
147172
try:
148-
subprocess.run(["pre-commit", "run", "--all", "--show-diff-on-failure"], cwd=str(result.project_dir), check=True, capture_output=True)
173+
subprocess.run(
174+
["pre-commit", "run", "--all", "--show-diff-on-failure"],
175+
cwd=str(result.project_dir),
176+
check=True,
177+
capture_output=True,
178+
)
149179
except subprocess.CalledProcessError as e:
150-
pytest.fail(f"pre-commit failed with output:\n{e.stdout.decode()}\nerror:\n{e.stderr.decode()}")
180+
pytest.fail(
181+
f"pre-commit failed with output:\n{e.stdout.decode()}\nerror:\n{e.stderr.decode()}"
182+
)

0 commit comments

Comments
 (0)