24
25
26
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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
| # #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.
#
import sys
import re
import functools
import pluginconf
import pluginconf.setup as psetup
import flit_core.common
#-- patchy patch
def inject(where):
def wrapped(func):
setattr(where, func.__name__, func)
return wrapped
@inject(flit_core.common)
def read_flit_config(path):
""" read_flit_config() with preset dynamic fields """
d = tomllib.loads(path.read_text('utf-8'))
# make fields dynamic
if not "dynamic" in d["project"]:
d["project"]["dynamic"] = []
for dyn in ['description', 'version']:
if dyn in d["project"]:
del d["project"][dyn]
if not dyn in d["project"]["dynamic"]:
d["project"]["dynamic"].append(dyn)
print(d)
# turn it into LoadedConfig
return prep_toml_config(d, path)
# override make_metadata
@inject(flit_core.common)
def make_metadata(module, ini_info):
meta = {
"name": module.name,
"provides": [module.name]
}
meta.update(ini_info.metadata)
meta.update(
pmd_meta(
pluginconf.plugin_meta(filename=module.file),
ini_info
)
)
return flit_core.common.Metadata(meta)
# map plugin meta to flit Metadata
def pmd_meta(pmd, ini):
""" enjoin PMD fields with flit meta data """
meta = dict(
summary = pmd.get("description"),
version = pmd.get("version"),
home_page = pmd.get("url"),
author = pmd.get("author"), # should split this into mail and name
author_email = None,
maintainer = None,
maintainer_email = None,
license = pmd.get("license"),
keywords = psetup._keywords(pmd),
download_url = None,
requires_python = psetup._python_requires(pmd).get("python_requires", ">= 2.7"),
platform = pmd.get("architecture"),
supported_platform = (),
classifiers = list(psetup._classifiers(pmd))
+ psetup._trove_license(pmd)
+ psetup._trove_status(pmd),
provides = (),
requires = psetup._install_requires(pmd).get("install_requires") or (),
obsoletes = (),
project_urls = [f"{k}, {v}" for k,v in psetup._project_urls(pmd).items()],
provides_dist = (),
requires_dist = psetup._install_requires(pmd).get("install_requires") or (),
obsoletes_dist = (),
requires_external = (),
provides_extra = (),
)
# comment/readme
for docs in psetup._plugin_doc(pmd), psetup._get_readme():
if docs["long_description"]:
meta.update({
k[5:]: v for k,v in docs.items()
})
# entry_points are in ini file
for section, entries in psetup._entry_points(pmd).items():
ini.entrypoints[section] = ini.entrypoints.get(section, {})
for e in entries:
ini.entrypoints[section].update(
dict(re.findall("(.+)=(.+)", e))
)
print(ini.entrypoints)
# strip empty entries
return {k: v for k, v in meta.items() if v}
#-- buildapi
from flit_core.buildapi import ( # These have to be late imports; else they'll
|
>
>
>
>
>
>
<
>
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
<
|
|
|
|
|
|
|
|
|
<
>
>
|
|
|
|
|
|
|
| 25
26
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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
| # #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.
#
""" monkeypatches flint to use pluginconf sources for packaging """
import sys
import re
import functools
import flit_core.common
import flit_core.config
import pluginconf
import pluginconf.setup as psetup
#-- patchy patch
def inject(where):
""" monkeypatch into module """
def wrapped(func):
setattr(where, func.__name__, func)
return wrapped
@inject(flit_core.config)
def read_flit_config(path):
""" read_flit_config() with preset 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"] = []
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
@inject(flit_core.common)
def make_metadata(module, ini_info):
""" different order, and obviously sources """
meta = {
"name": module.name,
"provides": [module.name]
}
meta.update(ini_info.metadata)
meta.update(
pmd_meta(
pluginconf.plugin_meta(filename=module.file),
ini_info
)
)
if not meta.get("version"):
meta.update(
flit_core.common.get_info_from_module(module.file, ['version'])
)
return flit_core.common.Metadata(meta)
# map plugin meta to flit Metadata
def pmd_meta(pmd, ini):
""" enjoin PMD fields with flit meta data """
pmd = psetup.MetaUtils(pmd)
meta = {
"summary": pmd.description,
"version": pmd.version,
"home_page": pmd.url,
"author": pmd.author, # should split this into mail and name
"author_email": None,
"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": (),
"classifiers": list(pmd.classifiers()) + pmd.trove_license() + pmd.trove_status(),
"provides": (),
"requires": pmd.install_requires().get("install_requires") or (),
"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)
# 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()
})
# 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)
# strip empty entries
return {k: v for k, v in meta.items() if v}
#-- buildapi
from flit_core.buildapi import ( # These have to be late imports; else they'll
|