<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
setuptoolswhat modules it must be including while packaging the tool. - In our case, we are asking it to include
my_tool.pyand 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
setuptoolsthat this tool will be used as a CLI tool (likepipornpm).
-
cooltool=my_tool:cli- this tells
setuptoolsthat whenever somebody typescooltoolin 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 details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file convertool-1.0.0.tar.gz.
File metadata
- Download URL: convertool-1.0.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
228cd653fc45afaf3902bd14e5024c2b070391fa54c852990d34677e0e663c99
|
|
| MD5 |
75a496859e1f9fa045e6aefd7ae92c68
|
|
| BLAKE2b-256 |
c0c998bb9834a52e3ae1eb9bb784bae185547e15674b01031ba4300969b03b35
|
File details
Details for the file convertool-1.0.0-py3-none-any.whl.
File metadata
- Download URL: convertool-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6346db2e632f546c63fc05d1d03f93b052ba0c76dfbc703522fd735acd8abaaa
|
|
| MD5 |
c9a46a095ebfd357fca801887ea00a7a
|
|
| BLAKE2b-256 |
6fe8e802ad18896e6e4dd1fbdfd90d7abec01aa08746dd37c3d1f0898e1e6f3e
|