A python library development template that is quick to release and easy to maintain.
- Modify all
example_lib_name
toyour_lib_name
- Edit
hello_world.py
(that's your library main code), and remenber to modify the file name 😊 - Select the library license. Choosealicense website will be helpful.
- Write your own code, documentation and test.
- Modify the description of this library in
setup.py
-
python3 setup.py sdist bdist_wheel
(if you not have setuptools and wheel, runpip3 install setuptools wheel
) -
twine upload dist/*
(if you not have twine, runpip3 install twine
) -
input the your API token in cmd, if you not have a api token
python3 update_version.py; git add -A; git commit -m"update version name"; git push; python3 setup.py sdist bdist_wheel; twine upload dist/*
In the terminal, enter vim .git/hooks/pre-commit
to open the pre-commit hook script. Add the following lines to the file:
#!/bin/bash
# Run the update_version.py script before committing.
python3 update_version.py
# Continue with the commit.
git add -A
Ensure that the script has execute permissions:
chmod +x .git/hooks/pre-commit
This code sets up a Git hook that runs the update_version.py script before each commit. This script updates the version number in your Python package’s setup.py file. The hook also automatically stages the changes to the setup.py file. This ensures that the version number is always up-to-date and that the changes are included in the commit.
This action supports PyPI's trusted publishing implementation, which allows authentication to PyPI without a manually configured API token or username/password combination. To perform trusted publishing with this action, your project's publisher must already be configured on PyPI.
In this example case, add your PYPI_API_TOKEN and RESP_GITHUB_TOKEN in your repository setting: https://github.com/your_github_name/your_lib_name/settings/secrets/actions
- Change the
test_hello_world.py
to test your library functions. - Run
python3 -m unittest discover -s tests
I recommend that you use manual publishing for the first time, and choose action publishing in subsequent releases. Because only after you publish manually can you selectively obtain the token that is only valid for this library, it will be safer to use this token for action.