Overview
Comment:move name_to_fn and get_readme into MetaUtils
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 63fdedee18b22b1c6c904b43e044800cedf7064b098cc712930fbfa534b44b64
User & Date: mario on 2022-11-01 18:50:32
Other Links: manifest | tags
Context
2022-11-01
23:29
use dict.pop() instead of get+del check-in: 900b323b25 user: mario tags: trunk
18:50
move name_to_fn and get_readme into MetaUtils check-in: 63fdedee18 user: mario tags: trunk
16:57
add new comment extraction rx check-in: 3ad4b252ac user: mario tags: trunk
Changes

Modified html/bind.html from [58b168e720] to [4883e6f315].

97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111







-
+







</tr>
</tbody>
</table>
<p>Module should be a package, as in a directory and init <code>plugins/__init__.py</code>.
Ideally this module was already imported in main. But parameter may be a string.</p>
<p>This could be invoked multiple times for the package name to append further
path= arguments (=./contrib/, =/usr/share/app/extenstions/, or a .pyz). Which
is functionally identical to delcaring <code>__path__</code> in the <code>package/__init__.py</code>.</p></div>
is functionally identical to declaring <code>__path__</code> in the <code>package/__init__.py</code>.</p></div>
</dd>
<dt id="pluginconf.bind.defaults"><code class="name flex">
<span>def <span class="ident">defaults</span></span>(<span>conf)</span>
</code></dt>
<dd>
<div class="desc"><p>Traverse installed plugins and expand config dict with presets 🧩 🧾</p>
<table>

Modified html/setup.html from [e6c6068172] to [ac7e57ed41].

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
27
28
29
30
31
32
33












34
35
36
37
38
39
40







-
-
-
-
-
-
-
-
-
-
-
-







<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="pluginconf.setup.get_readme"><code class="name flex">
<span>def <span class="ident">get_readme</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"><p>get README.md contents</p></div>
</dd>
<dt id="pluginconf.setup.name_to_fn"><code class="name flex">
<span>def <span class="ident">name_to_fn</span></span>(<span>name)</span>
</code></dt>
<dd>
<div class="desc"><p>find primary entry point.py from package name</p></div>
</dd>
<dt id="pluginconf.setup.setup"><code class="name flex">
<span>def <span class="ident">setup</span></span>(<span>filename=None, debug=False, **kwargs)</span>
</code></dt>
<dd>
<div class="desc"><p>Wrapper around <code>setuptools.setup()</code> which adds some defaults
and plugin meta data import, with some shortcut parameters:</p>
<table>
97
98
99
100
101
102
103












104
105
106
107
108
109
110
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110







+
+
+
+
+
+
+
+
+
+
+
+







<dl>
<dt id="pluginconf.setup.MetaUtils.datafiles_man"><code class="name flex">
<span>def <span class="ident">datafiles_man</span></span>(<span>)</span>
</code></dt>
<dd>
<div class="desc"><p>data_files=</p></div>
</dd>
<dt id="pluginconf.setup.MetaUtils.get_readme"><code class="name flex">
<span>def <span class="ident">get_readme</span></span>(<span>prefix='long_')</span>
</code></dt>
<dd>
<div class="desc"><p>get README.md contents</p></div>
</dd>
<dt id="pluginconf.setup.MetaUtils.name_to_fn"><code class="name flex">
<span>def <span class="ident">name_to_fn</span></span>(<span>name)</span>
</code></dt>
<dd>
<div class="desc"><p>find primary entry point.py from package name</p></div>
</dd>
</dl>
<h3>Methods</h3>
<dl>
<dt id="pluginconf.setup.MetaUtils.classifiers"><code class="name flex">
<span>def <span class="ident">classifiers</span></span>(<span>self)</span>
</code></dt>
<dd>
131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145







-
+







