A setuptools package to add details from git to your project.
APACHE-2.0 License
A setuptools
package to add details from git to your project.
Generates a file containing:
https://
URL to this project,git@
URL to this project,This file can then be used at will, see below examples.
Can be installed & configured through both setup.py
and PEP 518's
pyproject.toml
.
Does not require to change source code of the project.
Compatible with Python 3.8+.
pyproject.toml
[tool.setuptools-git-details]
write_to = "myproject/_git.py"
enabled = true # Optional. Default: true.
setuptools-git-details
generate the git details Python fileThe next time you run setuptools
(e.g., via pip install -e $(pwd)
),
setuptools-git-details
will then generate a file like the following at the
location defined via write_to
(e.g., in this case myproject/_git.py
):
# This file was generated by setuptools-git-details.
# Do NOT change. Do NOT track in version control.
# Generated at: 2024-09-29T05:18:09.101566+00:00
from typing import Dict, Union
git: Dict[str, Union[str, bool]] = {
"name": "myproject",
"revision": "738484d4c18cb04c7f9095c2ec834fea4872f184",
"branch": "main",
"tag": "",
"url": "https://github.com/myorg/myproject",
"git": "[email protected]:myorg/myproject.git",
"is_dirty": False,
}
__git__ = git
try:
from myproject._git import git
except ImportError:
git = {}
print(git.get("revision", "N/A"))
Examples:
--help
or --version
.Install just
and then run the below command:
just setup
just lint
just install
just clean
Add test.pypi.org's API token to ~/.pypirc
.
Update the version in pyproject.toml
.
Create a tag with the same version:
export VERSION="X.Y.Z" # N.B.: no "v" prefix!
git tag -a "${VERSION}" -m "${VERSION}"
git push origin tag "${VERSION}"
Run:
just test-release
Test the release:
python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps setuptools-git-details
N.B.: in case of release failure, and a re-release, the tag can be deleted this way (warning: bad practice to delete tags):
git tag -d "${VERSION}"
git push origin --delete "${VERSION}"
Add pypi.org's API token to ~/.pypirc
.
Run:
just release
Test the release:
python3 -m pip install setuptools-git-details