Pythonで書かれたpythonパッケージをパッケージ化

22216 ワード

これは完全にpypiから回転しています.リンクを参照してください.https://packaging.python.org/tutorials/packaging-projects/
パッケージ内ファイルの作成
/example_pkg
  /example_pkg
    __init__.py
  setup.py
  LICENSE
  README.md

setupを作成します.py
import setuptools

with open("README.md", "r") as fh:
    long_description = fh.read()

setuptools.setup(
    name="example_pkg",
    version="0.0.1",
    author="Example Author",
    author_email="[email protected]",
    description="A small example package",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/pypa/sampleproject",
    packages=setuptools.find_packages(),
    classifiers=(
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ),
)

READMEを作成する.md
# Example Package

This is a simple example package. You can use
[Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/)
to write your content.

LICENSEの作成
このサイトからLICENSEを見つけることができます.https://choosealicense.com/
インストールツールのインストール
python3 -m pip install --user --upgrade setuptools wheel

コンパイル生成パッケージ
python3 setup.py sdist bdist_wheel

twineのインストール
python3 -m pip install --user --upgrade twine

twineでアップロード
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

——————————私は華麗な分割線です————————————
次に、パッケージ用のスクリプトを示します.
#!/usr/bin/python
# coding:utf-8
__Author__ = 'Adair.l'
import os
import shutil
# get next version
version='0.0.1'
for line in open('setup.py'):
    if 'version' in line:
        version='.'.join(line.split('=')[1].strip().split('.')[:-1]+[str(int(line.split('=')[1].strip().strip(',').strip("'").split('.')[-1])+1)])
        version=version[1:]
