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

Support [project] table in pyproject.toml (PEP 621) #393

Merged
merged 28 commits into from
Mar 15, 2021
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift click to select a range
ce2ec0d
Start integrating support for PEP 621 metadata
takluyver Feb 20, 2021
62c26e7
Remove f-strings :(
takluyver Feb 20, 2021
6755cd0
Validate that dynamic fields are listed
takluyver Feb 27, 2021
b1a170d
Test loading config for PEP 621 with no dynamic fields
takluyver Feb 27, 2021
7bebd01
Set module name from PEP 621 table
takluyver Feb 27, 2021
6110be5
Remove unused metadata_and_module_from_ini_path function
takluyver Feb 27, 2021
432dc76
Avoid reusing imported modules for getting metadata
takluyver Feb 27, 2021
bd43136
Only get dynamic fields from module contents
takluyver Feb 27, 2021
d8e9c0a
Remove debugging prints
takluyver Feb 27, 2021
02e364c
Some integration tests for PEP 621 metadata
takluyver Feb 27, 2021
6472383
No extra build requirements with statically specified metadata
takluyver Feb 27, 2021
06352f1
Remove stray f-string
takluyver Feb 27, 2021
449a687
Test author metadata from [project] table
takluyver Feb 27, 2021
87cac59
Don't modify dict when creating Metadata object
takluyver Feb 28, 2021
f1090e4
Fix error message
takluyver Mar 8, 2021
bea8d33
Fix starting 'flit install' with statically specified PEP 621 metadata
takluyver Mar 8, 2021
2d6fd33
Fix [build-system] tables for PEP 621 samples
takluyver Mar 8, 2021
91394d5
Version number -> 3.2.0
takluyver Mar 8, 2021
d3043ff
Normalise version number coming from PEP 621 config
takluyver Mar 8, 2021
77eb453
Exercise reading more PEP 621 fields
takluyver Mar 11, 2021
059a130
Correct scripts & gui-scripts tables
takluyver Mar 11, 2021
85b1684
Add keywords & classifiers to PEP 621 samples
takluyver Mar 11, 2021
e781ed7
Add requires-python field to PEP 621 sample
takluyver Mar 11, 2021
97e9918
Test error checking in PEP 621 [project] table
takluyver Mar 11, 2021
c5134d6
Test checking for relative path to README
takluyver Mar 11, 2021
88dde16
Test unrecognised field in project.readme table
takluyver Mar 11, 2021
43b7c54
Use email.headerregistry.Address to format 'name <email@domain>'
takluyver Mar 12, 2021
746afdc
Allow module name != distribution name with PEP 621
takluyver Mar 12, 2021
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
Prev Previous commit
Next Next commit
Remove f-strings :(
  • Loading branch information
takluyver committed Mar 8, 2021
commit 62c26e78bad470da05004e82ee4a8d86f88ff0a9
20 changes: 10 additions & 10 deletions flit_core/flit_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 111,7 @@ def prep_toml_config(d, path):
unknown_sections = [s for s in unknown_sections if not s.lower().startswith('x-')]
if unknown_sections:
raise ConfigError('Unexpected tables in pyproject.toml: ' ', '.join(
f'[tool.flit.{s}]' for s in unknown_sections
'[tool.flit.{}]'.format(s) for s in unknown_sections
))

if 'sdist' in dtool:
Expand Down Expand Up @@ -372,15 372,15 @@ def _expand_requires_extra(re):
def _check_type(d, field_name, cls):
if not isinstance(d[field_name], cls):
raise ConfigError(
f"{field_name} field should be {cls}, not {type(d[field_name])}"
"{} field should be {}, not {}".format(field_name, cls, type(d[field_name]))
)

def _check_list_of_str(d, field_name):
if not isinstance(d[field_name], list) or not all(
isinstance(e, str) for e in d[field_name]
):
raise ConfigError(
f"{field_name} field should be a list of strings"
"{} field should be a list of strings".format(field_name)
)

def read_pep621_metadata(proj, path) -> LoadedConfig:
Expand Down Expand Up @@ -412,14 412,14 @@ def read_pep621_metadata(proj, path) -> LoadedConfig:
unrec_keys = set(readme.keys()) - {'text', 'file', 'content-type'}
if unrec_keys:
raise ConfigError(
f"Unrecognised keys in [project.readme]: {unrec_keys}"
"Unrecognised keys in [project.readme]: {}".format(unrec_keys)
)
if 'content-type' in readme:
mimetype = readme['content-type']
mtype_base = mimetype.split(';')[0].strip() # e.g. text/x-rst
if mtype_base not in readme_ext_to_content_type.values():
raise ConfigError(
f"Unrecognised readme content type: {mtype_base!r}"
"Unrecognised readme content type: {!r}".format(mtype_base)
)
# TODO: validate content-type parameters (charset, md variant)?
else:
Expand Down Expand Up @@ -458,7 458,7 @@ def read_pep621_metadata(proj, path) -> LoadedConfig:
unrec_keys = set(license_tbl.keys()) - {'text', 'file'}
if unrec_keys:
raise ConfigError(
f"Unrecognised keys in [project.license]: {unrec_keys}"
"Unrecognised keys in [project.license]: {}".format(unrec_keys)
)

# TODO: Do something with license info.
Expand Down Expand Up @@ -548,7 548,7 @@ def read_pep621_metadata(proj, path) -> LoadedConfig:
for e, reqs in optdeps.items():
if not all(isinstance(a, str) for a in reqs):
raise ConfigError(
f'Expected a string list for optional-dependencies ({e})'
'Expected a string list for optional-dependencies ({})'.format(e)
)

# Move dev-requires into requires-extra
Expand Down Expand Up @@ -585,16 585,16 @@ def pep621_people(people, group_name='author') -> (str, str):
names, emails = [], []
for person in people:
if not isinstance(person, dict):
raise ConfigError(f"{group_name} info must be list of dicts")
raise ConfigError("{} info must be list of dicts".format(group_name))
unrec_keys = set(person.keys()) - {'name', 'email'}
if unrec_keys:
raise ConfigError(
f"Unrecognised keys in {group_name} info: {unrec_keys}"
"Unrecognised keys in {} info: {}".format(group_name, unrec_keys)
)
if 'email' in person:
email = person['email']
if 'name' in person:
email = f'{person["name"]} <{email}>'
email = '{} <{}>'.format(person["name"], email)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users can include weird stuff in this field and break the formatting. Not sure if this is an issue.

{ name = "Jane\n\n\nDoe <[email protected]>", email="[email protected]" }

One could use formataddr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I didn't know about that function. It somewhat garbles non-ASCII text, though:

In [10]: email.utils.formataddr(('Zoë', '[email protected]>'))
Out[10]: '=?utf-8?q?Zo=C3=AB?= <[email protected]>>'

I don't know if that's what should happen. The original version metadata spec 1.0 (PEP 241) says the format is based on email headers, and presumably that's what email headers do. But that was almost 20 years ago, and it's possible that tools expect something a bit more Unicode native now. PEP 621 explicitly suggests "the format {name} <{email}>".

I'll open a discussion on the Python discourse about this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emails.append(email)
elif 'name' in person:
names.append(person['name'])
Expand Down