Building and Distributing Packages with Setuptools

install

$ pip install setuptools wheel twine

repo structure

.
├── LICENSE
├── README.md
├── build
│   ├── bdist.macosx-10.9-x86_64
│   └── lib
├── dist
│   └── mh_test_01-1.0.0-py3.8.egg
├── setup.py
├── src
│   ├── example_package_01
│   └── mh_test_01.egg-info
└── tests

setup.py

import os

from setuptools import find_packages, setup


# 读取文件
def read_file(filename):
    with open(os.path.join(os.path.dirname(__file__), filename), encoding='utf-8') as f:
        long_description = f.read()
    return long_description


setup(
    # 基本信息
    name="mh-test-01",  # project name, global unique name
    version="1.0.0",  # version
    author='allen',  # project develop
    author_email='[email protected]',  # email
    description='this is a test repo',  # description
    long_description=read_file('README.md'),  # detail description for pypi 
    long_description_content_type="text/markdown",  # file format
    platforms='python3',  # platform
    url='https://github.com/allenhaozi/exquisite-mlops-production',  # repo site

    # configuration
    # include src expect tests
    packages=find_packages('src', exclude=['*.tests', '*.tests.*', 'tests.*', 'tests']),
    package_dir={'': 'src'},  # find_packages define code directory
    package_data={
        # include .txt all of them
        '': ['*.txt']
    },
    exclude_package_data={},
    # python version
    python_requires='>=3',
    # pypi
    install_requires=[
        'flask >= 2.0.1',
    ],
    # auto generate executable files
    # Unix /path/to/python/bin 
    entry_points={
        'console_scripts': [
            'print_args = example_package_01.example:print_args',  # entrenched to function
        ],
    }
)

local install

local install

$ python setup.py install

local install with develop

$python setup.py develop

package package

$ python setup.py bdist_wheel

dict

.
├── LICENSE
├── README.md
├── build
│   ├── bdist.macosx-10.9-x86_64
│   └── lib
├── dist # package dir
│   ├── mh_test_01-1.0.0-py3-none-any.whl # project source code
│   └── mh_test_01-1.0.0-py3.8.egg
├── setup.py
├── src
│   ├── example_package_01
│   └── mh_test_01.egg-info
└── tests

8 directories, 5 files

local install

$ pip install dist/mh_test_01-1.0.0-py3-none-any.whl

publish/release

$ python setup.py register
$ python setup.py upload

$ twine upload dist/mh_test_01-1.0.0-py3-none-any.whl

$ pip install mh_test_01

uninstall

# uninstall local package
$ python setup.py develop -u

你可能感兴趣的:(Building and Distributing Packages with Setuptools)