From a9fee9f4588c004b0c4bbe80f040ed9a8e928c02 Mon Sep 17 00:00:00 2001 From: Melissa DeLucchi Date: Tue, 23 Sep 2025 10:45:28 -0400 Subject: [PATCH 1/2] Include version attribute, and encourage more environment information in bug report. --- .../{1-bug_report.md => 1-bug_report.md.jinja} | 6 +++++- .../src/{{package_name}}/__init__.py.jinja | 3 ++- .../tests/{{package_name}}/test_packaging.py.jinja | 6 ++++++ tests/test_package_creation.py | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) rename python-project-template/.github/ISSUE_TEMPLATE/{1-bug_report.md => 1-bug_report.md.jinja} (67%) create mode 100644 python-project-template/tests/{{package_name}}/test_packaging.py.jinja diff --git a/python-project-template/.github/ISSUE_TEMPLATE/1-bug_report.md b/python-project-template/.github/ISSUE_TEMPLATE/1-bug_report.md.jinja similarity index 67% rename from python-project-template/.github/ISSUE_TEMPLATE/1-bug_report.md rename to python-project-template/.github/ISSUE_TEMPLATE/1-bug_report.md.jinja index 16b6b711..0b211cc5 100644 --- a/python-project-template/.github/ISSUE_TEMPLATE/1-bug_report.md +++ b/python-project-template/.github/ISSUE_TEMPLATE/1-bug_report.md.jinja @@ -9,9 +9,13 @@ assignees: '' **Bug report** +**Environment Information** + + **Before submitting** Please check the following: -- [ ] 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. +- [ ] 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. +- [ ] I have included information about my environment, including the version of this package (e.g. `{{package_name}}.__version__`) - [ ] 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. - [ ] If I have a solution in mind, I have provided an explanation and/or pseudocode and/or task list. diff --git a/python-project-template/src/{{package_name}}/__init__.py.jinja b/python-project-template/src/{{package_name}}/__init__.py.jinja index f476f454..4e745ebb 100644 --- a/python-project-template/src/{{package_name}}/__init__.py.jinja +++ b/python-project-template/src/{{package_name}}/__init__.py.jinja @@ -1,4 +1,5 @@ -{%- if create_example_module -%} +from ._version import __version__ +{% if create_example_module -%} from .example_module import greetings, meaning __all__ = ["greetings", "meaning"] diff --git a/python-project-template/tests/{{package_name}}/test_packaging.py.jinja b/python-project-template/tests/{{package_name}}/test_packaging.py.jinja new file mode 100644 index 00000000..bf2dc023 --- /dev/null +++ b/python-project-template/tests/{{package_name}}/test_packaging.py.jinja @@ -0,0 +1,6 @@ +import {{package_name}} + + +def test_version(): + """Check to see that we can get the package version""" + assert {{package_name}}.__version__ is not None \ No newline at end of file diff --git a/tests/test_package_creation.py b/tests/test_package_creation.py index ca2bacba..e1e1f077 100644 --- a/tests/test_package_creation.py +++ b/tests/test_package_creation.py @@ -161,7 +161,7 @@ def test_use_black_and_no_example_modules(copie): assert successfully_created_project(result) assert directory_structure_is_correct(result) - assert pylint_runs_successfully(result) + assert not pylint_runs_successfully(result) assert contains_required_files(result) # make sure that the files that were not requested were not created From eb651bab38694a46af603de94e76df89fb82cc0d Mon Sep 17 00:00:00 2001 From: Melissa DeLucchi Date: Tue, 23 Sep 2025 13:41:06 -0400 Subject: [PATCH 2/2] Clarify pylint behavior, and make it pass again. --- python-project-template/pyproject.toml.jinja | 2 +- tests/test_package_creation.py | 30 +++++++------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/python-project-template/pyproject.toml.jinja b/python-project-template/pyproject.toml.jinja index 76586aad..4c5eef9f 100644 --- a/python-project-template/pyproject.toml.jinja +++ b/python-project-template/pyproject.toml.jinja @@ -9,7 +9,7 @@ license = "MIT" license = "GPL-3.0-only" {%- endif %} {%- if project_license != 'none' %} -license_file = ["LICENSE"] +license-files = ["LICENSE"] {%- endif %} readme = "README.md" authors = [ diff --git a/tests/test_package_creation.py b/tests/test_package_creation.py index f87a274f..d7d0a768 100644 --- a/tests/test_package_creation.py +++ b/tests/test_package_creation.py @@ -18,6 +18,12 @@ def create_project_with_basic_checks(copie, extra_answers, package_name="example result.exit_code == 0 and result.exception is None and result.project_dir.is_dir() ), "Did not successfully create project" + # install the `example_package` into the existing python environment. + build_results = subprocess.run( + ["python", "-m", "pip", "install", "--no-deps", "."], cwd=result.project_dir, check=False + ) + assert build_results.returncode == 0 + # pyproject_toml_is_valid precommit_results = subprocess.run( ["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 print("Required file not generated:", file) assert all_found - return result - - -def black_runs_successfully(result): - """Test to ensure that the black linter runs successfully on the project""" - # run black with `--check` to look for lint errors, but don't fix them. + # black_runs_successfully black_results = subprocess.run( ["python", "-m", "black", "--check", (result.project_dir / "src")], cwd=result.project_dir, check=False, ) - return black_results.returncode == 0 + assert black_results.returncode == 0 + + return result def pylint_runs_successfully(result): @@ -123,6 +126,7 @@ def test_all_defaults(copie): # run copier to hydrate a temporary project result = create_project_with_basic_checks(copie, {}) + # uses ruff instead of (black/isort/pylint) assert not pylint_runs_successfully(result) # 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): break assert found_line - assert black_runs_successfully(result) - @pytest.mark.parametrize( "enforce_style", @@ -187,9 +189,6 @@ def test_code_style_combinations(copie, enforce_style): } result = create_project_with_basic_checks(copie, extra_answers) - # black would still run successfully. - assert black_runs_successfully(result) - @pytest.mark.parametrize( "notification", @@ -211,7 +210,6 @@ def test_smoke_test_notification(copie, notification): # run copier to hydrate a temporary project result = create_project_with_basic_checks(copie, extra_answers) - assert black_runs_successfully(result) @pytest.mark.parametrize( @@ -233,8 +231,6 @@ def test_license(copie, license): # run copier to hydrate a temporary project result = create_project_with_basic_checks(copie, extra_answers) - assert black_runs_successfully(result) - @pytest.mark.parametrize( "doc_answers", @@ -255,7 +251,6 @@ def test_doc_combinations(copie, doc_answers): # run copier to hydrate a temporary project result = create_project_with_basic_checks(copie, doc_answers) - assert black_runs_successfully(result) assert docs_build_successfully(result) assert (result.project_dir / "docs").is_dir() @@ -279,7 +274,6 @@ def test_doc_combinations_no_docs(copie, doc_answers): # run copier to hydrate a temporary project result = create_project_with_basic_checks(copie, doc_answers) - assert black_runs_successfully(result) assert not (result.project_dir / "docs").is_dir() @@ -296,8 +290,6 @@ def test_test_lowest_version(copie, test_lowest_version): # run copier to hydrate a temporary project result = create_project_with_basic_checks(copie, extra_answers) - assert black_runs_successfully(result) - def test_github_workflows_schema(copie): """Confirm the current GitHub workflows have valid schemas."""