Repository navigation
feat: add a console script entry point and a license prompt - #34
Merged
Merged
Conversation
- Expose the greeting through src/<package>/__main__.py, register it as a [project.scripts] entry named after the project, and make the root main.py delegate to it so `uv run <project_name>` and `python -m` both work - Ask for a license (MIT, Apache-2.0, BSD-3-Clause or None), render the matching LICENSE from the SPDX text with the author and current year, and set the PEP 639 license and license-files metadata - Keep LICENSE out of template updates via _skip_if_exists, test the entry point, exclude the __main__ guard from coverage, and verify the LICENSE file and console script in the template CI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview and Background
Generated projects now expose a console script named after the project, so
uv run <project_name>(andpython -m <package_name>) runs the application, and generation asks which license to use, writing a LICENSE file and the PEP 639 metadata to match. Previously the only entry point was the rootmain.py, which is not installed with the package and cannot be invoked afteruv build, and projects were generated without any license file orlicensemetadata, leaving the built wheel without licensing information.Related Issues
None
Implementation Approach
src/<package>/__main__.pywith amain()function.[project.scripts]registers"<project_name>" = "<package>.__main__:main"(the key is quoted because project names may contain dots), and the rootmain.pyis kept as a thin delegate so existing instructions and the Compose command keep working. Theif __name__ == "__main__":guard is excluded from coverage.licenseprompt offers MIT, Apache-2.0, BSD-3-Clause, or None (default MIT). The LICENSE template embeds the canonical SPDX texts and fills the year with Copier'sstrftimefilter and the holder withauthor_name. For None the file name renders empty, which Copier treats as "do not create". LICENSE is added to_skip_if_existssocopier updatenever rewrites a license a project has customised or re-dated.pyproject.tomlgetslicense = "<SPDX id>"andlicense-files = ["LICENSE"]only when a license was chosen; hatchling emits these asLicense-ExpressionandLicense-Filein the wheel metadata.from __future__ import annotationswith aTYPE_CHECKINGimport of pytest, which satisfies theTCrules on every supported target version (with the py314 target, Ruff otherwise reports TC002).Changes
copier.yml:licenseprompt;LICENSEin_skip_if_exists.template/{% if license != 'None' %}LICENSE{% endif %}: MIT / Apache-2.0 / BSD-3-Clause texts.template/pyproject.toml: conditionallicenseandlicense-files;[project.scripts]; coverageexclude_also.template/src/{{package_name}}/__main__.py:main();template/main.pydelegates to it.template/tests/test_main.py: captures the greeting printed bymain()..github/workflows/test.yml: passeslicense=MIT, asserts the LICENSE file exists, and runs the console script.README.md,template/README.md: document the prompt anduv run <project_name>.Impact
uv run <project_name>andpython -m <package_name>are new;python main.pyanddocker compose upbehave as before._skip_if_exists, an existing LICENSE is never overwritten. The lockfile is unaffected (uv sync --lockedpasses with the new metadata).Validation Results
Generated projects from this branch for each license choice and for Python 3.10 and 3.14.