<dt id="pluginconf.setup.MetaUtils.install_requires"><code class="name flex">
<span>def <span class="ident">install_requires</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"><p>depends: python:module, pip:module</p></div>
</dd>
<dt id="pluginconf.setup.MetaUtils.plugin_doc"><code class="name flex">
<span>def <span class="ident">plugin_doc</span></span>(<span>self)</span>
<span>def <span class="ident">plugin_doc</span></span>(<span>self, prefix='long_')</span>
</code></dt>
<dd>
<div class="desc"><p>use comment block</p></div>
</dd>
<dt id="pluginconf.setup.MetaUtils.project_urls"><code class="name flex">
<span>def <span class="ident">project_urls</span></span>(<span>self, exclude=('url', 'update'))</span>
</code></dt>
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199

200

201
202
203
204
205
206
207
178
179
180
181
182
183
184


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207







-
-













+

+







<li><h3>Super-module</h3>
<ul>
<li><code><a title="pluginconf" href="index.html">pluginconf</a></code></li>
</ul>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="pluginconf.setup.get_readme" href="#pluginconf.setup.get_readme">get_readme</a></code></li>
<li><code><a title="pluginconf.setup.name_to_fn" href="#pluginconf.setup.name_to_fn">name_to_fn</a></code></li>
<li><code><a title="pluginconf.setup.setup" href="#pluginconf.setup.setup">setup</a></code></li>
</ul>
</li>
<li><h3><a href="#header-classes">Classes</a></h3>
<ul>
<li>
<h4><code><a title="pluginconf.setup.MetaUtils" href="#pluginconf.setup.MetaUtils">MetaUtils</a></code></h4>
<ul class="two-column">
<li><code><a title="pluginconf.setup.MetaUtils.classifiers" href="#pluginconf.setup.MetaUtils.classifiers">classifiers</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.datafiles_man" href="#pluginconf.setup.MetaUtils.datafiles_man">datafiles_man</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.entry_points" href="#pluginconf.setup.MetaUtils.entry_points">entry_points</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.extras_require" href="#pluginconf.setup.MetaUtils.extras_require">extras_require</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.get_keywords" href="#pluginconf.setup.MetaUtils.get_keywords">get_keywords</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.get_readme" href="#pluginconf.setup.MetaUtils.get_readme">get_readme</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.install_requires" href="#pluginconf.setup.MetaUtils.install_requires">install_requires</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.name_to_fn" href="#pluginconf.setup.MetaUtils.name_to_fn">name_to_fn</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.plugin_doc" href="#pluginconf.setup.MetaUtils.plugin_doc">plugin_doc</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.project_urls" href="#pluginconf.setup.MetaUtils.project_urls">project_urls</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.python_requires" href="#pluginconf.setup.MetaUtils.python_requires">python_requires</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.trove_license" href="#pluginconf.setup.MetaUtils.trove_license">trove_license</a></code></li>
<li><code><a title="pluginconf.setup.MetaUtils.trove_status" href="#pluginconf.setup.MetaUtils.trove_status">trove_status</a></code></li>
</ul>
</li>

Modified pluginconf/__init__.py from [7148596eca] to [295be38bfd].

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







# encoding: utf-8
# api: python
##type: extract
# category: config
# title: Plugin configuration
# description: Read meta data, pyz/package contents, module locating
# version: 0.8.0
# version: 0.8.1
# state: stable
# classifiers: documentation
# depends: python >= 2.7
# suggests: python:flit, python:PySimpleGUI
# license: PD
# priority: core
# api-docs: https://fossil.include-once.org/pluginspec/doc/trunk/html/index.html

Modified pluginconf/bind.py from [fcff8bd0e5] to [f6f6f09ee5].

167
168
169
170
171
172
173
174

175
176
177
178
179
180
181
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181







