Skip to content

Commit

Permalink
Merge pull request #566 from joukewitteveen/patch-1
Browse files Browse the repository at this point in the history
Normalize module name default value
  • Loading branch information
takluyver committed Aug 2, 2022
2 parents fd209d7 + 41669cd commit f861277
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
9 changes: 7 additions & 2 deletions doc/pyproject_toml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ The allowed fields are:

name
The name your package will have on PyPI. This field is required. For Flit,
this also points to your package as an import name by default (see
:ref:`pyproject_module` if that needs to be different).
this name, with any hyphens replaced by underscores, is also the default value
of the import name (see :ref:`pyproject_module` if that needs to be
different).
version
Version number as a string. If you want Flit to get this from a
``__version__`` attribute, leave it out of the TOML config and include
Expand Down Expand Up @@ -233,6 +234,10 @@ you should specify the install (PyPI) name in the ``[project]`` table
[tool.flit.module]
name = "nsist"
Flit looks for the source of the package by its import name. The source may be
located either in the directory that holds the ``pyproject.toml`` file, or in a
``src/`` subdirectory.

.. _pyproject_old_metadata:

Old style metadata
Expand Down
3 changes: 2 additions & 1 deletion flit_core/flit_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ def read_pep621_metadata(proj, path) -> LoadedConfig:
if 'name' not in proj:
raise ConfigError('name must be specified in [project] table')
_check_type(proj, 'name', str)
lc.module = md_dict['name'] = proj['name']
md_dict['name'] = proj['name']
lc.module = md_dict['name'].replace('-', '_')

unexpected_keys = proj.keys() - pep621_allowed_fields
if unexpected_keys:
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions flit_core/flit_core/tests/samples/normalization/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[build-system]
requires = ["flit_core >=3.8,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "my-python-module"
version = "0.0.1"
description = "Hyphenated package name, infered import name"
authors = [
{name = "Sir Robin", email = "robin@camelot.uk"}
]

[project.urls]
homepage = "http://github.com/me/python-module"
5 changes: 5 additions & 0 deletions flit_core/flit_core/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def test_load_toml_ns():
assert inf.module == 'ns1.pkg'
assert inf.metadata['home_page'] == 'http://github.com/sirrobin/module1'

def test_load_normalization():
inf = config.read_flit_config(samples_dir / 'normalization' / 'pyproject.toml')
assert inf.module == 'my_python_module'
assert inf.metadata['name'] == 'my-python-module'

def test_load_pep621():
inf = config.read_flit_config(samples_dir / 'pep621' / 'pyproject.toml')
assert inf.module == 'module1a'
Expand Down

0 comments on commit f861277

Please sign in to comment.