Index: pluginconf/flit.py ================================================================== --- pluginconf/flit.py +++ pluginconf/flit.py @@ -1,35 +1,43 @@ # encoding: utf-8 # api: pep517 # title: flit backend # description: wraps flit_core.buildapi -# version: 0.2 +# version: 0.3 # depends: python:flit (>=3.0, <4.0) # license: BSD-3-Clause # priority: extra -# src: ~/.local/lib/python3.8/site-packages/flit_core/ # pylint: disable=unused-import, wrong-import-position, wrong-import-order # -# This is supposed to become an alternative to pluginconf.setup, -# using flit as pep517 build backend. But adding automagic field -# lookup of course. +# As alternative to pluginconf.setup, this module is using flit as +# pep517 build backend. But adding automagic field lookup of course. # -# It can be invoked per `flit-pluginconfig build` and requires +# It can be invoked per `flit-pluginconfig build` and advises # a `pyproject.toml` like: # # [build-system] -# requires = ["flit_core", "pluginconf"] +# requires = ["pluginconf>=0.8", "flit>=3.2", "setuptools"] # build-backend = "pluginconf.flit" # # [project] # name = "foobar" -# #dynamic = ["version", "description"] +# dynamic = ["version", "description"] # # Injecting attributes between ini reading and parameter collection # turned out easier than expanding on flit_core.buildapi functions. -# And lastly, this just chains to flit.main() to handle setup and -# build steps. +# And lastly, this just chains to flit.main() to handle collect and +# build tasks. +# +# Dynamic handling currently violates all the package tool requirements: +# +# But it does have some interesting side effects. +# * mixes the override text and file inclusion +# license = { file = "LICENSE" } +# * for setuptools compat a long dynamic field is required (but flit hates it) +# dynamic = ["version", "description", "readme", "requires-python", +# "license", "keywords", "classifiers", "urls", "entry-points"] +# Not sure yet if the pyproject.toml specs allow for reconcilation here. # """ monkeypatches flint to use pluginconf sources for packaging """ @@ -52,29 +60,29 @@ setattr(where, func.__name__, func) wrapped.__doc__ = func.__doc__ return func return wrapped +# patch_flit_config @inject(flit_core.config) def read_flit_config(path): - """ @inject read_flit_config() with forced dynamic fields """ + """ @inject patch_flit_config() with forced dynamic fields """ ini = flit_core.config.tomli.loads(path.read_text('utf-8')) - # make fields dynamic - if not "dynamic" in ini["project"]: - ini["project"]["dynamic"] = [] + # make fields dynamic (exactly the fields flit allows) + ini["project"]["dynamic"] = ["version", "description"] + # maybe also record orig list to omit from pmd_meta update? (in addition to ini.MD.get check) for dyn in ['description', 'version']: if dyn in ini["project"]: del ini["project"][dyn] if not dyn in ini["project"]["dynamic"]: ini["project"]["dynamic"].append(dyn) - print(ini) # turn it into LoadedConfig return flit_core.config.prep_toml_config(ini, path) -# override make_metadata +# patch_metadata @inject(flit_core.common) def make_metadata(module, ini_info): """ @inject different sourcing order to apply plugin meta fields """ meta = { "name": module.name, @@ -89,10 +97,11 @@ ) if not meta.get("version"): meta.update( flit_core.common.get_info_from_module(module.file, ['version']) ) + #print(meta) return flit_core.common.Metadata(meta) # map plugin meta to flit Metadata def pmd_meta(pmd, ini): """ enjoin PMD fields with flit.common.MetaData """ @@ -106,45 +115,49 @@ "maintainer": None, "maintainer_email": None, "license": pmd.license, # {name=…} "keywords": pmd.get_keywords(), "download_url": None, - "requires_python": pmd.python_requires() or ">= 2.7", - "platform": pmd.architecture, - "supported_platform": (), + "requires_python": pmd.python_requires(), + "platform": [], + "supported_platform": pmd.architecture, "classifiers": list(pmd.classifiers()) + pmd.trove_license() + pmd.trove_status(), - "provides": (), - "requires": pmd.install_requires().get("install_requires") or (), - "obsoletes": (), + "provides": [], + "requires": [], # supposed to override requires_dist if present + "obsoletes": [], "project_urls": [f"{k}, {v}" for k, v in pmd.project_urls().items()], - "provides_dist": (), - "requires_dist": pmd.install_requires().get("install_requires") or (), - "obsoletes_dist": (), - "requires_external": (), - "provides_extra": (), - } - print(meta) - print(pmd.install_requires()) + "provides_dist": [], + "requires_dist": pmd.install_requires() or [], + "obsoletes_dist": [], + "requires_external": [], + "provides_extra": [], + } + #print(meta) # comment/readme for docs in pmd.plugin_doc(), psetup.get_readme(): if docs["long_description"]: meta.update({ # with "long_" prefix cut off - k[5:]: v for k, v in docs.items() + key[5:]: value for key, value in docs.items() }) # entry_points are in ini file for section, entries in pmd.entry_points().items(): ini.entrypoints[section] = ini.entrypoints.get(section, {}) for script in entries: ini.entrypoints[section].update( dict(re.findall("(.+)=(.+)", script)) ) - print(ini.entrypoints) + #print(ini.entrypoints) + #print(dir(ini)) + #print((ini.metadata)) # strip empty entries - return {k: v for k, v in meta.items() if v} + return { + key: value for key, value in meta.items() + if value and not ini.metadata.get(key) #? + } #-- buildapi from flit_core.buildapi import ( # These have to be late imports; else they'll @@ -155,11 +168,13 @@ prepare_metadata_for_build_editable, build_wheel, build_editable, build_sdist, ) + +del inject # omit from docs #-- invocation point from flit import main if __name__ == "__main__": main(sys.argv)