8000 Merge pull request #1333 from stonebig/master · winpython/winpython@cbbf6be · GitHub
[go: up one dir, main page]

Skip to content

Commit cbbf6be

Browse files
authored
Merge pull request #1333 from stonebig/master
push down to piptree the packages.ini handling
2 parents aaf207a + d991577 commit cbbf6be

File tree

2 files changed

+32
-44
lines changed

2 files changed

+32
-44
lines changed

winpython/piptree.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ def normalize(this):
1515
"""apply https://peps.python.org/pep-0503/#normalized-names"""
1616
return re.sub(r"[-_.]+", "-", this).lower()
1717

18-
def get_packages_ini_metadata(name):
18+
def get_package_metadata(database, name, gotoWWW=False, update=False, suggested_summary=None):
1919
"""Extract infos (description, url) from the local database"""
20+
# Note: we could use the PyPI database but this has been written on
21+
# machine which is not connected to the internet
2022
# we store only normalized names now (PEP 503)
21-
database= "packages.ini"
2223
db = cp.ConfigParser()
24+
filepath = Path(database) if Path(database).is_absolute() else Path(DATA_PATH) / database
2325
try:
24-
db.read_file(open(str(Path(DATA_PATH) / database), encoding = 'utf-8'))
26+
db.read_file(open(str(filepath), encoding = 'utf-8'))
2527
except:
26-
db.read_file(open(str(Path(DATA_PATH) / database)))
28+
db.read_file(open(str(filepath)))
2729
my_metadata = dict(
2830
description="",
2931
url="https://pypi.org/project/" + name,
@@ -36,9 +38,33 @@ def get_packages_ini_metadata(name):
3638
break
3739
except (cp.NoSectionError, cp.NoOptionError):
3840
pass
39-
db_desc = my_metadata["description"]
41+
db_desc = my_metadata.get("description")
42+
43+
if my_metadata.get("description") == "" and suggested_summary:
44+
# nothing in package.ini, we look in our installed packages
45+
try:
46+
my_metadata["description"] = (
47+
suggested_summary + "\n"
48+
).splitlines()[0]
49+
except:
50+
pass
51+
52+
if update == True and db_desc == "" and my_metadata["description"] != "":
53+
# we add new findings in our packgages.ini list, if it's required
54+
try:
55+
db[normalize(name)] = {}
56+
db[normalize(name)]["description"] = my_metadata["description"]
57+
with open(str(Path(DATA_PATH) / database), "w", encoding='UTF-8') as configfile:
58+
db.write(configfile)
59+
except:
60+
pass
4061
return my_metadata
4162

63+
64+
def get_packages_ini_metadata(name):
65+
"""Extract infos (description, url) from the local database"""
66+
return get_package_metadata("packages.ini", name, False, update=False, suggested_summary=None)
67+
4268
class pipdata:
4369
"""Wrapper around Distribution.discover() or pip inspect"""
4470

winpython/wppm.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,45 +54,7 @@ def get_package_metadata(database, name, gotoWWW=False, update=False):
5454
# Note: we could use the PyPI database but this has been written on
5555
# machine which is not connected to the internet
5656
# we store only normalized names now (PEP 503)
57-
db = cp.ConfigParser()
58-
try:
59-
db.read_file(open(str(Path(DATA_PATH) / database), encoding = 'utf-8'))
60-
except:
61-
db.read_file(open(str(Path(DATA_PATH) / database)))
62-
my_metadata = dict(
63-
description="",
64-
url="https://pypi.org/project/" + name,
65-
)
66-
for key in my_metadata:
67-
# wheel replace '-' per '_' in key
68-
for name2 in (name, normalize(name)):
69-
try:
70-
my_metadata[key] = db.get(name2, key)
71-
break
72-
except (cp.NoSectionError, cp.NoOptionError):
73-
pass
74-
db_desc = my_metadata.get("description")
75-
76-
if my_metadata.get("description") == "" and metadata:
77-
# nothing in package.ini, we look in our installed packages
78-
try:
79-
my_metadata["description"] = (
80-
metadata(name)["Summary"] + "\n"
81-
).splitlines()[0]
82-
except:
83-
pass
84-
85-
if update == True and db_desc == "" and my_metadata["description"] != "":
86-
# we add new findings in our packgages.ini list, if it's required
87-
try:
88-
db[normalize(name)] = {}
89-
db[normalize(name)]["description"] = my_metadata["description"]
90-
with open(str(Path(DATA_PATH) / database), "w", encoding='UTF-8') as configfile:
91-
db.write(configfile)
92-
except:
93-
pass
94-
return my_metadata
95-
57+
return piptree.get_package_metadata(database, name, gotoWWW, update)
9658

9759
class BasePackage(object):
9860
def __init__(self, fname):

0 commit comments

Comments
 (0)
0