Skip to content

Commit 5cf4cd2

Browse files
authored
Include version attribute (#533)
* Include version attribute, and encourage more environment information in bug report. * Clarify pylint behavior, and make it pass again.
1 parent ca23618 commit 5cf4cd2

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

python-project-template/.github/ISSUE_TEMPLATE/1-bug_report.md renamed to python-project-template/.github/ISSUE_TEMPLATE/1-bug_report.md.jinja

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ assignees: ''
99
**Bug report**
1010

1111

12+
**Environment Information**
13+
14+
1215
**Before submitting**
1316
Please check the following:
1417

15-
- [ ] I have described the situation in which the bug arose, including what code was executed, information about my environment, and any applicable data others will need to reproduce the problem.
18+
- [ ] I have described the situation in which the bug arose, including what code was executed, and any applicable data others will need to reproduce the problem.
19+
- [ ] I have included information about my environment, including the version of this package (e.g. `{{package_name}}.__version__`)
1620
- [ ] I have included available evidence of the unexpected behavior (including error messages, screenshots, and/or plots) as well as a description of what I expected instead.
1721
- [ ] If I have a solution in mind, I have provided an explanation and/or pseudocode and/or task list.

python-project-template/pyproject.toml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "MIT"
99
license = "GPL-3.0-only"
1010
{%- endif %}
1111
{%- if project_license != 'none' %}
12-
license_file = ["LICENSE"]
12+
license-files = ["LICENSE"]
1313
{%- endif %}
1414
readme = "README.md"
1515
authors = [

python-project-template/src/{{package_name}}/__init__.py.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
{%- if create_example_module -%}
1+
from ._version import __version__
2+
{% if create_example_module -%}
23
from .example_module import greetings, meaning
34

45
__all__ = ["greetings", "meaning"]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {{package_name}}
2+
3+
4+
def test_version():
5+
"""Check to see that we can get the package version"""
6+
assert {{package_name}}.__version__ is not None

tests/test_package_creation.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def create_project_with_basic_checks(copie, extra_answers, package_name="example
1818
result.exit_code == 0 and result.exception is None and result.project_dir.is_dir()
1919
), "Did not successfully create project"
2020

21+
# install the `example_package` into the existing python environment.
22+
build_results = subprocess.run(
23+
["python", "-m", "pip", "install", "--no-deps", "."], cwd=result.project_dir, check=False
24+
)
25+
assert build_results.returncode == 0
26+
2127
# pyproject_toml_is_valid
2228
precommit_results = subprocess.run(
2329
["pre-commit", "run", "validate-pyproject"], cwd=result.project_dir, check=False
@@ -48,19 +54,16 @@ def create_project_with_basic_checks(copie, extra_answers, package_name="example
4854
print("Required file not generated:", file)
4955
assert all_found
5056

51-
return result
52-
53-
54-
def black_runs_successfully(result):
55-
"""Test to ensure that the black linter runs successfully on the project"""
56-
# run black with `--check` to look for lint errors, but don't fix them.
57+
# black_runs_successfully
5758
black_results = subprocess.run(
5859
["python", "-m", "black", "--check", (result.project_dir / "src")],
5960
cwd=result.project_dir,
6061
check=False,
6162
)
6263

63-
return black_results.returncode == 0
64+
assert black_results.returncode == 0
65+
66+
return result
6467

6568

6669
def pylint_runs_successfully(result):
@@ -123,6 +126,7 @@ def test_all_defaults(copie):
123126
# run copier to hydrate a temporary project
124127
result = create_project_with_basic_checks(copie, {})
125128

129+
# uses ruff instead of (black/isort/pylint)
126130
assert not pylint_runs_successfully(result)
127131

128132
# check to see if the README file was hydrated with copier answers.
@@ -161,8 +165,6 @@ def test_use_black_and_no_example_modules(copie):
161165
break
162166
assert found_line
163167

164-
assert black_runs_successfully(result)
165-
166168

167169
@pytest.mark.parametrize(
168170
"enforce_style",
@@ -187,9 +189,6 @@ def test_code_style_combinations(copie, enforce_style):
187189
}
188190
result = create_project_with_basic_checks(copie, extra_answers)
189191

190-
# black would still run successfully.
191-
assert black_runs_successfully(result)
192-
193192

194193
@pytest.mark.parametrize(
195194
"notification",
@@ -211,7 +210,6 @@ def test_smoke_test_notification(copie, notification):
211210

212211
# run copier to hydrate a temporary project
213212
result = create_project_with_basic_checks(copie, extra_answers)
214-
assert black_runs_successfully(result)
215213

216214

217215
@pytest.mark.parametrize(
@@ -233,8 +231,6 @@ def test_license(copie, license):
233231
# run copier to hydrate a temporary project
234232
result = create_project_with_basic_checks(copie, extra_answers)
235233

236-
assert black_runs_successfully(result)
237-
238234

239235
@pytest.mark.parametrize(
240236
"doc_answers",
@@ -255,7 +251,6 @@ def test_doc_combinations(copie, doc_answers):
255251
# run copier to hydrate a temporary project
256252
result = create_project_with_basic_checks(copie, doc_answers)
257253

258-
assert black_runs_successfully(result)
259254
assert docs_build_successfully(result)
260255
assert (result.project_dir / "docs").is_dir()
261256

@@ -279,7 +274,6 @@ def test_doc_combinations_no_docs(copie, doc_answers):
279274
# run copier to hydrate a temporary project
280275
result = create_project_with_basic_checks(copie, doc_answers)
281276

282-
assert black_runs_successfully(result)
283277
assert not (result.project_dir / "docs").is_dir()
284278

285279

@@ -296,8 +290,6 @@ def test_test_lowest_version(copie, test_lowest_version):
296290
# run copier to hydrate a temporary project
297291
result = create_project_with_basic_checks(copie, extra_answers)
298292

299-
assert black_runs_successfully(result)
300-
301293

302294
def test_github_workflows_schema(copie):
303295
"""Confirm the current GitHub workflows have valid schemas."""

0 commit comments

Comments
 (0)