Search code examples
pythonwindowseggpython-wheel

Build a wheel/egg and all dependencies for a python project


In order to stage python project within our corporation I need to make an installable distribution.

This should include:

  • An egg or whl for my project
  • An egg or whl for every dependency of the project
  • (optionally) produce a requirements.txt file listing all the installable components for this release

Is there an easy plug in, (e.g. an alternative to bdist_wheel) that will not only compile one wheel but also that project's components?

Obviously I can script this, but I was hoping that there might be a short-cut that builds the package + dependencies in fewer steps.

This needs to work on Python 2.7 on Windows + Linux.


Solution

  • With poetry you can define your dependencies and metadata about your project in a file in the root of your project, called pyproject.toml:

    [tool.poetry]
    name = "my-project"
    version = "0.1.0"
    description = "some longer description"
    authors = ["Some Author <[email protected]>"]
    
    [tool.poetry.dependencies]
    python = "*"
    
    [tool.poetry.dev-dependencies]
    pytest = "^3.4"
    

    To build your project as a wheel, execute poetry build

    $ poetry build
    
    Building my-project (0.1.0)
    - Building sdist
    - Built my-project-0.1.0.tar.gz
    
    - Building wheel
    - Built my-project-0.1.0-py3-none-any.whl
    

    a dist/ folder is created with a wheel for your project.