A setuptools package to add details from git to your project.
Project description
setuptools-git-details
A setuptools
package to add details from git to your project.
Features
-
Generates a file containing:
- the name of the project,
- the current revision,
- the current branch,
- the current tag, if any,
- the
https://
URL to this project, - the
git@
URL to this project, - whether the current revision/branch/tag is "dirty".
This file can then be used at will, see below examples.
-
Can be installed & configured through both
setup.py
and PEP 518'spyproject.toml
. -
Does not require to change source code of the project.
-
Compatible with Python 3.8+.
Usage
1. Configure pyproject.toml
[tool.setuptools-git-details]
write_to = "myproject/_git.py"
enabled = true # Optional. Default: true.
2. Let setuptools-git-details
generate the git details Python file
The 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": "git@github.com:myorg/myproject.git",
"is_dirty": False,
}
__git__ = git
3. Use the generated file in your Python code
try:
from myproject._git import git
except ImportError:
git = {}
print(git.get("revision", "N/A"))
Examples:
- In a CLI, print these details as part of
--help
or--version
. - In an ETL, use these details as metadata for your data lineage.
- etc.
Development
Setup
Install just
and then run the below command:
just setup
Lint
just lint
Install
just install
Clean
just clean
Release
Test-release to test.pypi.org
-
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}"
Release to pypi.org
-
Add pypi.org's API token to
~/.pypirc
. -
Run:
just release
-
Test the release:
python3 -m pip install setuptools-git-details
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
File details
Details for the file setuptools_git_details-1.0.0.tar.gz
.
File metadata
- Download URL: setuptools_git_details-1.0.0.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 946a293345723a5e6341af7f496ffca1ff6d230ccb216c4269dd879f9b4ea325 |
|
MD5 | 3e0f1b3bb8d7e13b769cb0926f4d53d1 |
|
BLAKE2b-256 | 6cee05fb27ea9e2efb6344de3b1cbf334e91fe915d266722ff4ffbb80dfa02c4 |
File details
Details for the file setuptools_git_details-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: setuptools_git_details-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a57e9c1dbbb483bfb8b5dc231255f28e1c938a32753b05daec1fd7b04c33685 |
|
MD5 | 01d48a0925a382dbdb57a3faa339a800 |
|
BLAKE2b-256 | 55e3b6eaacb883dc6be0cb91ffd4c004694d34a2737b128236c46f0ba2ee0dcc |