Skip to content

Commit

Permalink
ENH: make the editable install build directory more discoverable
Browse files Browse the repository at this point in the history
Change the editable install build directory to a subdirectory named
after the ABI tag for the target Python interpreter placed in the
``build`` directory in the project source directory.

Add .gitignode and .hgignore files with catch all glob patterns to the
``build`` directory, if it is empty, to have the major VCS systems
ignore it.

Fixes #370, #380.
  • Loading branch information
dnicolodi authored and rgommers committed Apr 12, 2023
1 parent a9c3e0b commit eacd23a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,18 @@ def _check_meson_version(*, version: str = _MESON_REQUIRED_VERSION) -> None:
raise ConfigError(f'Could not find meson version {version} or newer, found {meson_version}.')


def _add_ignore_files(directory: pathlib.Path) -> None:
directory.joinpath('.gitignore').write_text(textwrap.dedent('''
# This file is generated by meson-python. It will not be recreated if deleted or modified.
*
'''), encoding='utf-8')
directory.joinpath('.hgignore').write_text(textwrap.dedent('''
# This file is generated by meson-python. It will not be recreated if deleted or modified.
syntax: glob
**/*
'''), encoding='utf-8')


def _pyproject_hook(func: Callable[P, T]) -> Callable[P, T]:
@functools.wraps(func)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
Expand Down Expand Up @@ -1111,7 +1123,11 @@ def build_editable(
if not config_settings:
config_settings = {}
if 'builddir' not in config_settings:
config_settings['builddir'] = os.path.join('.mesonpy', 'editable', 'build')
builddir = pathlib.Path('build')
builddir.mkdir(exist_ok=True)
if not next(builddir.iterdir(), None):
_add_ignore_files(builddir)
config_settings['builddir'] = os.fspath(builddir / str(mesonpy._tags.get_abi_tag()))

out = pathlib.Path(wheel_directory)
with _project(config_settings) as project:
Expand Down

0 comments on commit eacd23a

Please sign in to comment.