如何创建一个空的 python 包?
How can I create an empty python package?
我想使用 poetry 工具创建一个空的(元)包,主要是为了简化将依赖项列表组合在一起的过程。如果我按如下方式创建 project.toml:
[build-system]
requires = ["poetry"]
[tool.poetry]
name = "metapackage"
version = "1.0.0"
description = "My empty metapackage"
authors = ["Me"]
license = "MIT"
[tool.poetry.dependencies]
numpy = "*"
然后执行poetry build
,报错:
$ mkdir -p metapackage
$ python -m poetry build --no-interaction --format wheel -vvvUsing virtualenv: /Users/duncan/opt/miniconda3/envs/py37
Building metapackage (1.0.0)
[ValueError]
metapackage is not a package.
Traceback (most recent call last):
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/clikit/console_application.py", line 131, in run
status_code = command.handle(parsed_args, io)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/clikit/api/command/command.py", line 120, in handle
status_code = self._do_handle(args, io)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/clikit/api/command/command.py", line 171, in _do_handle
return getattr(handler, handler_method)(args, io, self)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/cleo/commands/command.py", line 92, in wrap_handle
return self.handle()
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/console/commands/build.py", line 30, in handle
builder.build(fmt)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/builder.py", line 19, in build
builder = self._FORMATS[fmt](self._poetry, self._env, self._io)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/builders/wheel.py", line 44, in __init__
super(WheelBuilder, self).__init__(poetry, env, io)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/builders/builder.py", line 68, in __init__
includes=self._package.include,
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/utils/module.py", line 72, in __init__
source=package.get('from'),
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/utils/package_include.py", line 15, in __init__
self.check_elements()
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/utils/package_include.py", line 61, in check_elements
raise ValueError('{} is not a package.'.format(root.name))
我是不是漏了点什么告诉诗诗这个包裹没有内容了?
附录:我只是想用诗歌来创建一个包含元数据的 .dist-info
目录,以便 pip
看到安装的元数据包,如果有更好的工具,我很高兴切换。
用 poetry 构建的包的绝对最低要求是它包含一个可导入的 python 模块或包。
因此您至少需要一个文件来允许语句 import metapackage
,仅一个没有任何文件的文件夹是不够的:
选项 1,带模块
.
├── pyproject.toml
└── metapackage.py # can be empty
选项 2,带套餐
.
├── pyproject.toml
└── metapackage
└── __init__.py # can be empty
使用 setuptools 它可能如下所示:
pyproject.toml
[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools"]
setup.cfg
[metadata]
name = metapackage
version = 1.0.0
description = My empty metapackage
authors = Me
license = MIT
[options]
install_requires =
numpy
请注意 options packages
, py_modules
, scripts
, and ext_modules
是如何未填充的。
我想使用 poetry 工具创建一个空的(元)包,主要是为了简化将依赖项列表组合在一起的过程。如果我按如下方式创建 project.toml:
[build-system]
requires = ["poetry"]
[tool.poetry]
name = "metapackage"
version = "1.0.0"
description = "My empty metapackage"
authors = ["Me"]
license = "MIT"
[tool.poetry.dependencies]
numpy = "*"
然后执行poetry build
,报错:
$ mkdir -p metapackage
$ python -m poetry build --no-interaction --format wheel -vvvUsing virtualenv: /Users/duncan/opt/miniconda3/envs/py37
Building metapackage (1.0.0)
[ValueError]
metapackage is not a package.
Traceback (most recent call last):
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/clikit/console_application.py", line 131, in run
status_code = command.handle(parsed_args, io)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/clikit/api/command/command.py", line 120, in handle
status_code = self._do_handle(args, io)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/clikit/api/command/command.py", line 171, in _do_handle
return getattr(handler, handler_method)(args, io, self)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/cleo/commands/command.py", line 92, in wrap_handle
return self.handle()
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/console/commands/build.py", line 30, in handle
builder.build(fmt)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/builder.py", line 19, in build
builder = self._FORMATS[fmt](self._poetry, self._env, self._io)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/builders/wheel.py", line 44, in __init__
super(WheelBuilder, self).__init__(poetry, env, io)
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/builders/builder.py", line 68, in __init__
includes=self._package.include,
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/utils/module.py", line 72, in __init__
source=package.get('from'),
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/utils/package_include.py", line 15, in __init__
self.check_elements()
File "/Users/duncan/opt/miniconda3/envs/py37/lib/python3.7/site-packages/poetry/masonry/utils/package_include.py", line 61, in check_elements
raise ValueError('{} is not a package.'.format(root.name))
我是不是漏了点什么告诉诗诗这个包裹没有内容了?
附录:我只是想用诗歌来创建一个包含元数据的 .dist-info
目录,以便 pip
看到安装的元数据包,如果有更好的工具,我很高兴切换。
用 poetry 构建的包的绝对最低要求是它包含一个可导入的 python 模块或包。
因此您至少需要一个文件来允许语句 import metapackage
,仅一个没有任何文件的文件夹是不够的:
选项 1,带模块
.
├── pyproject.toml
└── metapackage.py # can be empty
选项 2,带套餐
.
├── pyproject.toml
└── metapackage
└── __init__.py # can be empty
使用 setuptools 它可能如下所示:
pyproject.toml
[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools"]
setup.cfg
[metadata]
name = metapackage
version = 1.0.0
description = My empty metapackage
authors = Me
license = MIT
[options]
install_requires =
numpy
请注意 options packages
, py_modules
, scripts
, and ext_modules
是如何未填充的。