Search code examples
pythonpython-packagingpython-poetry

How can I create an empty python package?


I would like to create an empty (meta)package using the poetry tool, mainly to simplify bringing together a list of dependencies. If I create my project.toml as follows:

[build-system]
requires = ["poetry"]

[tool.poetry]
name = "metapackage"
version = "1.0.0"
description = "My empty metapackage"
authors = ["Me"]
license = "MIT"

[tool.poetry.dependencies]
numpy = "*"

Then execute poetry build, I get an error:

$ 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))

Am I missing something to tell poetry that this package has no contents?

Addendum: I'm jusy using poetry as a means to creating a .dist-info directory populated with metadata, so that pip sees the installed metapackae, if there's a better tool for that, I'm happy to switch.


Solution

  • With setuptools it could look like the following:

    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
    

    Note how the options packages, py_modules, scripts, and ext_modules are not populated.