Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b989bae

Browse filesBrowse files
committed
ENH: respect exclude_dirs and exclude_files in editable installs
Add support for the exclude_dirs and exclude_files arguments of install_subdir() Meson function. Extend editable install tests to cover this functionality and a more complex package layout.
1 parent 8ace029 commit b989bae
Copy full SHA for b989bae

File tree

3 files changed

+56
-21
lines changed
Filter options

3 files changed

+56
-21
lines changed

‎mesonpy/_editable.py

Copy file name to clipboardExpand all lines: mesonpy/_editable.py
+19-9Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,21 @@ def get(self, key: Union[str, Tuple[str, ...]]) -> Optional[Union[Node, str]]:
222222
return dict.get(node, key)
223223

224224

225-
def walk(root: str, path: str = '') -> Iterator[pathlib.Path]:
226-
with os.scandir(os.path.join(root, path)) as entries:
227-
for entry in entries:
228-
if entry.is_dir():
229-
yield from walk(root, os.path.join(path, entry.name))
230-
else:
231-
yield pathlib.Path(path, entry.name)
225+
def walk(src: str, exclude_files: Set[str], exclude_dirs: Set[str]) -> Iterator[str]:
226+
for root, dirnames, filenames in os.walk(src):
227+
for name in dirnames.copy():
228+
dirsrc = os.path.join(root, name)
229+
relpath = os.path.relpath(dirsrc, src)
230+
if relpath in exclude_dirs:
231+
dirnames.remove(name)
232+
# sort to process directories determninistically
233+
dirnames.sort()
234+
for name in sorted(filenames):
235+
filesrc = os.path.join(root, name)
236+
relpath = os.path.relpath(filesrc, src)
237+
if relpath in exclude_files:
238+
continue
239+
yield relpath
232240

233241

234242
def collect(install_plan: Dict[str, Dict[str, Any]]) -> Node:
@@ -238,8 +246,10 @@ def collect(install_plan: Dict[str, Dict[str, Any]]) -> Node:
238246
path = pathlib.Path(target['destination'])
239247
if path.parts[0] in {'{py_platlib}', '{py_purelib}'}:
240248
if key == 'install_subdirs' and os.path.isdir(src):
241-
for entry in walk(src):
242-
tree[(*path.parts[1:], *entry.parts)] = os.path.join(src, *entry.parts)
249+
exclude_files = {os.path.normpath(x) for x in target.get('exclude_files', [])}
250+
exclude_dirs = {os.path.normpath(x) for x in target.get('exclude_dirs', [])}
251+
for entry in walk(src, exclude_files, exclude_dirs):
252+
tree[(*path.parts[1:], *entry.split(os.sep))] = os.path.join(src, entry)
243253
else:
244254
tree[path.parts[1:]] = src
245255
return tree

‎tests/packages/complex/meson.build

Copy file name to clipboardExpand all lines: tests/packages/complex/meson.build
+31-8Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,36 @@ endif
1515

1616
py = import('python').find_installation()
1717

18-
py.install_sources('move.py', subdir: 'complex/more', pure: false)
19-
20-
install_data('foo.py', rename: 'bar.py', install_dir: py.get_install_dir(pure: false) / 'complex')
21-
22-
install_subdir('complex', install_dir: py.get_install_dir(pure: false))
23-
24-
py.extension_module('test', 'test.pyx', install: true, subdir: 'complex')
25-
py.extension_module('baz', 'complex/more/baz.pyx', install: true, subdir: 'complex/more')
18+
py.install_sources(
19+
'move.py',
20+
subdir: 'complex/more',
21+
pure: false,
22+
)
23+
24+
install_data(
25+
'foo.py',
26+
rename: 'bar.py',
27+
install_dir: py.get_install_dir(pure: false) / 'complex',
28+
)
29+
30+
install_subdir(
31+
'complex',
32+
install_dir: py.get_install_dir(pure: false),
33+
exclude_files: ['more/meson.build', 'more/baz.pyx'],
34+
)
35+
36+
py.extension_module(
37+
'test',
38+
'test.pyx',
39+
install: true,
40+
subdir: 'complex',
41+
)
42+
43+
py.extension_module(
44+
'baz',
45+
'complex/more/baz.pyx',
46+
install: true,
47+
subdir: 'complex/more',
48+
)
2649

2750
subdir('complex/more')

‎tests/test_editable.py

Copy file name to clipboardExpand all lines: tests/test_editable.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818

1919
def test_walk(package_complex):
20-
entries = set(_editable.walk(os.fspath(package_complex / 'complex')))
21-
assert entries == {
20+
entries = _editable.walk(
21+
os.fspath(package_complex / 'complex'),
22+
[os.path.normpath('more/meson.build'), os.path.normpath('more/baz.pyx')],
23+
['namespace'],
24+
)
25+
assert {pathlib.Path(x) for x in entries} == {
2226
pathlib.Path('__init__.py'),
2327
pathlib.Path('more/__init__.py'),
24-
pathlib.Path('namespace/bar.py'),
25-
pathlib.Path('namespace/foo.py')
2628
}
2729

2830

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.