SK_33
SK_33

Reputation: 87

Package a Python project to be run in the console: pyproject.toml file structure

I have the following structure for a Python project that I want to package to have an entry point on the console.

example_prog
├── src
├   └── my_module_name
├       └── app.py
├       └── blueprint.py
├       └── cli.py
├       └── config.py
├       └── db.py
├       └── search.py
├       └── wsgi.py
├       └── static
├       └── templates
├── pyproject.toml
└── README.md

The cli.py program contains a def main() function which starts as follows:

def main():
    parser = argparse.ArgumentParser(prog="my_module_name")

I have followed what is stated in this link and have the following pyproject.toml that should includes the path to the main file.

[project.scripts]
futdash = "futdash:cli:main"

But when I build with twine (on testpypi) as follows (which is what I am usually doing for other package building):

python3 -m build
python3 -m twine upload --repository testpypi dist/*

But I get the following error:

* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools)
* Getting build dependencies for sdist...
configuration error: `project.scripts.my_module_name` must be python-entrypoint-reference
DESCRIPTION:
    Reference to a Python object. It is either in the form
    ``importable.module``, or ``importable.module:object.attr``.

GIVEN VALUE:
    "my_module_name:cli:main"

OFFENDING RULE: 'format'

DEFINITION:
    {
        "type": "string",
        "format": "python-entrypoint-reference",
        "$comment": "https://packaging.python.org/specifications/entry-points/"
    }

 ..
 ..

  File "/tmp/build-env-g403qutw/lib/python3.9/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_sdist
    return self._get_build_requires(config_settings, requirements=[])
  File "/tmp/build-env-g403qutw/lib/python3.9/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires
    self.run_setup()
  File "/tmp/build-env-g403qutw/lib/python3.9/site-packages/setuptools/build_meta.py", line 335, in run_setup
    exec(code, locals())
  File "<string>", line 1, in <module>
  File "/tmp/build-env-g403qutw/lib/python3.9/site-packages/setuptools/__init__.py", line 87, in setup
    return distutils.core.setup(**attrs)
  File "/tmp/build-env-g403qutw/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 159, in setup
    dist.parse_config_files()
  File "/tmp/build-env-g403qutw/lib/python3.9/site-packages/setuptools/dist.py", line 867, in parse_config_files
    pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
  File "/tmp/build-env-g403qutw/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 62, in apply_configuration
    config = read_configuration(filepath, True, ignore_option_errors, dist)
  File "/tmp/build-env-g403qutw/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 126, in read_configuration
    validate(subset, filepath)
  File "/tmp/build-env-g403qutw/lib/python3.9/site-packages/setuptools/config/pyprojecttoml.py", line 51, in validate
    raise ValueError(f"{error}\n{summary}") from None
ValueError: invalid pyproject.toml config: `project.scripts.my_module_name`.
configuration error: `project.scripts.my_module_name` must be python-entrypoint-reference

ERROR Backend subprocess exited when trying to invoke get_requires_for_build_sdist

Is it a matter of structure of files and implies changing the path in the [project.scripts]?

Upvotes: 3

Views: 3351

Answers (1)

DC Slagel
DC Slagel

Reputation: 586

Try changing the first : colon to a . dot. This should work with structures with the following format:
<Project>.<File>:<Function>

From:

[project.scripts]
futdash = "futdash:cli:main"

To:

[project.scripts]
futdash = "futdash.cli:main"

Upvotes: 4

Related Questions