Index: pluginconf/setup.py ================================================================== --- pluginconf/setup.py +++ pluginconf/setup.py @@ -1,11 +1,11 @@ # encoding: utf-8 # api: setuptools ##type: functions # title: setup() wrapper # description: utilizes PMD to populate some package fields -# version: 0.4 +# version: 0.5 # license: PD # pylint: disable=line-too-long # # Utilizes plugin meta data to cut down setup.py incantations # to basically just: @@ -48,11 +48,10 @@ import os import re import glob import pprint -import setuptools import pluginconf def name_to_fn(name): """ find primary entry point.py from package name """ @@ -93,19 +92,26 @@ def python_requires(self): """ depends: python >= 3.5 """ deps = re.findall(r"python\s*\(?(>=?\s?[\d.]+)", self.get("depends", "")) if deps: - return {"python_requires": deps[0]} - return {} + return deps[0] + return None def install_requires(self): """ depends: python:module, pip:module """ - deps = re.findall(r"(?:python|pip):([\w\-]+)\s*(\(?[<=>\s\d.\-]+)?", self.get("depends", "")) + deps = re.findall(r"(?:python|pip):([\w\-]+)\s*([\s\d\w.\-~]+|\([\s\d\w.\-,~]+\))?", self.get("depends", "")) if deps: - return {"install_requires": [name+re.sub(r"[^<=>\d.\-]", "", ver) for name, ver in deps]} - return {} + for index, (name, ver) in enumerate(deps): + ver = re.sub(r"[(\s)]+", "", ver) + if not ver: + continue + ver = re.sub("(,)", r"\1 ", ver) + deps[index] = (name, " (" + ver + ")") + # doesn't need much cleanup: https://peps.python.org/pep-0508/ + return [name + ver for name, ver in deps] + return [] def extras_require(self): """ suggest: line """ deps = re.findall(r"(?:python|pip):([\w\-]+)\s*\(?\s*([>=<]+\s*[\d.\-]+)", self.get("suggests", "")) if deps: @@ -188,26 +194,32 @@ def get_keywords(self): """ keywords= """ return self.keywords or self.category or self.type - -def setup(debug=0, **kwargs): +@pluginconf.renamed_arguments({"fn": "filename"}) +def setup(filename=None, debug=False, **kwargs): """ Wrapper around `setuptools.setup()` which adds some defaults - and plugin meta data import, with two shortcut params: + and plugin meta data import, with some shortcut parameters: Parameters ---------- - fn : str - main file "pkg/main.py" + filename : str + main file "pkg/main.py" (else deduced from primary package name) + debug : bool + display collected options prior setuptools.setup() invocation long_description : str e.g. "README.md", else comment block used Other setup() params work as usual, and are passed trough. Notably entry_points= or data_files= can be used, even if they get augmented. """ + + # optionalized here (avoid dependency in flit import) + # p-y-l-i-n-t: disable=import-outside-toplevel + import setuptools # stub values stub = { "classifiers": [], "project_urls": {}, @@ -230,30 +242,24 @@ # read README if field empty or says `@README` if re.match("^$|^[@./]*README.{0,5}$", kwargs.get("long_description", "")): kwargs.update(get_readme()) - # search name= package if no fn= given - if kwargs.get("filename"): - kwargs["fn"] = kwargs["filename"] - del kwargs["filename"] - if not kwargs.get("fn") and kwargs.get("name"): - kwargs["fn"] = name_to_fn(kwargs["name"]) + # search name= package if no filename= given + if not filename and kwargs.get("name"): + filename = name_to_fn(kwargs["name"]) # read plugin meta data (PMD) pmd = MetaUtils( - pluginconf.plugin_meta(filename=kwargs["fn"]) + pluginconf.plugin_meta(filename=filename) ) - # id: if no name= still + # use id: if no name= still if pmd.get("id") and not kwargs.get("name"): if pmd["id"] == "__init__": - pmd["id"] = re.findall(r"([\w\.\-]+)/__init__.+$", kwargs["fn"])[0] + pmd["id"] = re.findall(r"([\w\.\-]+)/__init__.+$", filename)[0] kwargs["name"] = pmd["id"] - # cleanup - if "fn" in kwargs: - del kwargs["fn"] # version:, description:, author: for field in "version", "description", "license", "author", "url": if field in pmd and not field in kwargs: kwargs[field] = pmd[field] @@ -260,13 +266,13 @@ # other urls: kwargs["project_urls"].update(pmd.project_urls()) # depends: if "depends" in pmd: - kwargs.update(pmd.python_requires()) + kwargs["python_requires"] = pmd.python_requires() if "depends" in pmd and not kwargs["install_requires"]: - kwargs.update(pmd.install_requires()) + kwargs["install_requires"] = pmd.install_requires() # suggests: if "suggests" in pmd and not kwargs["extras_require"]: kwargs["extras_require"].update(pmd.extras_require()) # doc: if not kwargs.get("long_description"): Index: setup.py ================================================================== --- setup.py +++ setup.py @@ -15,15 +15,16 @@ #from os import system #system("pandoc -f markdown -t rst README.md > README.rst") pluginconf.setup.setup( - fn="pluginconf/__init__.py", + filename="pluginconf/__init__.py", long_description="README.md", + packages=["pluginconf"], #author_email="m..@include-once.org", # entry_points={ # "console_scripts": [ # "flit-pluginconf=pluginconf.flit:main", # ] # }, )