Plugin for poetry that creates/updates an package_info.py file with various details about the project/package.
Project description
Poetry Plugin: Package Info
This package is a plugin that generates an package_info.py
file with variables containing values from pyproject.toml and git.
Installation
The easiest way to install the package-info
plugin is via the self add
command of Poetry.
poetry self add poetry-plugin-package-info
If you used pipx
to install Poetry you can add the plugin via the pipx inject
command.
pipx inject poetry poetry-plugin-package-info
Otherwise, if you used pip
to install Poetry you can add the plugin packages via the pip install
command.
pip install poetry-plugin-plugin-package-info
Usage
By default, the package-info.py
file is generated only when using the package-info generate-file
command in poetry,
poetry package-info generate-file
The plugin can be enabled to automatically patch wheel files after poetry build
is run by adding the patch-wheels
to the project pyproject.toml file.
[tool.poetry-plugin-package-info]
patch-build-formats = ['wheel', 'sdist'] # or can just do ['all']
The plugin can be re-configured in the pyproject.toml file, below are the options and their defaults.
[tool.poetry-plugin-package-info]
# Patch any .whl files produced by `poetry build`
patch-build-formats = []
# The path relative to the pyproject.toml file
package-info-file-path = "package_name_in_snake_case/package_info.py"
# Search parent directories (relative to pyproject.toml) for .git
git-search-parent-directories = false
# The formatter to format the generated package_info.py file.
formatter = "poetry-plugin-package-info.formatters.black:BlackContentFormatter"
# The generators to use to extract property values.
generators = {
project = "poetry-plugin-package-info.generators.project:ProjectContentFormatter",
git = "poetry-plugin-package-info.generators.git:GitContentFormatter",
}
template = """\
\"\"\"Auto-generated by poetry-plugin-package-info at {{ now().replace(microsecond=0).isoformat() }}.\"\"\"\
{% for import in imports %}
import {{import}}
{% endfor %}
class PackageInfo:
{% for property in properties %}\
{{ " " }}{{property.property_config.variable_name}}: {{as_python(property.property_type)}} = {{as_python(property.property_value)}}
{% endfor %}
"""
# ordered list of variables to include in the file.
properties = [
"project-name",
"project-description",
"project-version",
"project-authors",
"project-license",
"project-classifiers",
"project-documentation",
"project-repository",
"project-homepage",
"project-maintainers",
"project-keywords",
"git-commit-id",
"git-commit-author-name",
"git-commit-author-email",
"git-commit-timestamp",
"git-branch-name",
"git-branch-path",
"git-has-staged-changes",
"git-has-unstaged-changes",
"git-has-changes"
]
Give the defaults, below is an example package_info.py
file.
"""Auto-generated by poetry-plugin-package-info at 2023-06-11T00:38:17."""
import datetime
class PackageInfo:
project_name: str | None = "poetry-plugin-package-info"
project_description: str | None = "Plugin for poetry that creates/updates an package_info.py file with various details about the project/package."
project_version: str | None = "0.2.0"
project_authors: list[str] | None = ["Ben Ellis <ben.ellis@softweyr.co.uk>"]
project_license: str | None = "MIT"
project_classifiers: list[str] | None = [
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: System Administrators",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Version Control :: Git",
"Topic :: Software Development",
"Topic :: System :: Archiving :: Packaging",
"Topic :: System :: Installation/Setup",
"Topic :: System :: Software Distribution",
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
]
project_documentation: str | None = (
"https://github.com/bellis/poetry-plugin-package-info"
)
project_repository: str | None = None
project_homepage: str | None = (
"https://github.com/bellis/poetry-plugin-package-info"
)
project_maintainers: list[str] | None = None
project_keywords: list[str] | None = None
git_commit_id: str | None = "b69755ca54300baaabe5f92bc99b7e101712739b"
git_commit_author_name: str | None = "Ben Ellis"
git_commit_author_email: str | None = "ben.ellis@softweyr.co.uk"
git_commit_timestamp: datetime.datetime | None = datetime.datetime.fromisoformat(
"2023-06-11T00:31:29+01:00"
)
git_branch_name: str | None = "main"
git_branch_path: str | None = "refs/heads/main"
git_is_dirty: bool | None = True
git_is_dirty_excluding_untracked: bool | None = True
git_has_staged_changes: bool | None = False
git_has_unstaged_changes: bool | None = True
git_has_untracked_changes: bool | None = False
How-to
Change variable names
It is possible to override the name of the generated variable by expanding the properties section to
[tool.poetry-plugin-package-info]
properties = [
"project-name",
"project-description",
"git-commit-id",
{ "property-generator" = "git", "property-name" = "is-dirty", "variable_name" = "clean_me" },
{ "property-name" = "git-is-dirty", "variable_name" = "clean_me_too" }
]
Related Projects
- website: The official Poetry website and blog
- poetry-plugin-export: Export Poetry projects/lock files to foreign formats like requirements.txt (Used some test code from this project)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for poetry_plugin_package_info-0.2.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20cc334e40a86d16cf5b316fb7b7aea2bac43a50dd5ac56fbd1ee4918119dee0 |
|
MD5 | b409b4692ae9638ff67feb0d5aac7894 |
|
BLAKE2b-256 | da9ddc345a27ea412114c7146cf63e182b35ec3e954895a453644aaa2424cc69 |
Hashes for poetry_plugin_package_info-0.2.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00b6ddc1c48c2d059feaabce3ec73853045b2bf2a40aa1d1306b9c5be425a279 |
|
MD5 | 1f3930e421f1eed1762c6480a2c035be |
|
BLAKE2b-256 | 949c00cb432a9ec7a4016fa4fd6fba752e2376e5054f9175b2a951cfcbdfa312 |