Index: html/flit.html ================================================================== --- html/flit.html +++ html/flit.html @@ -3,11 +3,12 @@ pluginconf.flit API documentation - + @@ -20,11 +21,20 @@

Module pluginconf.flit

-

monkeypatches flint to use pluginconf sources for packaging

+

monkeypatches flit to use pluginconf sources for packaging with a +pyproject.toml like:

+
[build-system]
+requires = ["pluginconf", "flit"]
+build-backend = "pluginconf.flit"
+
+[project]
+name = "foobar"
+
+

Can be invoked per flit-pluginconf build or python -m build.

flit - can't believe it's not setup.py!!

Index: html/index.html ================================================================== --- html/index.html +++ html/index.html @@ -21,10 +21,17 @@

Package pluginconf

Plugin meta extraction and module lookup

+
    +
  • Main function plugin_meta(filename=…) unpacks +meta fields +into dictionaries.
  • +
  • Other utility code is about module location, but requires +some initialization.
  • +

#

Sub-modules

@@ -32,11 +39,12 @@

Dependency validation and consistency checker for updates

pluginconf.flit
-

monkeypatches flint to use pluginconf sources for packaging …

+

monkeypatches flit to use pluginconf sources for packaging with a +pyproject.toml like: …

pluginconf.gui

PySimpleGUI window to populate config dict via plugin options …

@@ -67,10 +75,23 @@
meta : dict
input plugin meta data (invoke once per plugin)
module : str
basename of meta: blocks plugin file
+ +
+def all_plugin_meta() +
+
+

This is a trivial wrapper to assemble a complete dictionary +of available/installed plugins. It associates each plugin name +with a its meta{} fields.

+

Returns

+
+
dict : names to meta data dict
+
 
+
def get_data(filename, decode=False, gzip=False, file_base=None)
@@ -118,31 +139,47 @@

Extract plugin meta data block from different sources:

Parameters

filename : str
-
read literal files, or .pyz contents
+
Read literal files, or .pyz contents.
src : str
-
from already uncovered script code
+
From already uncovered script code.
module : str
-
lookup per pkgutil, from plugin_base or top-level modules
+
Lookup per pkgutil, from plugin_base or top-level modules.
frame : int
-
extract comment header of caller (default)
+
Extract comment header of caller (default).
extra_base : list
-
additional search directories
+
Additional search directories.
max_length : list
-
maximum size to read from files
+
Maximum size to read from files.

Returns

-
dict : key-value pairs of comment fields, config: preparsed
+
dict : Extracted comment fields, with config: preparsed
 
+

Classes

+
+
+class PluginMeta +(*args, **kwargs) +
+
+

Plugin meta data, as dictionary with alternative .property access. +Returned for each plugin_meta() result, and config: options. +Non-existent .fieldnames just resolve to "".

+

Ancestors

+
    +
  • builtins.dict
  • +
