-
Notifications
You must be signed in to change notification settings - Fork 10
Build A Package
Meir Gabay edited this page Nov 26, 2020
·
9 revisions
Build a Python package from source code.
- You've gone through Create A Package
- Install setuptools and wheel
$ pip install -U setuptools wheel
- (Optional) Use this project as a template if you haven't previously created a Python project
Once your project is ready to be built, execute the following command.
$ python setup.py sdist bdist_wheel-
sdist: you're creating
setuptoolsartifacts - enable installing from source code -
bdist_wheel: you're creating a
wheelartifact - a single.whlfile which is like a ZIP file of the whole package -
Why sdist?: If the installation from
wheelfails, for any reason, thenpipfalls back and installs from source code (setuptools)
The following directories will be created after the Build step.
- .eggs: Contains eggs that were downloaded by setuptools to build, test, and run plug-ins
-
build: Source files of the package that will be zipped into
.whl; this is a temporary folder, and it can be ignored - {APP_NAME}.egg-info: The package's metadata, such as the path to app source files, required packages, entrypoint (for Python CLI App), etc.
-
dist: Artifacts that can be used by pip to install the Python app. The wheel file name is dependant on the wheel's type. If you didn't specify anything, you'd probably generate this filename
{APP_NAME}-{APP_VERSION}-py3-none-any.whl
The following Bash script will search for *.whl in dist/; there should be only one file. If you're building for a specific operating system, like macOS, Windows, or Linux, then change *.whl to *{SPECIFIC_OS_NAME}*.whl.
The {} represents the name of the *.whl file that was found, and \; means it's the end of an -exec.
$ find dist/ -type f -name *.whl -exec pip install {} \;This step is useful for checking whether the wheel package was built properly before publishing it to PyPi.
- Home
- Python
- Docker
- Intro
- Build A Docker Image
- Multistage Build
- CI/CD
- Intro
- GitHub Actions