<short description for the tool>
Project description
How to Build and Distribute a CLI Tool with Python
Requirements
virtualenv
: n isolated python env where we can test our tools/scripts etc while not installing them on our system globally.
pip install virtualenv
wheel
: a packaging mechanism for python tools/packages.
pip install wheel
setuptools
: a library that we will use to package our tool.
pip install --upgrade setuptools
twine
: used for distributing the packages topypi/test.pypi
.
pip install twine
Directory Structure & Initial Setup
MyTool
- app
- __init__.py
- __main__.py
- application.py
- my_tool.py
- setup.py
- requirements.txt
- README.md
- LICENSE
- MANIFEST.in
License
Choose a LICENSE for distributing the package to pick from https://choosealicense.com/.
Required packages
pip install -r requirements.txt
setup.py
-
py_modules
- This is the place where we tell
setuptools
what modules it must be including while packaging the tool. - In our case, we are asking it to include
my_tool.py
and the whole app folder. - That is where the main functionalities of our tool will lie.
- This is the place where we tell
-
packages
- This tells the places setuptools should look for in the current directory to find packages required for the tool.
find_packages()
without any arguments means look through the whole directory to find any packages required.
-
entry_points
- This is where we tell how our tool can be invoked and what function must be called when it is invoked.
- [console_scripts] tells the
setuptools
that this tool will be used as a CLI tool (likepip
ornpm
).
-
cooltool=my_tool:cli
- this tells
setuptools
that whenever somebody typescooltool
in the terminal, call the cli function insidemy_tool.py
. - If we have another function called start, and we want that to be invoked, we would write
my_tool:start
.
- this tells
Testing the Tool
# Create a virtual env
virtualenv <virtual-env-name>
# Activate the created virtual env
source venv/bin/activate
# Install the CLI tool
python setup.py develop
# Verify the installation
which cooltool
Tests
# Tests
% cooltool hello
Hello World
% cooltool hello -n Python
Hello Python
Packaging and Distributing
python setup.py sdist bdist_wheel
Use twine
to upload the binaries to test.pypi.org
.
twine upload --repository testpypi --skip-existing dist/*
Now install it using pip
.
pip install --index-url https://test.pypi.org/simple/ cooltool
Reference
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
convertool-1.0.0.tar.gz
(4.0 kB
view hashes)
Built Distribution
Close
Hashes for convertool-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6346db2e632f546c63fc05d1d03f93b052ba0c76dfbc703522fd735acd8abaaa |
|
MD5 | c9a46a095ebfd357fca801887ea00a7a |
|
BLAKE2b-256 | 6fe8e802ad18896e6e4dd1fbdfd90d7abec01aa08746dd37c3d1f0898e1e6f3e |