+
+
Index: pluginconf/__init__.py ================================================================== --- pluginconf/__init__.py +++ pluginconf/__init__.py @@ -80,10 +80,16 @@ # module basenames, if there's only one namespace to manage. (Plugin # names unique across project.) """ Plugin meta extraction and module lookup + + * Main function `plugin_meta(filename=…)` unpacks + [meta fields](https://fossil.include-once.org/pluginspec/) + into dictionaries. + * Other utility code is about module location, but requires + some initialization. ![#](https://fossil.include-once.org/pluginspec/logo) """ @@ -105,11 +111,12 @@ return zlib.decompress(bytestr, 16 + zlib.MAX_WBITS) import zipfile import argparse __all__ = [ - "get_data", "module_list", "plugin_meta", "add_plugin_defaults" + "plugin_meta", "get_data", "module_list", "add_plugin_defaults", + "PluginMeta", "all_plugin_meta", ] # Injectables # ‾‾‾‾‾‾‾‾‾‾‾ @@ -251,25 +258,25 @@ Extract plugin meta data block from different sources: Parameters ---------- filename : str - read literal files, or .pyz contents + Read literal files, or .pyz contents. src : str - from already uncovered script code + From already uncovered script code. module : str - lookup per pkgutil, from plugin_base or top-level modules + Lookup per pkgutil, from plugin_base or top-level modules. frame : int - extract comment header of caller (default) + Extract comment header of caller (default). extra_base : list - additional search directories + Additional search directories. max_length : list - maximum size to read from files + Maximum size to read from files. Returns ------- - dict : key-value pairs of comment fields, config: preparsed + dict : Extracted comment fields, with config: preparsed """ # Try via pkgutil first, # find any plugins.* modules, or main packages if module: @@ -314,11 +321,11 @@ @renamed_arguments({"fn": "filename"}) def plugin_meta_extract(src="", filename=None, literal=False): """ Finds the first comment block. Splits key:value header fields from comment. Turns everything into an dict, with - some stub fields if absent. + some stub fields if absent. Dashes substituted for underscores. Parameters ---------- src : str from existing source code @@ -357,24 +364,28 @@ if src.find("\n\n") > 0: src, meta["doc"] = src.split("\n\n", 1) # Turn key:value lines into dictionary for field in rx.keyval.findall(src): - meta[field[0].replace("-", "_")] = field[1].strip() + meta[field[0].replace("-", "_").lower()] = field[1].strip() meta["config"] = plugin_meta_config(meta.get("config") or "") return PluginMeta(meta) # Dict wrapper # ‾‾‾‾‾‾‾‾‾‾‾‾ class PluginMeta(dict): - """ Plugin meta data, convenience dict with property access """ + """ + Plugin meta data, as dictionary with alternative .property access. + Returned for each `plugin_meta()` result, and config: options. + Non-existent .fieldnames just resolve to `""`. + """ def __getattr__(self, key): """ Return [key] for .property access, else None """ - return self.get(key) + return self.get(key, "") def __hasattr__(self, key): """ Return [key] for .property access, else None """ return key in self Index: pluginconf/flit.py ================================================================== --- pluginconf/flit.py +++ pluginconf/flit.py @@ -9,21 +9,10 @@ # pylint: disable=unused-import, wrong-import-position, wrong-import-order # # 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 advises -# a `pyproject.toml` like: -# -# [build-system] -# requires = ["pluginconf>=0.8", "flit>=3.2", "setuptools"] -# build-backend = "pluginconf.flit" -# -# [project] -# name = "foobar" -# 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 collect and # build tasks. # @@ -34,20 +23,31 @@ # 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 +monkeypatches flit to use pluginconf sources for packaging with a +`pyproject.toml` like: + + [build-system] + requires = ["pluginconf", "flit"] + build-backend = "pluginconf.flit" + + [project] + name = "foobar" + +Can be invoked per `flit-pluginconf build` or `python -m build`. ![flit - can't believe it's not setup.py!!](https://i.imgur.com/82cTkcq.gif) """ import sys +import os import re import functools import flit_core.common import flit_core.config @@ -172,13 +172,15 @@ prepare_metadata_for_build_editable, build_wheel, build_editable, build_sdist, ) +import flit_core.buildapi # also permit backend="pluginconf.flit:buildapi" del inject # omit from docs #-- invocation point from flit import main if __name__ == "__main__": + # os.environ["FLIT_ALLOW_INVALID"] = 1 # alternative to patch_flit_config? main(sys.argv) Index: test/basic.py ================================================================== --- test/basic.py +++ test/basic.py @@ -23,9 +23,9 @@ assert pmd["title"] == "basic PMD" def doc_(pmd): assert pmd["doc"] == "This the doc." -# Should probably migrate all to pmd.property access now that we have PluginMeta wrapper +# Should probably migrate all to PluginMeta.property access def test_all_as_props(pmd): for key, val in pmd.items(): assert getattr(pmd, key) == val