在Python上上传新的库 [英] Upload New Library on Python

查看:0
本文介绍了在Python上上传新的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Python中部署一个库,并尝试使用pippip install它,但在上载该库后,它只安装了INFO文件:";oauth2clientz.egg-info";。

注意:我的库名为oauth2clientz

我遵循的步骤:

  1. 创建一个名为oauth2clientz的文件夹。

  2. 创建License.txt文件,其中放入我自己的许可证。

  3. 创建Manifest.in文件并编写以下代码:

    global-include *.txt *.py
    
  4. 创建setup.py文件并编写以下代码:

    from setuptools import setup, find_packages
    
    setup(
    name='oauth2clientz',
    version='0.0.1',
    description='oauth2clientzskproject',
    long_description='outh2client',
    long_description_content_type='text/plain',
    url='https://github.com/sukan/oauth2clientz',
    author='sukan',
    author_email='sukanpp@gmail.com',
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Intended Audience :: Developers',
        'Topic :: Software Development :: Build Tools',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',
    ],
    keywords='oauth2clientz project',
    )
    
  5. 在此文件夹中创建新文件夹,将其命名为oauth2clientz,并将我的所有库文件放入其中(__init__.py)。

  6. 转到cmd的第一个oauth2clientz文件夹,然后输入:

    python setup.py sdist
    
  7. 它将生成以下两个文件夹:";oauth2clientz.egg-info";和";dist";。

  8. 最后,输入命令cmd:

    twipe upload --repository-url https://upload.pypi.org/legacy/ dist/*
    
    enter username:
    
    enter password:
    

已将其部署到Python org,但当我使用pip install oauth2clientz安装它时,它只安装了这个信息文件夹:";oauth2clientz.egg-info";,它没有安装我添加到oauth2clientz文件夹中的库。

为什么?我的工作哪里做错了?我是否应该向setup.py文件中添加任何内容?

推荐答案

正如@Klaus D所述,您缺少packages

根据上次的最佳实践(src layoutpyproject.tomlsetup.cfg..)),您的包通常应具有以下结构:

oauth2clientz/

  .. src/
     .. oauth2clientz/
        .. __ init__.py  # HERE you declare the version of your package
        .. module-1.py
        .. module-2.py

  .. tests/
     .. __ init__.py
     .. test_module_1.py
     .. test_module_2.py

  .. .editconfig
  .. .gitignore
  .. LISENCE
  .. MANIFEST.in
  .. README.md
  .. setup.cfg
  .. pyproject.toml

src/oauth2clientz/__init__.py

from module_1 import [..]
from module_2 import [..]


VERSION = (0, 0, 1, 'dev1')
__version__ = '.'.join(map(str, VERSION))


# YOU business logic 
# ..

MANIFEST.IN

# https://packaging.python.org/guides/using-manifest-in/
graft src/oauth2clientz
global-exclude __pycache__
global-exclude *.py[cod]

setup.cfg

# https://setuptools.readthedocs.io/en/latest/userguide/declarative_config.html
[metadata]
name = oauth2clientz
version = attr: oauth2clientz.__version__  # use 'attr:' helper get the version from the package 
description = oauth2 clientz project
long_description = file: README.md
long_description_content_type = text/markdown
author = sukan
author_email = sukanpp@gmail.com
# maintainer =
# maintainer_email =
license = BSD-3-Clause
license_file = LICENSE
# license_files = LICENSES/*
url = https://github.com/sukan/oauth2clientz
download_url = https://github.com/sukan/oauth2clientz
project_urls =
    Documentation = https://github.com/sukan/oauth2clientz#readme
    Issue Tracker = https://github.com/sukan/oauth2clientz/issues
    Source Code = https://github.com/sukan/oauth2clientz
keywords = oauth2 client
sclassifiers =
    Development Status :: 1 - Planning
    Intended Audience :: Developers
    License :: OSI Approved :: BSD License
    Operating System :: OS Independent
    Programming Language :: Python
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3 :: Only
    Programming Language :: Python :: 3.6
    Programming Language :: Python :: 3.7
    Programming Language :: Python :: 3.8
    Programming Language :: Python :: 3.9
platforms = any

[options]
python_requires = >=3.6
packages = find:  # use 'find:' to finde packages located in 'package_dir' 
package_dir =
    = src
zip_safe = False

[options.packages.find]
where = src

[options.extras_require]
tests =
  pytest
  pytest-cov

code =
  flake8

pyproject.toml

[build-system]
# https://setuptools.readthedocs.io/en/latest/setuptools.html#setup-cfg-only-projects
requires = [
  "setuptools >= 58",
  "wheel"
]
build-backend = "setuptools.build_meta"

如果您在Windows上,并且想要生成并发布您的包

pip install build wheel twine
py -m build -n  # don't forget '-n' flage to force using your project venv
py install -e .  # for editable mode 
py -m twine upload dist/*  # if everything is ok then pulish it on pypi

希望工作正常。

这篇关于在Python上上传新的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