构建
创建源码分发包:
python setup.py sdist
目录中生成以下内容:
dist
└── lr_grepy-0.1.0.tar.gz
对于 wheel 分发包:
python setup.py bdist_wheel
它将生成一个 .whl
文件:
dist
├── lr_grepy-0.1.0-py3-none-any.whl
└── lr_grepy-0.1.0.tar.gz
最后,你可以使用类似 twine
的工具将包上传到 PyPI:
pip install twine
twine upload dist/<file_name>
此刻,你可能有太多命令(运行、测试、本地安装、构建等)要记。可以选择添加一个 Makefile 来帮助构建。
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
然后,你可以轻松地执行这些操作:
make run
make test
make build
make publish