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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
# built documents.
#
# The short X.Y version.
version = '3.1.0'
version = '3.2.0'
# The full version, including alpha/beta/rc tags.
release = version #+ '.1'

Expand Down
2 changes: 1 addition & 1 deletion flit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .config import ConfigError
from .log import enable_colourful_output

__version__ = '3.1.0'
__version__ = '3.2.0'

log = logging.getLogger(__name__)

Expand Down
6 changes: 3 additions & 3 deletions flit/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,12 @@ def install_requirements(self):
def install_reqs_my_python_if_needed(self):
"""Install requirements to this environment if needed.

We can normally get the module's docstring and version number without
importing it, but if we do need to import it, we may need to install
We can normally get the summary and version number without import the
module, but if we do need to import it, we may need to install
its requirements for the Python where flit is running.
"""
try:
common.get_info_from_module(self.module)
common.get_info_from_module(self.module, self.ini_info.dynamic_metadata)
except ImportError:
if self.deps == 'none':
raise # We were asked not to install deps, so bail out.
Expand Down
2 changes: 1 addition & 1 deletion flit_core/flit_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
All the convenient development features live in the main 'flit' package.
"""

__version__ = '3.1.0'
__version__ = '3.2.0'
9 changes: 7 additions & 2 deletions flit_core/flit_core/buildapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
def get_requires_for_build_wheel(config_settings=None):
"""Returns a list of requirements for building, as strings"""
info = read_flit_config(pyproj_toml)
# If we can get the module info from the AST, we don't need any extra
# If we can get version & description from pyproject.toml (PEP 621), or
# by parsing the module (_via_ast), we don't need any extra
# dependencies. If not, we'll need to try importing it, so report any
# runtime dependencies as build dependencies.
want_summary = 'description' in info.dynamic_metadata
want_version = 'version' in info.dynamic_metadata

module = Module(info.module, Path.cwd())
docstring, version = get_docstring_and_version_via_ast(module)
if (docstring is None) or (version is None):

if (want_summary and not docstring) or (want_version and not version):
return info.metadata.get('requires_dist', [])
else:
return []
Expand Down
52 changes: 33 additions & 19 deletions flit_core/flit_core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,45 +143,65 @@ def get_docstring_and_version_via_ast(target):
return ast.get_docstring(node), version


# To ensure we're actually loading the specified file, give it a unique name to
# avoid any cached import. In normal use we'll only load one module per process,
# so it should only matter for the tests, but we'll do it anyway.
_import_i = 0


def get_docstring_and_version_via_import(target):
"""
Return a tuple like (docstring, version) for the given module,
extracted by importing the module and pulling __doc__ & __version__
from it.
"""
global _import_i
_import_i += 1

log.debug("Loading module %s", target.file)
from importlib.machinery import SourceFileLoader
sl = SourceFileLoader(target.name, str(target.file))
sl = SourceFileLoader('flit_core.dummy.import%d' % _import_i, str(target.file))
with _module_load_ctx():
m = sl.load_module()
docstring = m.__dict__.get('__doc__', None)
version = m.__dict__.get('__version__', None)
return docstring, version


def get_info_from_module(target):
def get_info_from_module(target, for_fields=('version', 'description')):
"""Load the module/package, get its docstring and __version__
"""
if not for_fields:
return {}

# What core metadata calls Summary, PEP 621 calls description
want_summary = 'description' in for_fields
want_version = 'version' in for_fields

log.debug("Loading module %s", target.file)

# Attempt to extract our docstring & version by parsing our target's
# AST, falling back to an import if that fails. This allows us to
# build without necessarily requiring that our built package's
# requirements are installed.
docstring, version = get_docstring_and_version_via_ast(target)
if not (docstring and version):
if (want_summary and not docstring) or (want_version and not version):
docstring, version = get_docstring_and_version_via_import(target)

if (not docstring) or not docstring.strip():
raise NoDocstringError('Flit cannot package module without docstring, '
'or empty docstring. Please add a docstring to your module '
'({}).'.format(target.file))
res = {}

if want_summary:
if (not docstring) or not docstring.strip():
raise NoDocstringError(
'Flit cannot package module without docstring, or empty docstring. '
'Please add a docstring to your module ({}).'.format(target.file)
)
res['summary'] = docstring.lstrip().splitlines()[0]

version = check_version(version)
if want_version:
res['version'] = check_version(version)

docstring_lines = docstring.lstrip().splitlines()
return {'summary': docstring_lines[0],
'version': version}
return res

def check_version(version):
"""
Expand Down Expand Up @@ -297,6 +317,7 @@ class Metadata(object):
metadata_version = "2.1"

def __init__(self, data):
data = data.copy()
self.name = data.pop('name')
self.version = data.pop('version')
self.summary = data.pop('summary')
Expand Down Expand Up @@ -363,17 +384,10 @@ def supports_py2(self):

def make_metadata(module, ini_info):
md_dict = {'name': module.name, 'provides': [module.name]}
md_dict.update(get_info_from_module(module))
md_dict.update(get_info_from_module(module, ini_info.dynamic_metadata))
md_dict.update(ini_info.metadata)
return Metadata(md_dict)

def metadata_and_module_from_ini_path(ini_path):
from .config import read_flit_config
ini_path = str(ini_path)
ini_info = read_flit_config(ini_path)
module = Module(ini_info.module, osp.dirname(ini_path))
metadata = make_metadata(module, ini_info)
return metadata,module


def normalize_dist_name(name: str, version: str) -> str:
Expand Down
Loading