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()
|