setup.py examples?

后端 未结 8 1758
庸人自扰
庸人自扰 2020-12-12 11:06

After studying this page:

http://docs.python.org/distutils/builtdist.html

I am hoping to find some setup.py files to study so as to make my own (with the goa

8条回答
  •  有刺的猬
    2020-12-12 11:28

    READ THIS FIRST https://packaging.python.org/en/latest/current.html

    Installation Tool Recommendations

    1. Use pip to install Python packages from PyPI.
    2. Use virtualenv, or pyvenv to isolate application specific dependencies from a shared Python installation.
    3. Use pip wheel to create a cache of wheel distributions, for the purpose of > speeding up subsequent installations.
    4. If you’re looking for management of fully integrated cross-platform software stacks, consider buildout (primarily focused on the web development community) or Hashdist, or conda (both primarily focused on the scientific community).

    Packaging Tool Recommendations

    1. Use setuptools to define projects and create Source Distributions.
    2. Use the bdist_wheel setuptools extension available from the wheel project to create wheels. This is especially beneficial, if your project contains binary extensions.
    3. Use twine for uploading distributions to PyPI.

    This anwser has aged, and indeed there is a rescue plan for python packaging world called

    wheels way

    I qoute pythonwheels.com here:

    What are wheels?

    Wheels are the new standard of python distribution and are intended to replace eggs. Support is offered in pip >= 1.4 and setuptools >= 0.8.

    Advantages of wheels

    1. Faster installation for pure python and native C extension packages.
    2. Avoids arbitrary code execution for installation. (Avoids setup.py)
    3. Installation of a C extension does not require a compiler on Windows or OS X.
    4. Allows better caching for testing and continuous integration.
    5. Creates .pyc files as part of installation to ensure they match the python interpreter used.
    6. More consistent installs across platforms and machines.

    The full story of correct python packaging (and about wheels) is covered at packaging.python.org


    conda way

    For scientific computing (this is also recommended on packaging.python.org, see above) I would consider using CONDA packaging which can be seen as a 3rd party service build on top of PyPI and pip tools. It also works great on setting up your own version of binstar so I would imagine it can do the trick for sophisticated custom enterprise package management.

    Conda can be installed into a user folder (no super user permisssions) and works like magic with

    conda install

    and powerful virtual env expansion.


    eggs way

    This option was related to python-distribute.org and is largerly outdated (as well as the site) so let me point you to one of the ready to use yet compact setup.py examples I like:

    • A very practical example/implementation of mixing scripts and single python files into setup.py is giving here
    • Even better one from hyperopt

    This quote was taken from the guide on the state of setup.py and still applies:

    • setup.py gone!
    • distutils gone!
    • distribute gone!
    • pip and virtualenv here to stay!
    • eggs ... gone!

    I add one more point (from me)

    • wheels!

    I would recommend to get some understanding of packaging-ecosystem (from the guide pointed by gotgenes) before attempting mindless copy-pasting.

    Most of examples out there in the Internet start with

    from distutils.core import setup
    

    but this for example does not support building an egg python setup.py bdist_egg (as well as some other old features), which were available in

    from setuptools import setup
    

    And the reason is that they are deprecated.

    Now according to the guide

    Warning

    Please use the Distribute package rather than the Setuptools package because there are problems in this package that can and will not be fixed.

    deprecated setuptools are to be replaced by distutils2, which "will be part of the standard library in Python 3.3". I must say I liked setuptools and eggs and have not yet been completely convinced by convenience of distutils2. It requires

    pip install Distutils2
    

    and to install

    python -m distutils2.run install
    

    PS

    Packaging never was trivial (one learns this by trying to develop a new one), so I assume a lot of things have gone for reason. I just hope this time it will be is done correctly.

提交回复
热议问题