Skip to content

Commit 04eb5b2

Browse files
committed
optimize_upip.py: Rework inclusion/exclusion logic.
We should include files by default, as a package may contain arbitrary files, e.g. as resources. So, rework inclusion/exlusion logic to work using incremental refinement.
1 parent e8e531b commit 04eb5b2

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

optimize_upip.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ def recompress_latest(dir):
4949
recompress(latest)
5050

5151

52-
EXCLUDE = [r".+/setup.py"]
53-
INCLUDE = [r".+\.py", r".+\.egg-info/(PKG-INFO|requires\.txt)"]
52+
FILTERS = [
53+
# include, exclude, repeat
54+
(r".+\.egg-info/(PKG-INFO|requires\.txt)", r"setup.py$"),
55+
(r".+\.py$", r"[^/]+$"),
56+
(None, r".+\.egg-info/.+"),
57+
]
5458

5559

5660
outbuf = io.BytesIO()
@@ -60,18 +64,29 @@ def filter_tar(name):
6064
fout = tarfile.open(fileobj=outbuf, mode="w")
6165
for info in fin:
6266
# print(info)
67+
if not "/" in info.name:
68+
continue
69+
fname = info.name.split("/", 1)[1]
6370
include = None
64-
for p in EXCLUDE:
65-
if re.match(p, info.name):
66-
include = False
67-
break
68-
if include is None:
69-
for p in INCLUDE:
70-
if re.match(p, info.name):
71+
72+
for inc_re, exc_re in FILTERS:
73+
if include is None and inc_re:
74+
if re.match(inc_re, fname):
7175
include = True
72-
print("Including:", info.name)
73-
if not include:
76+
77+
if include is None and exc_re:
78+
if re.match(exc_re, fname):
79+
include = False
80+
81+
if include is None:
82+
include = True
83+
84+
if include:
85+
print("Including:", fname)
86+
else:
87+
print("Excluding:", fname)
7488
continue
89+
7590
farch = fin.extractfile(info)
7691
fout.addfile(info, farch)
7792
fout.close()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy