» Make grep CLI App in Python » 3. Publish » 3.1 Build

Build

To create a source distribution package, use:

python setup.py sdist

It produces this in your project directory:

dist
└── lr_grepy-0.1.0.tar.gz

And for a wheel distribution package:

python setup.py bdist_wheel

It produces a .whl file:

dist
├── lr_grepy-0.1.0-py3-none-any.whl
└── lr_grepy-0.1.0.tar.gz

Finally, you can upload your package to PyPI using a tool like twine:

pip install twine
twine upload dist/<file_name>

At this point, you may have too many commands (run, test, local install, build, and etc) to remember. Add a Makefile to make it easier.

Makefile:

.PHONY: run test build publish clean

run:
	python3 -m grepy.cli -rn result .

test:
	python3 -m unittest tests/*py

install:
	pip3 install .

build:
	python3 setup.py sdist bdist_wheel

publish: build
	twine upload dist/*

clean:
	rm -rf dist build lr_grepy.egg-info

Then you can easily do these operations:

make run
make test
make build
make publish