Skip to content

Commit c95da87

Browse files
dnicolodirgommers
authored andcommitted
ENH: rename the buildir config setting to build-dir
The old name is still accepted for backward compatibility. Fixes #275.
1 parent d838772 commit c95da87

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

docs/how-to-guides/build-directory.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Use a permanent build directory
1111

1212
.. todo::
1313

14-
- Explain why you'd want to use the ``builddir`` option
14+
- Explain why you'd want to use the ``build-dir`` option
1515
- Mention it works properly when using ``--cross-file`` (eg. https://github.com/scipy/scipy/blob/1c836efe5ff37ffa4490756269b060a464690e62/.github/workflows/wheels.yml#L180-L188)
16-
- Explain how ``builddir`` works
16+
- Explain how ``build-dir`` works
1717
- Warn that user-configured build directories are "use at your own risk"
1818
- Warn that ``meson-python`` version mismatches in the build directory can
1919
cause trouble

docs/how-to-guides/debug-builds.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ We can do all that with the following ``pip`` invocation:
2323
2424
$ pip install -e . --no-build-isolation \
2525
-Csetup-args=-Dbuildtype=debug \
26-
-Cbuilddir=build-dbg
26+
-Cbuild-dir=build-dbg
2727
2828
This debug build of your package will work with either a regular or debug build
2929
of your Python interpreter. A debug Python interpreter isn't necessary, but may

docs/how-to-guides/editable-installs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ to install the same project in editable mode for multiple interpreters
105105
with different ABIs.
106106

107107
An alternative build directory can be specified using the
108-
:option:`builddir` config setting.
108+
:option:`build-dir` config setting.
109109

110110

111111
.. _how-to-guides-editable-installs-verbose:

docs/reference/config-settings.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ settings you can pass when building the project. Please refer to the
1414
:ref:`how-to-guides-meson-args` guides for information on how to use
1515
them.
1616

17-
.. option:: builddir
17+
.. option:: build-dir
1818

19-
By default ``meson-python`` uses a temporary builds directory.
19+
By default ``meson-python`` uses a temporary build directory.
2020
This settings allows to select the Meson build directory and
2121
prevents it to be deleted when ``meson-python`` terminates. If the
2222
directory does not exists, it will be created. If the directory
@@ -27,6 +27,9 @@ them.
2727
``meson-python``. This avoids having to rebuild the whole project
2828
when testing changes during development.
2929

30+
For backward comaptibility reasons, the alternative ``builddir``
31+
spelling is also accepted.
32+
3033
.. option:: dist-args
3134

3235
Extra arguments to be passed to the ``meson dist`` command.

mesonpy/__init__.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ def _string_or_strings(value: Any, name: str) -> List[str]:
583583

584584
options = {
585585
'builddir': _string,
586+
'build-dir': _string,
586587
'editable-verbose': _bool,
587588
'dist-args': _string_or_strings,
588589
'setup-args': _string_or_strings,
@@ -602,6 +603,17 @@ def _string_or_strings(value: Any, name: str) -> List[str]:
602603
else:
603604
raise ConfigError(f'Unknown option "{key}"')
604605
config[key] = parser(value, key)
606+
607+
# Check backward compatibility aliases.
608+
aliases = {
609+
'build-dir': 'builddir',
610+
}
611+
for key, alt in aliases.items():
612+
if key in config and alt in config:
613+
raise ConfigError(f'Option "{alt}" is a backward compatibility alias for "{key}". Only one can be used')
614+
if alt in config:
615+
config[key] = config[alt]
616+
605617
return config
606618

607619

@@ -942,7 +954,7 @@ def _project(config_settings: Optional[Dict[Any, Any]] = None) -> Iterator[Proje
942954
settings = _validate_config_settings(config_settings or {})
943955
meson_args = typing.cast(MesonArgs, {name: settings.get(f'{name}-args', []) for name in _MESON_ARGS_KEYS})
944956
source_dir = os.path.curdir
945-
build_dir = settings.get('builddir')
957+
build_dir = settings.get('build-dir')
946958
editable_verbose = bool(settings.get('editable-verbose'))
947959

948960
with contextlib.ExitStack() as ctx:
@@ -1081,15 +1093,15 @@ def build_editable(
10811093
) -> str:
10821094
_setup_cli()
10831095

1084-
# force set a permanent builddir
1096+
# Force set a permanent build directory.
10851097
if not config_settings:
10861098
config_settings = {}
1087-
if 'builddir' not in config_settings:
1088-
builddir = pathlib.Path('build')
1089-
builddir.mkdir(exist_ok=True)
1090-
if not next(builddir.iterdir(), None):
1091-
_add_ignore_files(builddir)
1092-
config_settings['builddir'] = os.fspath(builddir / str(mesonpy._tags.get_abi_tag()))
1099+
if 'build-dir' not in config_settings and 'builddir' not in config_settings:
1100+
build_dir = pathlib.Path('build')
1101+
build_dir.mkdir(exist_ok=True)
1102+
if not next(build_dir.iterdir(), None):
1103+
_add_ignore_files(build_dir)
1104+
config_settings['build-dir'] = os.fspath(build_dir / str(mesonpy._tags.get_abi_tag()))
10931105

10941106
out = pathlib.Path(wheel_directory)
10951107
with _project(config_settings) as project:

0 commit comments

Comments
 (0)