• Python Packaging & Distribution


    distuils & setuptools

    distuils is the standard packaging tool of Python, and setuptools is its improvement.

    Example: distuils

    1. setup.py
    from distutils.core import setup
    
    setup(
        name = 'hello',
        version = '1.0',
        packages = ['hello'],
    )
    
    1. shell command
    python setup.py sdist
    # got a tar.gz file in dist dictionary
    

    Example: setuptools

    1. setup.py
    from setuptools import setup
    setup(     
        name='mypackage',
        author='Giorgos Myrianthous',     
        version='0.1',     
        install_requires=[         
            'pandas',         
            'numpy',
            'matplotlib',
        ],
        # ... more options/metadata
    )
    
    1. setup.cfg
      1. just copy parameters to cfg file
    [metadata]
    name = mypackage
    author = Giorgos Myrianthous
    version = 0.1
    [options]
    install_requires =
        pandas
        numpy
        matplotlib
    
    1. shell command
    python setup.py bdist_egg
    # got a egg file in dist dictionary
    

    PyPI & egg, PIP & easy_install

    PyPI · The Python Package Index

    Once you upload your egg file onto PyPI, you can download and install your module throught easy_install(deprecated) or pip


    requirements.txt

    The requirements.txt is a file listing all the dependencies for a specific Python project.

    Example: requirements.txt

    1. requirements.txt
    matplotlib>=2.2
    numpy>=1.15.0, <1.21.0
    pandas
    pytest==4.0.1
    
    1. shell command
    pip install -r requirements.txt
    

    Do we need both requirements.txt and setup.py/setup.cfg files?

    • If your package is mostly for development purposes but you aren’t planning on redistributing it, requirements.txt should be enough (even when the package is developed on multiple machines).
    • If your package is developed only by yourself (i.e. on a single machine) but you are planning to redistribute it, then setup.py/setup.cfg should be enough.
    • If you package is developed on multiple machines and you also need to redistribute it, you will need both the requirements.txt and setup.py/setup.cfg files.

    In case you are using both, your setup.py (and/or setup.cfg) files should include the list of abstract dependencies, whereas the requirements.txt file must contain the concrete dependencies with the specific pins for each package version (using == pin).


    pyproject.toml

    The goal of this file is to allow you to define what build tools are needed in order to build your package – no longer assuming it must be Setuptools. And it can be Poetry or Filt.

    /path/to/example/project/
    ├── src/                            Source dir.
    │   └── example/                    Python package directory.
    │       ├── __init__.py             This makes the directory a package.
    │       └── example_module.py       Example module.
    ├── pyproject.toml                  Definition of build process of the package.
    ├── README.md                       README with info of the project.
    └── setup.cfg                       Configuration details of the python package.
    

    Tools are standardizing on pyproject.toml, so now projects like Black, coverage.py, towncrier, and tox (in a way) allow you to specify their configurations in pyproject.toml instead of in a separate file.

  • 相关阅读:
    CDN加速器有哪些?
    C++实现的动态规划求解分解为若干素数之和的方案总数
    2023年9月 少儿编程 中国电子学会图形化编程等级考试Scratch编程一级真题解析(选择题)
    【人工智能】强化学习笔记(持续更新)
    ubuntu 23.04安装中文输入法
    计算机网络_2.2物理层下面的传输媒体
    客户分析:必须要找出这5种客户?(BP分析)
    C++:红黑树
    MapGIS 10.6 Pro新品发布!加速地理信息领域核心技术国产替代
    【RocketMQ系列六】RocketMQ事务消息
  • 原文地址:https://blog.csdn.net/qq_39384184/article/details/127042852