Packaging Python Projects
|
|
The project structure
|
|
Creating pyproject.toml
|
|
Generating distribution archives
|
|
Now run this command from the same directory where pyproject.toml is located:
|
|
This command should output a lot of text and once completed should generate two files in the dist directory:
|
|
The tar.gz file is a source distribution whereas the .whl file is a built distribution.
Uploading the distribution archives
-
register an account on TestPyPI.
-
Create a PyPI API token at https://test.pypi.org/manage/account/#api-tokens
-
setting the “Scope” of a PyPI API token to “Entire account”.
-
install Twine:
1python -m pip install --upgrade twine -
upload the archives
1python -m twine upload --repository testpypi dist/*You will be prompted for a username and password. For the username, use
__token__. For the password, use the token value, including thepypi-prefix. -
verify package on TestPyPI
1https://test.pypi.org/project/edx-helper
Installing your newly uploaded package
-
You can use pip to install your package and verify that it works. Create a virtual environment and install your package from TestPyPI:
1python -m pip install --index-url https://test.pypi.org/simple/ --no-deps edx-helper -
You can test that it was installed correctly by importing the package. Make sure you’re still in your virtual environment, then run Python:
1python31 2from edx_helper import edx_dl edx_dl.main()
Real step
- Register an account on https://pypi.org
- Use
twine upload dist/*to upload your package and enter your credentials for the account you registered on the real PyPI. Now that you’re uploading the package in production, you don’t need to specify--repository; the package will upload to https://pypi.org/ by default. - Install your package from the real PyPI using
python3 -m pip install [your-package].
TODO
rewrite README.md