`module` vs `dist-name` in PEP 621?

With flit there is a way to specify a dist-name (for example, scikit-learn) different from the module (for example, sklearn). Is there a way to do it with the PEP 621 metadata?

The relationship is the inverse. dist-name in flit is equivalent to name in PEP 621 and there is no equivalent for module. PEP 621 does not attempt to standardise build metadata and deriving the module name from the project name is something that’s specific to flit.

2 Likes

OT: is a package in poetry the same as a module in flit? The pyproject.toml file | Documentation | Poetry - Python dependency management and packaging made easy

I.e. is a module just another directory with sources or something like the concept of assembling multiple more independent units like e.g. in maven, where you may manage two webapps and a common library in one project and each webapp and the library are a module?

A module in Python is a single unit which can be imported (meaning 1). The “module” field in flit accepts either a Python source file with a .py extension, also known as a “module” (meaning 2), or a folder containing at least one Python source file, __init__.py, and also known as a “package”. Python supports importing modules (meaning 2) and packages as modules (meaning 1). In Poetry’s description of the “package” field, “module” has the second meaning and “package” has the same meaning as in flit. Neither field name describes its value accurately - Poetry emphasises packages whereas flit is probably inspired by the import system abstraction.

1 Like

Thanks @layday for the response. However, setting aside the specific flit feature, doesn’t setuptools also have a way of designating the package (name) that doesn’t have to match the actual package names (packages)? If I understand correctly, in PEP 621 this capability doesn’t exist, and it wasn’t just a flit-specific thing.

PEP 621 is solely about package (in the sense of “distribution package”, a project that can be distributed as a sdist/wheel on PyPI) metadata. So it has a means to specify the name of the package/project. This is the equivalent of “scikit-learn” (so I guess the dist-name in flit terms).

PEP 621 does not address the details of how to determine what files will get distributed as part of the package, that’s a matter for the build backend (flit or setuptools, for example). So module in flit is a backend-specific way of giving that information, which is in the tool.flit.metadata section precisely because it is not standardised (by PEP 621 or any other PEP). For setuptools, this is handled using the packages value in setup.cfg or setup.py.

2 Likes

The problem is that at least flit does not allow using both:

  Complete output (14 lines):
  Traceback (most recent call last):
    File "/home/juanlu/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 280, in <module>
      main()
    File "/home/juanlu/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 263, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/home/juanlu/Projects/LSF/opensatcom/constellation-designer/.venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 114, in get_requires_for_build_wheel
      return hook(config_settings)
    File "/tmp/pip-build-env-u188qixe/overlay/lib/python3.9/site-packages/flit_core/buildapi.py", line 23, in get_requires_for_build_wheel
      info = read_flit_config(pyproj_toml)
    File "/tmp/pip-build-env-u188qixe/overlay/lib/python3.9/site-packages/flit_core/config.py", line 71, in read_flit_config
      return prep_toml_config(d, path)
    File "/tmp/pip-build-env-u188qixe/overlay/lib/python3.9/site-packages/flit_core/config.py", line 89, in prep_toml_config
      raise ConfigError(
  flit_core.config.ConfigError: Use [project] table for metadata or [tool.flit.metadata], not both.

but perhaps this is a flit bug @takluyver ?

(To clarify: even if I want to use PEP 621 name plus a backend-specific way of determining the files, at the moment flit does not allow it)

Yep, that sounds like a flit bug.

If you’re using PEP 621 metadata, you can specify a different distribution name & module name like this:

[project]
name = "pyfoo"  # As in: pip install pyfoo

[tool.flit.module]
name = "foo"   # As in: import foo

Note the second table is tool.flit.module rather than the old .metadata. I decided to have a clean break between the new config based around PEP 621 and the previous style.

This is undocumented so far because I wanted to try out the new style and have a chance to fix any bugs before inviting lots of people to use it. So thanks for trying it out!

6 Likes

Works beautifully :slight_smile: Thanks @takluyver !

1 Like

For future reference (because I keep coming back to this), it’s now documented at The pyproject.toml config file — Flit 3.9.0 documentation