Wednesday, May 1, 2024
HomePythonPackaging your python scripts. - Yasoob Khalid

Packaging your python scripts. – Yasoob Khalid


Oh hello there! Welcome to a different helpful put up. This put up goes to be about tips on how to package deal your python scripts and packages for distribution on PyPI or another place. Right here I received’t go too deep into explaining the whole lot as most of us simply have to know the fundamentals of packaging. Nevertheless i’ll offer you totally different hyperlinks for additional examine.

Okay lets speak about setuptools first. What’s it? It’s a Python module which permits us to simply package deal our python scripts and modules for distribution. Nevertheless there are different packaging libraries as properly however right here i’ll speak about setuptools solely.

So what must be the essential instance to indicate the utilization of setuptools? Right here you go. For primary use of setuptools, simply import issues from setuptools after which look under for the minimal setup script utilizing setuptools.

from setuptools import setup, find_packages
setup(
    identify = "HelloWorld",
    model = "0.1",
    packages = find_packages(),
)

As you see we don’t must specify a lot in an effort to use setuptools in a venture. Simply by doing the above, this venture will be capable of produce eggs, add to PyPI, and routinely embody all packages within the listing the place the setup.py lives. However if you find yourself releasing your initiatives on PyPI then you need to add a bit extra details about your self and this package deal and in case your venture depends on some exterior dependencies then record them there as properly. Right here is one other script which might do all that:

from setuptools import setup, find_packages
setup(
    identify = "HelloWorld",
    model = "0.1",
    packages = find_packages(),
    scripts = ['say_hello.py'],

    # Undertaking makes use of reStructuredText, so be sure that the 
    # docutils get put in or upgraded on the goal 
    # machine
    install_requires = ['docutils>=0.3'],

    package_data = {
        # If any package deal accommodates *.txt or *.rst recordsdata,
        # embody them:
        '': ['*.txt', '*.rst'],
        # And embody any *.msg recordsdata discovered within the 
        # 'hey' package deal, too:
        'hey': ['*.msg'],
    },

    # metadata for add to PyPI
    creator = "Me",
    author_email = "me@instance.com",
    description = "That is an Instance Package deal",
    license = "PSF",
    key phrases = "hey world instance examples",
    # venture house web page, if any :
    url = "http://instance.com/HelloWorld/",   

    # may additionally embody long_description, download_url,
    # classifiers, and so forth.
)

I hope that is sufficient for now. Nevertheless listed below are another packaging libraries in case you had been questioning :

  1. Distutils is the usual instrument used for packaging. It really works quite properly for easy wants, however is restricted and never trivial to increase.
  2. Setuptools is a venture born from the need to fill lacking distutils performance and discover new instructions. In some sub-communities, it’s a de facto commonplace. It makes use of monkey-patching and magic that’s frowned upon by Python core builders.
  3. Distribute is a fork of Setuptools that was began by builders feeling that its growth tempo was too gradual and that it was not doable to evolve it. Its growth was significantly slowed when distutils2 was began by the identical group.
  4. Distutils2 is a brand new distutils library, began as a fork of the distutils codebase, with good concepts taken from setup instruments (of which some had been completely mentioned in PEPs), and a primary installer impressed by pip. Distutils2 didn’t make the Python 3.3 launch, and it was placed on maintain.

Supply: Stackoverflow

For additional examine i like to recommend: http://pythonhosted.org/distribute/setuptools.html

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments