Skip to content

Commit 4eddbbe

Browse files
Filtering: Include everything by default (#98)
Co-authored-by: Thorsten Beier <[email protected]>
1 parent 12a64fc commit 4eddbbe

File tree

9 files changed

+72
-247
lines changed

9 files changed

+72
-247
lines changed

.github/workflows/lint.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ jobs:
1919
with:
2020
fetch-depth: 0
2121

22-
- name: Install mamba and dependencies
23-
uses: mamba-org/provision-with-micromamba@main
22+
- uses: mamba-org/setup-micromamba@v1
2423
with:
2524
environment-file: ci_env.yml
26-
environment-name: ci-env
27-
micromamba-version: '1.4.1'
25+
cache-environment: true
26+
2827

2928
- name: Lint check
3029
shell: bash -l {0}

.github/workflows/workflow.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ jobs:
2828
with:
2929
fetch-depth: 0
3030

31-
- name: Install mamba and dependencies
32-
uses: mamba-org/provision-with-micromamba@main
31+
- uses: mamba-org/setup-micromamba@v1
3332
with:
3433
environment-file: ci_env.yml
35-
environment-name: ci-env
36-
micromamba-version: '1.4.1'
34+
cache-environment: true
3735

3836
- name: Install empack
3937
shell: bash -l {0}

config/empack_config.yaml

Lines changed: 29 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -1,183 +1,39 @@
11
packages:
22
setuptools:
3-
include_patterns:
4-
- pattern: '**/pkg_resources/*.so'
5-
- pattern: '**/pkg_resources/**/*.so'
6-
- pattern: '**/pkg_resources/*.py'
7-
- pattern: '**/pkg_resources/**/*.py'
8-
- pattern: '**/*.dist-info/METADATA'
9-
bokeh:
10-
include_patterns:
11-
- pattern: '*.so'
12-
- pattern: '*.py'
13-
- pattern: '**/bokeh/**/*.html'
14-
- pattern: '**/bokeh/**/*.js'
15-
- pattern: '**/bokeh/*.json'
16-
- pattern: '**/*.dist-info/METADATA'
173
exclude_patterns:
18-
- pattern: '**/tests/**/*.py'
19-
- pattern: '**/tests/**/*.so'
20-
plotly:
21-
include_patterns:
22-
- pattern: '*.so'
23-
- pattern: '*.py'
24-
- pattern: '**/plotly/package_data/**'
25-
- pattern: '**/*.dist-info/METADATA'
26-
exclude_patterns:
27-
- pattern: '**/tests/**/*.py'
28-
- pattern: '**/tests/**/*.so'
29-
folium:
30-
include_patterns:
31-
- pattern: '*.so'
32-
- pattern: '*.py'
33-
- pattern: '*.json'
34-
- pattern: '**/folium/templates/**'
35-
- pattern: '**/*.dist-info/METADATA'
36-
exclude_patterns:
37-
- pattern: '**/tests/**/*.py'
38-
- pattern: '**/tests/**/*.so'
39-
branca:
40-
include_patterns:
41-
- pattern: '*.so'
42-
- pattern: '*.py'
43-
- pattern: '*.json'
44-
- pattern: '**/branca/templates/**'
45-
- pattern: '**/*.dist-info/METADATA'
46-
exclude_patterns:
47-
- pattern: '**/tests/**/*.py'
48-
- pattern: '**/tests/**/*.so'
49-
python-dateutil:
50-
include_patterns:
51-
- pattern: '*.so'
52-
- pattern: '*.py'
53-
- pattern: '*.json'
54-
- pattern: '*dateutil-zoneinfo.tar.gz'
55-
- pattern: '**/*.dist-info/METADATA'
56-
exclude_patterns:
57-
- pattern: '**/tests/**/*.py'
58-
- pattern: '**/tests/**/*.so'
59-
# For matplotlib <3.5.2 which didn't have matplotlib-base published
60-
matplotlib:
61-
include_patterns:
62-
- pattern: '*.so'
63-
- pattern: '*.py'
64-
- pattern: '*.json'
65-
- pattern: '**/matplotlib/mpl-data/**'
66-
- pattern: '**/*.dist-info/METADATA'
67-
exclude_patterns:
68-
- pattern: '**/tests/**/*.py'
69-
- pattern: '**/tests/**/*.so'
70-
matplotlib-base:
71-
include_patterns:
72-
- pattern: '*.so'
73-
- pattern: '*.py'
74-
- pattern: '*.json'
75-
- pattern: '**/matplotlib/mpl-data/**'
76-
- pattern: '**/*.dist-info/METADATA'
77-
exclude_patterns:
78-
- pattern: '**/tests/**/*.py'
79-
- pattern: '**/tests/**/*.so'
80-
scikit-learn:
81-
include_patterns:
82-
- pattern: '*.so'
83-
- pattern: '*.py'
84-
- pattern: '*.json'
85-
- pattern: '**/sklearn/datasets/**'
86-
- pattern: '**/*.dist-info/METADATA'
87-
exclude_patterns:
88-
- pattern: '**/tests/**/*.py'
89-
- pattern: '**/tests/**/*.so'
90-
scikit-image:
91-
include_patterns:
92-
- pattern: '*.txt'
93-
- pattern: '*.so'
94-
- pattern: '*.py'
95-
- pattern: '*.json'
96-
- pattern: '**/skimage/data/**'
97-
- pattern: '**/skimage/io/_plugins/*.ini'
98-
- pattern: '**/*.dist-info/METADATA'
99-
exclude_patterns:
100-
- pattern: '**/tests/**/*.py'
101-
- pattern: '**/tests/**/*.so'
102-
xarray:
103-
include_patterns:
104-
- pattern: '**/*.py'
105-
- pattern: '**/static/css/*.css'
106-
- pattern: '**/static/html/*.html'
107-
- pattern: '**/*.dist-info/METADATA'
4+
- pattern: '**/_distutils_hack/**'
5+
- pattern: '**/distutils-precedence.pth'
6+
- pattern: '**/setuptools/**'
7+
- pattern: '**/pkg_resources/_vendor/**'
8+
zlib:
1089
exclude_patterns:
109-
- pattern: '**/tests/**/*.py'
10+
- pattern: '**/so'
11011
widgetsnbextension:
11112
exclude_patterns:
11213
- pattern: '**'
113-
python:
114-
include_patterns:
115-
- pattern: '*.so'
116-
- pattern: '*.py'
117-
- pattern: '*.json'
118-
- pattern: 'share/zoneinfo/**'
119-
- pattern: '**/*.dist-info/METADATA'
120-
exclude_patterns:
121-
- pattern: '**/tests/**/*.py'
122-
- pattern: '**/tests/**/*.so'
123-
- pattern: '**/tests/*.py'
124-
- pattern: '**/tests/*.so'
125-
python-tzdata:
126-
include_patterns:
127-
- pattern: '*.so'
128-
- pattern: '*.py'
129-
- pattern: '*.json'
130-
- pattern: 'share/zoneinfo/**'
131-
- pattern: '**/tzdata/zoneinfo/**'
132-
- pattern: '**/*.dist-info/METADATA'
133-
exclude_patterns:
134-
- pattern: '**/tests/**/*.py'
135-
- pattern: '**/tests/**/*.so'
136-
- pattern: '**/tests/*.py'
137-
- pattern: '**/tests/*.so'
138-
- pattern: '**/tzdata/zoneinfo/**/*.pyc'
139-
zlib:
140-
exclude_patterns:
141-
- pattern: '**/so'
142-
itables:
143-
include_patterns:
144-
- pattern: '*.py'
145-
- pattern: 'html/**'
146-
- pattern: 'external/**'
147-
- pattern: '**/*.dist-info/METADATA'
148-
urllib3:
149-
include_patterns:
150-
- pattern: '*.py'
151-
- pattern: '**/contrib/emscripten/emscripten_fetch_worker.js'
152-
certifi:
153-
include_patterns:
154-
- pattern: '*.py'
155-
- pattern: '*.pem'
156-
pyvis:
157-
include_patterns:
158-
- pattern: '*.py'
159-
- pattern: '*.html'
160-
pint:
161-
include_patterns:
162-
- pattern: '*.so'
163-
- pattern: '*.py'
164-
- pattern: '*.txt'
165-
exclude_patterns:
166-
- pattern: '**/tests/**/*.py'
167-
- pattern: '**/tests/**/*.so'
16814
default:
169-
include_patterns:
170-
- pattern: '*.so'
171-
- pattern: '*.py'
172-
- pattern: '*.json'
173-
- pattern: 'share/zoneinfo/**'
174-
- pattern: '**/*.dist-info/METADATA'
17515
exclude_patterns:
176-
- pattern: '**/tests/**/*.py'
177-
- pattern: '**/tests/**/*.so'
178-
- pattern: '**/tests/*.py'
179-
- pattern: '**/tests/*.so'
180-
- pattern: 'share/jupyter/nbextensions/**/*'
181-
- pattern: 'share/jupyter/labextensions/**/*'
182-
- pattern: 'etc/jupyter/nbconfig/**/*'
16+
- pattern: 'include/**'
17+
- pattern: '**/include/**'
18+
- pattern: 'bin/**'
19+
- pattern: '**/bin/**'
20+
- pattern: 'tests/**'
21+
- pattern: '**/tests/**'
22+
- pattern: '**/*.ini'
23+
- pattern: '**/*.exe'
24+
- pattern: '**/*.a'
25+
- pattern: '**/*.c'
26+
- pattern: '**/*.pxd'
27+
- pattern: '**/*.pyi'
28+
- pattern: '**/*.pyx'
29+
- pattern: '**/*.pyc'
30+
- pattern: '**/*.typed'
31+
- pattern: '**/*.egg-info'
32+
- pattern: '**/site-packages/pip/_vendor/**'
33+
- pattern: '**/idlelib/**'
34+
- pattern: '**/ensurepip/**'
18335
- pattern: 'Scripts/*'
36+
# Excluding jupyter front-end and server extensions
37+
- pattern: 'share/jupyter/nbextensions/**'
38+
- pattern: 'share/jupyter/labextensions/**'
39+
- pattern: 'etc/jupyter/nbconfig/**'

empack/file_patterns.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def match(self, path):
2121

2222

2323
class FileFilter:
24-
def __init__(self, include_patterns=None, exclude_patterns=None):
24+
def __init__(self, exclude_patterns=None):
2525
def patter_from_dict(**d):
2626
if "pattern" in d:
2727
return UnixPattern(**d)
@@ -30,33 +30,31 @@ def patter_from_dict(**d):
3030
else:
3131
raise ValueError("pattern or regex must be provided")
3232

33-
if include_patterns is None:
34-
include_patterns = []
3533
if exclude_patterns is None:
3634
exclude_patterns = []
37-
self.include_patterns = [patter_from_dict(**p) for p in include_patterns]
3835
self.exclude_patterns = [patter_from_dict(**p) for p in exclude_patterns]
3936

4037
def match(self, path):
41-
include = False
42-
for ip in self.include_patterns:
43-
if ip.match(path):
44-
include = True
45-
if include:
46-
for ep in self.exclude_patterns:
47-
if ep.match(path):
48-
return False
49-
return include
38+
return all(not ep.match(path) for ep in self.exclude_patterns)
5039

5140

5241
class PkgFileFilter:
53-
def __init__(self, packages, default=None):
42+
def __init__(self, packages=None, default=None):
5443
self.packages = {}
44+
45+
if packages is None:
46+
packages = {}
47+
48+
default_exclude_patterns = []
49+
if default is not None and "exclude_patterns" in default:
50+
default_exclude_patterns = default["exclude_patterns"]
51+
5552
for k, v in packages.items():
5653
if isinstance(v, dict):
57-
self.packages[k] = FileFilter(**v)
58-
elif isinstance(v, list):
59-
self.packages[k] = [FileFilter(**x) for x in v]
54+
exclude_patterns = default_exclude_patterns
55+
if "exclude_patterns" in v:
56+
exclude_patterns = exclude_patterns + v["exclude_patterns"]
57+
self.packages[k] = FileFilter(exclude_patterns=exclude_patterns)
6058
else:
6159
err = f"invalid value for package {k}: {v}"
6260
raise ValueError(err)

empack/filter_env.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,18 @@ def filter_pkg(env_prefix, pkg_meta, target_dir, matchers):
9292
for _i, matcher in enumerate(matchers):
9393
include = matcher.match(path=file)
9494
if include:
95-
included.append(file)
9695
path = env_path / file
9796
if path.is_symlink() and not path.exists():
9897
continue
9998

10099
dest_fpath = os.path.join(target_dir, file)
101100
os.makedirs(os.path.dirname(dest_fpath), exist_ok=True)
102-
shutil.copy(os.path.join(env_prefix, file), dest_fpath)
101+
try:
102+
shutil.copy(os.path.join(env_prefix, file), dest_fpath)
103+
included.append(file)
104+
except FileNotFoundError:
105+
# This may happen when following a symlink on a filtered out file
106+
pass
103107
break
104108
path = write_minimal_conda_meta(pkg_meta=pkg_meta, env_prefix=target_dir)
105109
included.append(path.relative_to(target_dir))

tests/empack_test_config.yaml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
1-
packages:
2-
python-dateutil:
3-
include_patterns:
4-
- regex: '^(?!.*\/tests\/).*(.*.\.py$)|(.*.\.so$)|(.*dateutil-zoneinfo\.tar\.gz$)'
5-
matplotlib:
6-
include_patterns:
7-
- regex: '^(?!.*\/tests\/).*(.*.\.py$)|(.*.\.so$)'
8-
- pattern: "*matplotlibrc"
9-
10-
scikit-learn:
11-
include_patterns:
12-
- regex: '^(?!.*\/tests\/).*(.*.\.py$)|(.*.\.so$)'
13-
- pattern: "**/sklearn/datasets/**"
14-
15-
scikit-image:
16-
include_patterns:
17-
- regex: '^(?!.*\/tests\/).*(.*.\.py$)|(.*.\.so$)'
18-
- pattern: "**/skimage/data/**"
19-
20-
211
default:
22-
include_patterns:
23-
- pattern: '*.so'
24-
- pattern: '*.py'
252
exclude_patterns:
3+
- pattern: '**/*.pyc'
264
- pattern: '**/tests/**/*.py'
275
- pattern: '**/tests/**/*.so'
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
packages:
22
scikit-image:
33
exclude_patterns:
4-
- pattern: '**'
4+
- pattern: '**/bar.py'
5+
- pattern: '**/bar.so'
56

6-
7-
scipy:
8-
- include_patterns:
9-
- pattern: '**/core'
10-
- include_patterns:
11-
- pattern: '**/sparse'
12-
- include_patterns:
13-
- pattern: '**'
7+
default:
8+
exclude_patterns:
9+
- pattern: '**/*.pyc'
10+
- pattern: '**/tests/**/*.py'
11+
- pattern: '**/tests/**/*.so'

0 commit comments

Comments
 (0)