Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to fail on unknown keys. #506

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions flit_core/flit_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def prep_toml_config(d, path):
"""
dtool = d.get('tool', {}).get('flit', {})

strict = dtool.get("config", {}).get("fail_on_unknown_pep621_keys", False)

if 'project' in d:
# Metadata in [project] table (PEP 621)
if 'metadata' in dtool:
Expand All @@ -94,7 +96,7 @@ def prep_toml_config(d, path):
"[tool.flit.entrypoints]. Use [project.scripts],"
"[project.gui-scripts] or [project.entry-points] as replacements."
)
loaded_cfg = read_pep621_metadata(d['project'], path)
loaded_cfg = read_pep621_metadata(d["project"], path, strict)

module_tbl = dtool.get('module', {})
if 'name' in module_tbl:
Expand All @@ -120,7 +122,12 @@ def prep_toml_config(d, path):
)

unknown_sections = set(dtool) - {
'metadata', 'module', 'scripts', 'entrypoints', 'sdist'
"metadata",
"module",
"scripts",
"entrypoints",
"sdist",
"config",
}
unknown_sections = [s for s in unknown_sections if not s.lower().startswith('x-')]
if unknown_sections:
Expand Down Expand Up @@ -397,7 +404,8 @@ def _check_list_of_str(d, field_name):
"{} field should be a list of strings".format(field_name)
)

def read_pep621_metadata(proj, path) -> LoadedConfig:

def read_pep621_metadata(proj, path, strict: bool = False) -> LoadedConfig:
lc = LoadedConfig()
md_dict = lc.metadata

Expand All @@ -408,7 +416,15 @@ def read_pep621_metadata(proj, path) -> LoadedConfig:

unexpected_keys = proj.keys() - pep621_allowed_fields
if unexpected_keys:
log.warning("Unexpected names under [project]: %s", ', '.join(unexpected_keys))
if strict:
raise ValueError(
"Unexpected names under [project]: %s", ", ".join(unexpected_keys)
)
else:
log.warning(
"Unexpected names under [project]: %s", ", ".join(unexpected_keys)
)


if 'version' in proj:
_check_type(proj, 'version', str)
Expand Down