Python 项目打包,上传至Artifactory,并下载安装

Python Packing

Python Project结构

python_project/
  package/
    __init__.py
    xx.py
  setup.py
  LICENSE
  README.md

上面是一个Python Project最基本的结构,包含:

  • package folder:
  • __init__.py 和 你真正的Python module文件 xx.py
  • setup.py
  • LICENSE license 文件: 具体想要什么样license,可以去这里找 https://choosealicense.com/
  • README.md 不仅是README,甚至可以放一些配置文件,这些配置文件可以被诸如 setup.py 所引用

__init__.py

将自己的module expose出去的配置文件;比如我自定义了了一个module rex_test,我需要将其expose出去

#__init__.py
from . import rex_test

setup.py

关于如何package的一个configuration文件,例如

import setuptools

setuptools.setup(
    name='rexg',
    version='1.0.0',
    author='Rex',
    author_email='[email protected]',
    description='Rex test Python packaging',
    url='https://rexg.github.io/',
    install_requires=[
        'mlflow==1.0.0',
    ],
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    python_requires='>=3.6',
)

使用到的命令

打包

pip install --upgrade setuptools wheel
python setup.py sdist bdist_wheel

这是项目的 /dist folder下就会生成 *.tar.gz 的打包文件;

上传至Artifactory

pip install --upgrade twine
python -m twine upload -u  -p  -r  --repository-url https://artifactory.xxx dist/*

引用

sudo pip install -i https://artifactory.xxx/simple rexg

你可能感兴趣的:(python)