-
+







    | **Returns** | None   | -                             |

    Module should be a package, as in a directory and init `plugins/__init__.py`.
    Ideally this module was already imported in main. But parameter may be a string.

    This could be invoked multiple times for the package name to append further
    path= arguments (=./contrib/, =/usr/share/app/extenstions/, or a .pyz). Which
    is functionally identical to delcaring `__path__` in the `package/__init__.py`.
    is functionally identical to declaring `__path__` in the `package/__init__.py`.
    """

    # if supplied as string, instead of active module
    if isinstance(module, str):
        module = sys.modules.get(module) or __import__(module)

    # add to search list

Modified pluginconf/flit.py from [7e6be741f0] to [50d8d8a6ee].

151
152
153
154
155
156
157
158
159
160



161
162
163
164
165
166
167
168
169
151
152
153
154
155
156
157



158
159
160


161
162
163
164
165
166
167







-
-
-
+
+
+
-
-







        "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
    for docs in pmd.plugin_doc(prefix=""), pmd.get_readme(prefix=""):
        if docs["description"]:
            meta.update(docs)
                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))

Modified pluginconf/setup.py from [69618d8a4a] to [eeec59e038].

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
























87

88
89
90
91


92
93
94
95
96
97
98
50
51
52
53
54
55
56






















57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91


92
93
94
95
96
97
98
99
100







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+


-
-
+
+







import os
import re
import glob
import pprint
import pluginconf


def name_to_fn(name):
    """ find primary entry point.py from package name """
    for pfx in "", "src/", "src/"+name+"/":
        for sfx in ".py", "/__init__.py":
            if os.path.exists(pfx+name+sfx):
                return pfx+name+sfx
    return ""

def get_readme():
    """ get README.md contents """
    for filename, mime in ("README.md", "text/markdown"), ("README.rst", "text/x-rst"), ("README.txt", "text/plain"):
        if os.path.exists(filename):
            with open(filename, "r") as read:
                return {
                    "long_description": read.read(),
                    "long_description_content_type": mime,
                }
    return {
        "long_description": "",
        "long_description_content_type": "text/plain",
    }


class MetaUtils(dict):
    """ Convenience access to PMD fields and conversion functions """

    def __getattr__(self, name):
        """ dict into properties """
        return self.get(name, "")

    @staticmethod
    def name_to_fn(name):
        """ find primary entry point.py from package name """
        for pfx in "", "src/", "src/"+name+"/":
            for sfx in ".py", "/__init__.py":
                if os.path.exists(pfx+name+sfx):
                    return pfx+name+sfx
        return ""

    @staticmethod
    def get_readme(prefix="long_"):
        """ get README.md contents """
        for filename, mime in ("README.md", "text/markdown"), ("README.rst", "text/x-rst"), ("README.txt", "text/plain"):
            if os.path.exists(filename):
                with open(filename, "r") as read:
                    return {
                        prefix+"description": read.read(),
                        prefix+"description_content_type": mime,
                    }
        return {
            prefix+"description": "",
            prefix+"description_content_type": "text/plain",
        }

    def plugin_doc(self):
    def plugin_doc(self, prefix="long_"):
        """ use comment block """
        return {
            "long_description": self.doc,
            "long_description_content_type": self.doc_format or "text/plain"
            prefix+"description": self.doc,
            prefix+"description_content_type": self.doc_format or "text/plain"
        }

    def python_requires(self):
        """ depends: python >= 3.5 """
        deps = re.findall(r"python\s*\(?(>=?\s?[\d.]+)", self.get("depends", ""))
        if deps:
            return deps[0]
234
235
236
237
238
239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
236
237
238
239
240
241
242



243
244
245

246
247
248
249
250
251
252
253







-
-
-



-
+







        if not key in kwargs:
            kwargs[key] = val

    # package name
    if "name" not in kwargs and kwargs.get("packages"):
        kwargs["name"] = kwargs["packages"][0]

    # 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 filename= given
    if not filename and kwargs.get("name"):
        filename = name_to_fn(kwargs["name"])
        filename = MetaUtils.name_to_fn(kwargs["name"])

    # read plugin meta data (PMD)
    pmd = MetaUtils(
        pluginconf.plugin_meta(filename=filename)
    )

    # use id: if no name= still
268
269
270
271
272
273
274



275
276
277
278
279
280
281
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283







+
+
+







    if "depends" in pmd:
        kwargs["python_requires"] = pmd.python_requires()
    if "depends" in pmd and not kwargs["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())
    # read README if field empty or says `@README`
    if re.match("^$|^[@./]*README.{0,5}$", kwargs.get("long_description", "")):
        kwargs.update(pmd.get_readme())
    # doc:
    if not kwargs.get("long_description"):
        kwargs.update(pmd.plugin_doc())

    # keywords=
    if "keywords" not in kwargs:
        kwargs["keywords"] = pmd.get_keywords()