|
7 | 7 | from importlib.metadata import Distribution , distributions
|
8 | 8 | from pathlib import Path
|
9 | 9 |
|
| 10 | +# for package.ini safety belt |
| 11 | +from winpython.config import DATA_PATH |
| 12 | +import configparser as cp |
| 13 | + |
10 | 14 | def normalize(this):
|
11 | 15 | """apply https://peps.python.org/pep-0503/#normalized-names"""
|
12 | 16 | return re.sub(r"[-_.]+", "-", this).lower()
|
13 | 17 |
|
| 18 | +def get_packages_ini_metadata(name): |
| 19 | + """Extract infos (description, url) from the local database""" |
| 20 | + # we store only normalized names now (PEP 503) |
| 21 | + database= "packages.ini" |
| 22 | + db = cp.ConfigParser() |
| 23 | + try: |
| 24 | + db.read_file(open(str(Path(DATA_PATH) / database), encoding = 'utf-8')) |
| 25 | + except: |
| 26 | + db.read_file(open(str(Path(DATA_PATH) / database))) |
| 27 | + my_metadata = dict( |
| 28 | + description="", |
| 29 | + url="https://pypi.org/project/" + name, |
| 30 | + ) |
| 31 | + for key in my_metadata: |
| 32 | + # wheel replace '-' per '_' in key |
| 33 | + for name2 in (name, normalize(name)): |
| 34 | + try: |
| 35 | + my_metadata[key] = db.get(name2, key) |
| 36 | + break |
| 37 | + except (cp.NoSectionError, cp.NoOptionError): |
| 38 | + pass |
| 39 | + db_desc = my_metadata["description"] |
| 40 | + return my_metadata |
14 | 41 |
|
15 | 42 | class pipdata:
|
16 | 43 | """Wrapper around Distribution.discover() or pip inspect"""
|
@@ -91,7 +118,7 @@ def __init__(self, Target=None):
|
91 | 118 | self.distro[key] = {
|
92 | 119 | "name": name,
|
93 | 120 | "version": p.version,
|
94 |
| - "summary": meta["Summary"] if "Summary" in meta else "", |
| 121 | + "summary": meta["Summary"] if "Summary" in meta else get_packages_ini_metadata(key)["description"], |
95 | 122 | "requires_dist": requires,
|
96 | 123 | "wanted_per": [],
|
97 | 124 | "description": meta["Description"] if "Description" in meta else "",
|
|
0 commit comments