# change to next version
content=[(line if not 'version' in line else line.split('=')[0]+' = \''+ version+"',
") for line in open('setup.py').readlines()] open('setup.py','w').writelines(content) # distribute os.system('python3 setup.py sdist bdist_wheel') try: shutil.rmtree("dist_compiled") os.remove('dist_compiled') os.mkdir('dist_compiled') except: pass # move files generated shutil.move("dist",'dist_compiled') shutil.move("build",'dist_compiled') shutil.move("labinstrument.egg-info",'dist_compiled') # os.system('pip3 uninstall labinstrument') os.system('pip3 install dist_compiled/labinstrument-{}-py3-none-any.whl'.format(version))

上記のコードの実行結果は、イテレーションが自動的に更新され、自動的にインストールされるたびに、ほぼ同じです.
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 "/Users/adair/GitHub/instruments/Source Code/Python/dist.py"
running sdist
running egg_info
creating labinstrument.egg-info
writing labinstrument.egg-info/PKG-INFO
getting
writing dependency_links to labinstrument.egg-info/dependency_links.txt
writing top-level names to labinstrument.egg-info/top_level.txt
writing manifest file 'labinstrument.egg-info/SOURCES.txt'
reading manifest file 'labinstrument.egg-info/SOURCES.txt'
writing manifest file 'labinstrument.egg-info/SOURCES.txt'
running check
creating labinstrument-0.0.6
creating labinstrument-0.0.6/labinstrument
creating labinstrument-0.0.6/labinstrument.egg-info
creating labinstrument-0.0.6/labinstrument/Audio
creating labinstrument-0.0.6/labinstrument/NA
creating labinstrument-0.0.6/labinstrument/PS
creating labinstrument-0.0.6/labinstrument/SA
creating labinstrument-0.0.6/labinstrument/SG
creating labinstrument-0.0.6/labinstrument/SS
creating labinstrument-0.0.6/labinstrument/SS/CMW500
creating labinstrument-0.0.6/labinstrument/SS/CMW500/CMW500_WIFI
creating labinstrument-0.0.6/labinstrument/SS/E5515C
creating labinstrument-0.0.6/labinstrument/UI
creating labinstrument-0.0.6/labinstrument/calculation
creating labinstrument-0.0.6/labinstrument/interfaces
creating labinstrument-0.0.6/labinstrument/release
creating labinstrument-0.0.6/labinstrument/switch
creating labinstrument-0.0.6/labinstrument/tools
creating labinstrument-0.0.6/labinstrument/turntable
creating labinstrument-0.0.6/labinstrument/turntable/ETS2090
copying files to labinstrument-0.0.6...
copying README.md -> labinstrument-0.0.6
copying setup.py -> labinstrument-0.0.6
copying labinstrument/Interface.py -> labinstrument-0.0.6/labinstrument
copying labinstrument/__init__.py -> labinstrument-0.0.6/labinstrument
copying labinstrument/remote.py -> labinstrument-0.0.6/labinstrument
copying labinstrument.egg-info/PKG-INFO -> labinstrument-0.0.6/labinstrument.egg-info
copying labinstrument.egg-info/SOURCES.txt -> labinstrument-0.0.6/labinstrument.egg-info
copying labinstrument.egg-info/dependency_links.txt -> labinstrument-0.0.6/labinstrument.egg-info
copying labinstrument.egg-info/top_level.txt -> labinstrument-0.0.6/labinstrument.egg-info
copying labinstrument/Audio/__init__.py -> labinstrument-0.0.6/labinstrument/Audio
copying labinstrument/NA/__init__.py -> labinstrument-0.0.6/labinstrument/NA
copying labinstrument/PS/__init__.py -> labinstrument-0.0.6/labinstrument/PS
copying labinstrument/SA/__init__.py -> labinstrument-0.0.6/labinstrument/SA
copying labinstrument/SG/__init__.py -> labinstrument-0.0.6/labinstrument/SG
copying labinstrument/SS/__init__.py -> labinstrument-0.0.6/labinstrument/SS
copying labinstrument/SS/CMW500/CMW500Base.py -> labinstrument-0.0.6/labinstrument/SS/CMW500
copying labinstrument/SS/CMW500/__init__.py -> labinstrument-0.0.6/labinstrument/SS/CMW500
copying labinstrument/SS/CMW500/CMW500_WIFI/CMW500_WIFI.py -> labinstrument-0.0.6/labinstrument/SS/CMW500/CMW500_WIFI
copying labinstrument/SS/CMW500/CMW500_WIFI/Unit_test_CMW500_WIFI.py -> labinstrument-0.0.6/labinstrument/SS/CMW500/CMW500_WIFI
copying labinstrument/SS/CMW500/CMW500_WIFI/__init__.py -> labinstrument-0.0.6/labinstrument/SS/CMW500/CMW500_WIFI
copying labinstrument/SS/E5515C/__init__.py -> labinstrument-0.0.6/labinstrument/SS/E5515C
copying labinstrument/UI/__init__.py -> labinstrument-0.0.6/labinstrument/UI
copying labinstrument/calculation/__init__.py -> labinstrument-0.0.6/labinstrument/calculation
copying labinstrument/interfaces/__init__.py -> labinstrument-0.0.6/labinstrument/interfaces
copying labinstrument/interfaces/basic_interface.py -> labinstrument-0.0.6/labinstrument/interfaces
copying labinstrument/interfaces/na_interface.py -> labinstrument-0.0.6/labinstrument/interfaces
copying labinstrument/interfaces/ota_interface.py -> labinstrument-0.0.6/labinstrument/interfaces
copying labinstrument/interfaces/ps_interface.py -> labinstrument-0.0.6/labinstrument/interfaces
copying labinstrument/interfaces/sg_interface.py -> labinstrument-0.0.6/labinstrument/interfaces
copying labinstrument/interfaces/ss_interface.py -> labinstrument-0.0.6/labinstrument/interfaces
copying labinstrument/interfaces/switch_interface.py -> labinstrument-0.0.6/labinstrument/interfaces
copying labinstrument/interfaces/turntable_interface.py -> labinstrument-0.0.6/labinstrument/interfaces
copying labinstrument/release/FreqTool.py -> labinstrument-0.0.6/labinstrument/release
copying labinstrument/release/__init__.py -> labinstrument-0.0.6/labinstrument/release
copying labinstrument/switch/__init__.py -> labinstrument-0.0.6/labinstrument/switch
copying labinstrument/tools/__init__.py -> labinstrument-0.0.6/labinstrument/tools
copying labinstrument/tools/buildin_ex.py -> labinstrument-0.0.6/labinstrument/tools
copying labinstrument/tools/builtin_ex.py -> labinstrument-0.0.6/labinstrument/tools
copying labinstrument/tools/cardSecurity.py -> labinstrument-0.0.6/labinstrument/tools
copying labinstrument/tools/freqTool.py -> labinstrument-0.0.6/labinstrument/tools
copying labinstrument/tools/power_tool.py -> labinstrument-0.0.6/labinstrument/tools
copying labinstrument/tools/processing_control.py -> labinstrument-0.0.6/labinstrument/tools
copying labinstrument/turntable/__init__.py -> labinstrument-0.0.6/labinstrument/turntable
copying labinstrument/turntable/ETS2090/ETS2090.py -> labinstrument-0.0.6/labinstrument/turntable/ETS2090
copying labinstrument/turntable/ETS2090/__init__.py -> labinstrument-0.0.6/labinstrument/turntable/ETS2090
getting
Writing labinstrument-0.0.6/setup.cfg
creating dist
Creating tar archive
removing 'labinstrument-0.0.6' (and everything under it)
running bdist_wheel
running build
running build_py
creating build
creating build/lib
creating build/lib/labinstrument
copying labinstrument/remote.py -> build/lib/labinstrument
copying labinstrument/Interface.py -> build/lib/labinstrument
copying labinstrument/__init__.py -> build/lib/labinstrument
creating build/lib/labinstrument/UI
copying labinstrument/UI/__init__.py -> build/lib/labinstrument/UI
creating build/lib/labinstrument/tools
copying labinstrument/tools/power_tool.py -> build/lib/labinstrument/tools
copying labinstrument/tools/cardSecurity.py -> build/lib/labinstrument/tools
copying labinstrument/tools/builtin_ex.py -> build/lib/labinstrument/tools
copying labinstrument/tools/freqTool.py -> build/lib/labinstrument/tools
copying labinstrument/tools/__init__.py -> build/lib/labinstrument/tools
copying labinstrument/tools/processing_control.py -> build/lib/labinstrument/tools
copying labinstrument/tools/buildin_ex.py -> build/lib/labinstrument/tools
creating build/lib/labinstrument/NA
copying labinstrument/NA/__init__.py -> build/lib/labinstrument/NA
creating build/lib/labinstrument/release
copying labinstrument/release/FreqTool.py -> build/lib/labinstrument/release
copying labinstrument/release/__init__.py -> build/lib/labinstrument/release
creating build/lib/labinstrument/SS
copying labinstrument/SS/__init__.py -> build/lib/labinstrument/SS
creating build/lib/labinstrument/SA
copying labinstrument/SA/__init__.py -> build/lib/labinstrument/SA
creating build/lib/labinstrument/calculation
copying labinstrument/calculation/__init__.py -> build/lib/labinstrument/calculation
creating build/lib/labinstrument/PS
copying labinstrument/PS/__init__.py -> build/lib/labinstrument/PS
creating build/lib/labinstrument/Audio
copying labinstrument/Audio/__init__.py -> build/lib/labinstrument/Audio
creating build/lib/labinstrument/SG
copying labinstrument/SG/__init__.py -> build/lib/labinstrument/SG
creating build/lib/labinstrument/switch
copying labinstrument/switch/__init__.py -> build/lib/labinstrument/switch
creating build/lib/labinstrument/turntable
copying labinstrument/turntable/__init__.py -> build/lib/labinstrument/turntable
creating build/lib/labinstrument/interfaces
copying labinstrument/interfaces/na_interface.py -> build/lib/labinstrument/interfaces
copying labinstrument/interfaces/basic_interface.py -> build/lib/labinstrument/interfaces
copying labinstrument/interfaces/switch_interface.py -> build/lib/labinstrument/interfaces
copying labinstrument/interfaces/__init__.py -> build/lib/labinstrument/interfaces
copying labinstrument/interfaces/sg_interface.py -> build/lib/labinstrument/interfaces
copying labinstrument/interfaces/ota_interface.py -> build/lib/labinstrument/interfaces
copying labinstrument/interfaces/ss_interface.py -> build/lib/labinstrument/interfaces
copying labinstrument/interfaces/ps_interface.py -> build/lib/labinstrument/interfaces
copying labinstrument/interfaces/turntable_interface.py -> build/lib/labinstrument/interfaces
creating build/lib/labinstrument/SS/CMW500
copying labinstrument/SS/CMW500/__init__.py -> build/lib/labinstrument/SS/CMW500
copying labinstrument/SS/CMW500/CMW500Base.py -> build/lib/labinstrument/SS/CMW500
creating build/lib/labinstrument/SS/E5515C
copying labinstrument/SS/E5515C/__init__.py -> build/lib/labinstrument/SS/E5515C
creating build/lib/labinstrument/SS/CMW500/CMW500_WIFI
copying labinstrument/SS/CMW500/CMW500_WIFI/CMW500_WIFI.py -> build/lib/labinstrument/SS/CMW500/CMW500_WIFI
copying labinstrument/SS/CMW500/CMW500_WIFI/__init__.py -> build/lib/labinstrument/SS/CMW500/CMW500_WIFI
copying labinstrument/SS/CMW500/CMW500_WIFI/Unit_test_CMW500_WIFI.py -> build/lib/labinstrument/SS/CMW500/CMW500_WIFI
creating build/lib/labinstrument/turntable/ETS2090
copying labinstrument/turntable/ETS2090/ETS2090.py -> build/lib/labinstrument/turntable/ETS2090
copying labinstrument/turntable/ETS2090/__init__.py -> build/lib/labinstrument/turntable/ETS2090
installing to build/bdist.macosx-10.6-intel/wheel
running install
running install_lib
creating build/bdist.macosx-10.6-intel
creating build/bdist.macosx-10.6-intel/wheel
creating build/bdist.macosx-10.6-intel/wheel/labinstrument
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/UI
copying build/lib/labinstrument/UI/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/UI
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/tools
copying build/lib/labinstrument/tools/power_tool.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/tools
copying build/lib/labinstrument/tools/cardSecurity.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/tools
copying build/lib/labinstrument/tools/builtin_ex.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/tools
copying build/lib/labinstrument/tools/freqTool.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/tools
copying build/lib/labinstrument/tools/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/tools
copying build/lib/labinstrument/tools/processing_control.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/tools
copying build/lib/labinstrument/tools/buildin_ex.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/tools
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/NA
copying build/lib/labinstrument/NA/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/NA
copying build/lib/labinstrument/remote.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument
copying build/lib/labinstrument/Interface.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument
copying build/lib/labinstrument/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/release
copying build/lib/labinstrument/release/FreqTool.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/release
copying build/lib/labinstrument/release/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/release
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/SS
copying build/lib/labinstrument/SS/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/SS
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/SS/CMW500
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/SS/CMW500/CMW500_WIFI
copying build/lib/labinstrument/SS/CMW500/CMW500_WIFI/CMW500_WIFI.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/SS/CMW500/CMW500_WIFI
copying build/lib/labinstrument/SS/CMW500/CMW500_WIFI/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/SS/CMW500/CMW500_WIFI
copying build/lib/labinstrument/SS/CMW500/CMW500_WIFI/Unit_test_CMW500_WIFI.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/SS/CMW500/CMW500_WIFI
copying build/lib/labinstrument/SS/CMW500/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/SS/CMW500
copying build/lib/labinstrument/SS/CMW500/CMW500Base.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/SS/CMW500
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/SS/E5515C
copying build/lib/labinstrument/SS/E5515C/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/SS/E5515C
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/SA
copying build/lib/labinstrument/SA/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/SA
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/calculation
copying build/lib/labinstrument/calculation/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/calculation
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/PS
copying build/lib/labinstrument/PS/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/PS
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/Audio
copying build/lib/labinstrument/Audio/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/Audio
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/SG
copying build/lib/labinstrument/SG/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/SG
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/switch
copying build/lib/labinstrument/switch/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/switch
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/turntable
copying build/lib/labinstrument/turntable/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/turntable
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/turntable/ETS2090
copying build/lib/labinstrument/turntable/ETS2090/ETS2090.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/turntable/ETS2090
copying build/lib/labinstrument/turntable/ETS2090/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/turntable/ETS2090
creating build/bdist.macosx-10.6-intel/wheel/labinstrument/interfaces
copying build/lib/labinstrument/interfaces/na_interface.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/interfaces
copying build/lib/labinstrument/interfaces/basic_interface.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/interfaces
copying build/lib/labinstrument/interfaces/switch_interface.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/interfaces
copying build/lib/labinstrument/interfaces/__init__.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/interfaces
copying build/lib/labinstrument/interfaces/sg_interface.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/interfaces
copying build/lib/labinstrument/interfaces/ota_interface.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/interfaces
copying build/lib/labinstrument/interfaces/ss_interface.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/interfaces
copying build/lib/labinstrument/interfaces/ps_interface.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/interfaces
copying build/lib/labinstrument/interfaces/turntable_interface.py -> build/bdist.macosx-10.6-intel/wheel/labinstrument/interfaces
running install_egg_info
Copying labinstrument.egg-info to build/bdist.macosx-10.6-intel/wheel/labinstrument-0.0.6-py3.6.egg-info
running install_scripts
creating build/bdist.macosx-10.6-intel/wheel/labinstrument-0.0.6.dist-info/WHEEL
creating '/Users/adair/GitHub/instruments/Source Code/Python/dist/labinstrument-0.0.6-py3-none-any.whl' and adding '.' to it
adding 'labinstrument/Interface.py'
adding 'labinstrument/__init__.py'
adding 'labinstrument/remote.py'
adding 'labinstrument/Audio/__init__.py'
adding 'labinstrument/NA/__init__.py'
adding 'labinstrument/PS/__init__.py'
adding 'labinstrument/SA/__init__.py'
adding 'labinstrument/SG/__init__.py'
adding 'labinstrument/SS/__init__.py'
adding 'labinstrument/SS/CMW500/CMW500Base.py'
adding 'labinstrument/SS/CMW500/__init__.py'
adding 'labinstrument/SS/CMW500/CMW500_WIFI/CMW500_WIFI.py'
adding 'labinstrument/SS/CMW500/CMW500_WIFI/Unit_test_CMW500_WIFI.py'
adding 'labinstrument/SS/CMW500/CMW500_WIFI/__init__.py'
adding 'labinstrument/SS/E5515C/__init__.py'
adding 'labinstrument/UI/__init__.py'
adding 'labinstrument/calculation/__init__.py'
adding 'labinstrument/interfaces/__init__.py'
adding 'labinstrument/interfaces/basic_interface.py'
adding 'labinstrument/interfaces/na_interface.py'
adding 'labinstrument/interfaces/ota_interface.py'
adding 'labinstrument/interfaces/ps_interface.py'
adding 'labinstrument/interfaces/sg_interface.py'
adding 'labinstrument/interfaces/ss_interface.py'
adding 'labinstrument/interfaces/switch_interface.py'
adding 'labinstrument/interfaces/turntable_interface.py'
adding 'labinstrument/release/FreqTool.py'
adding 'labinstrument/release/__init__.py'
adding 'labinstrument/switch/__init__.py'
adding 'labinstrument/tools/__init__.py'
adding 'labinstrument/tools/buildin_ex.py'
adding 'labinstrument/tools/builtin_ex.py'
adding 'labinstrument/tools/cardSecurity.py'
adding 'labinstrument/tools/freqTool.py'
adding 'labinstrument/tools/power_tool.py'
adding 'labinstrument/tools/processing_control.py'
adding 'labinstrument/turntable/__init__.py'
adding 'labinstrument/turntable/ETS2090/ETS2090.py'
adding 'labinstrument/turntable/ETS2090/__init__.py'
adding 'labinstrument-0.0.6.dist-info/top_level.txt'
adding 'labinstrument-0.0.6.dist-info/WHEEL'
adding 'labinstrument-0.0.6.dist-info/METADATA'
adding 'labinstrument-0.0.6.dist-info/RECORD'
removing build/bdist.macosx-10.6-intel/wheel
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing ./dist_compiled/labinstrument-0.0.6-py3-none-any.whl
Installing collected packages: labinstrument
  Found existing installation: labinstrument 0.0.5
    Uninstalling labinstrument-0.0.5:
      Successfully uninstalled labinstrument-0.0.5
Successfully installed labinstrument-0.0.6

Process finished with exit code 0