-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: remove fallback needed only with now unsupported Meson versions #280
Conversation
3577f43
to
4031d7c
Compare
Thanks @dnicolodi. I'm a little nervous about this one, because we've had so many problems with this logic before. I think all Meson issues are fixed indeed. However, it's hard for me to verify that we definitely won't need this fallback code anymore. IIRC this was a problematic case that we may not have a test for: custom_target('file_with_random_extension',
input : ['codegen.c.in'],
output : ['codegen.c'],
command : [custom_script, '@INPUT@', '@OUTPUT@'],
install : true, # still needed because of meson#7372 - can't pass generated targets to py.install_sources
install_dir : py.get_install_dir() / 'pkgname' / 'submod' # this may work now, not sure if that covers everything Or are we sure that by design there is no way to hit that heuristics code path anymore? |
I just verified that the case above works correctly. |
I tested this PR with SciPy, and all works as expected for a regular wheel build on Linux. So that looks good. I'll leave further review to @FFY00, because he's more familiar with this code. |
Yeah, I am a bit uneasy about this. IMO we should wait until after the editable installs release to merge this, unless there's any dependence on this1. Footnotes
|
The reason to remove this is indeed not to have to worry about "stray" installation paths (installation paths that do not start with a placeholder) in the editable support code. If we want to err on the safe side, we can check that all installation paths start with a placeholder and error out if they do not. If we find any, it is a Meson bug. |
Even though newer Meson versions have it fixed, several users will still be using older versions, shipped by their distros. I'd really prefer to do this change after we release editable installs, so that we don't have to deal with breakage coming from several places.
Yes, we should do that. |
Please note that this change has the possibility of breaking normal installs. I just want to wait a little bit. |
No, they cannot use older Meson shipped by their distros, we depend on Meson >= 0.63.3: Line 31 in c9438b0
We already emit a warning if we cannot map the file. We can turn it into an error if the path does not start with a placeholder. |
I'm not in an hurry to merge this, but for what should we wait exactly? To say that we need to wait without specifying what we need to wait for seem like postponing indefinitely. What we should have done, was to add comments to this code specifying in which cases it was required, and ideally we should have added corresponding tests to the test suite. Now we would not be debating whether this work-around is still needed or not. But "del senno di poi son piene le fosse". |
I forgot about that. |
@dnicolodi did you delete this? Because I actually do not see your comment at all 🤣. I just got the email notification. |
Yes, I did. The comments are actually there. Just in a weird order. Sometimes the GitHub interface confuses me. |
We're missing |
(sorry, wrong button) |
Adding something to the meson-python's However, this is a good point. It is not impossible to conceive a way to use the system meson while installing meson-python in a virtual environment. I think maybe we should add a run-time check for the meson version. I think it would cost very little. Going down this line we could even move meson to a build dependency of the project being built obtained via |
You are right, good point. +1 for a check. |
It is theoretically possible to parse import json
import subprocess
stdout = subprocess.check_output(['meson', 'introspect', '--ast', 'meson.build'])
j = json.loads(stdout)
for kw in j['lines'][0]['args']['kwargs']:
if kw['key']['value'] == 'meson_version':
meson_version = kw['val']['value']
break |
We don't install the meson-python's |
b570f3c
to
e107203
Compare
Is there a way to make the output of pre-commit-check more informative? pre-commit-check is failing with this error
which tells me exactly nothing about what is wrong. |
mesonpy/__init__.py
Outdated
# Maps wheel installation paths to Meson installation path placeholders. | ||
_SCHEME_MAP = { | ||
'scripts': ('{bindir}',), | ||
'purelib': ('{py_purelib}',), | ||
'platlib': ('{py_platlib}', '{moduledir_shared}'), | ||
'headers': ('{includedir}',), | ||
'data': ('{datadir}',), | ||
# our custom location | ||
'mesonpy-libs': ('{libdir}', '{libdir_shared}') | ||
} | ||
|
||
|
||
def _map_meson_destination(destination: str) -> Tuple[Optional[str], pathlib.Path]: | ||
"""Map Meson installation path placeholders to wheel installation directory.""" | ||
parts = pathlib.Path(destination).parts | ||
for folder, placeholders in _SCHEME_MAP.items(): | ||
if parts[0] in placeholders: | ||
return folder, pathlib.Path(*parts[1:]) | ||
return None, pathlib.Path(destination) | ||
|
||
|
||
def _map_to_wheel(sources: Dict[str, Dict[str, Any]]) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]: | ||
"""Map files to the wheel, organized by wheel installation directrory.""" | ||
wheel_files = collections.defaultdict(list) | ||
for group in sources.values(): | ||
for src, target in group.items(): | ||
dest = target['destination'] | ||
directory, path = _map_meson_destination(dest) | ||
if directory is not None: | ||
wheel_files[directory].append((path, src)) | ||
else: | ||
warnings.warn(f'Installation path {dest!r} for {src!r} could not be mapped to an equivalent wheel directory.') | ||
if not re.match(r'^{\w+}$', path.parts[0]): | ||
raise RuntimeError('Meson installation path {dest!r} does not start with a placeholder. Meson bug!') | ||
return wheel_files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep these functions in _WheelBuilder
.
Please keep the docstring from _map_from_scheme_map
.
Installation paths can get quite big, so please keep the original "File could not be mapped to an equivalent wheel directory" warning. It puts the actual issue on the front, making sure you can easily read it if the path is big, and gives all similar warnings the same initial text, making it obvious that a bunch of warnings are the same issue.
The error could also benefit from a similar format, but it's less of a problem.
IMO it'd be cleaner to move the warnings to _map_meson_destination
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep these functions in
_WheelBuilder
.
Why? They don't need access to any member of _WheelBuilder
.
IMO it'd be cleaner to move the warnings to
_map_meson_destination
.
For doing that, either the src path needs to be passed to _map_meson_destination
just for the purpose of maybe emitting the warning this information needs to be removed from the warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? They don't need access to any member of
_WheelBuilder
.
Because its whole purpose is to support code in _WheelBuilder
, and this way it also can access internal state, for example the source paths you referred in the next comment.
For doing that, either the src path needs to be passed to
_map_meson_destination
just for the purpose of maybe emitting the warning this information needs to be removed from the warning.
Or you can have the function in _WheelBuilder
and be able to access it directly 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at how the code is written. Having it a method of _WheelBuilder
does not help in any way.
meson-python correct behavior depends on fixes for Meson bugs released with version 0.63.3. Implement a belt and suspenders approach for making sure the version of the meson command line tool matches our minimum requirement.
c5f07be
to
8286b5c
Compare
I did some more testing with the merged version of this in SciPy's CI. We have a specific job for Debian there which used to be an issue. All good now it looks like. Glad to see this code gone! |
This reverts commits: - 4a4b54b - ba2743e - 26ab3e4 - 8661c22 Signed-off-by: Filipe Laíns <[email protected]>
This reverts commits: - 4a4b54b - ba2743e - 26ab3e4 - 8661c22 Signed-off-by: Filipe Laíns <[email protected]>
This reverts commits: - 4a4b54b - ba2743e - 26ab3e4 - 8661c22 Signed-off-by: Filipe Laíns <[email protected]>
Switch from debug=false, optimization=2 to buildtype=release. Despite what the Meson documentation says, the former does not change the default buildtype=debug, which undesired effects on other settings derived from the value of the buildtype option. Whit the default b_vscrt=from_buildtype option, Meson instructs the MSVC compiler to use the debug version of the VS runtime library when buildtype=debug. This causes the linker look for the debug build of all the linked DLLs. The Python distribution for Windows does not contain a debug version of the python.dll and linking fails. To avoid this issue when the user explicitly asks for a debug build, also set b_vscrt=mt. The b_ndebug=if-release option set by meson-python also looks at the value of the buildtype and not to the value of the debug options. Setting buildtype=release has the desired effect of disabling assertions. The prefix, python.purelibdir, and python.platlibdir build options are no more necessary after the heuristic for determining the location where installed files need to be placer from their installation location has been removed in mesonbuild#280. Remove them. Fixes mesonbuild#381.
Switch from debug=false, optimization=2 to buildtype=release. Despite what the Meson documentation says, the former does not change the default buildtype=debug, which undesired effects on other settings derived from the value of the buildtype option. Whit the default b_vscrt=from_buildtype option, Meson instructs the MSVC compiler to use the debug version of the VS runtime library when buildtype=debug. This causes the linker look for the debug build of all the linked DLLs. The Python distribution for Windows does not contain a debug version of the python.dll and linking fails. To avoid this issue when the user explicitly asks for a debug build, also set b_vscrt=mt. The b_ndebug=if-release option set by meson-python also looks at the value of the buildtype and not to the value of the debug options. Setting buildtype=release has the desired effect of disabling assertions. The prefix, python.purelibdir, and python.platlibdir build options are no more necessary after the heuristic for determining the location where installed files need to be placer from their installation location has been removed in mesonbuild#280. Remove them. Fixes mesonbuild#381.
Switch from debug=false, optimization=2 to buildtype=release. Despite what the Meson documentation says, the former does not change the default buildtype=debug, which undesired effects on other settings derived from the value of the buildtype option. Whit the default b_vscrt=from_buildtype option, Meson instructs the MSVC compiler to use the debug version of the VS runtime library when buildtype=debug. This causes the linker look for the debug build of all the linked DLLs. The Python distribution for Windows does not contain a debug version of the python.dll and linking fails. To avoid this issue when the user explicitly asks for a debug build, also set b_vscrt=mt. The b_ndebug=if-release option set by meson-python also looks at the value of the buildtype and not to the value of the debug options. Setting buildtype=release has the desired effect of disabling assertions. The prefix, python.purelibdir, and python.platlibdir build options are no more necessary after the heuristic for determining the location where installed files need to be placer from their installation location has been removed in mesonbuild#280. Remove them. Fixes mesonbuild#381.
Switch from debug=false, optimization=2 to buildtype=release. Despite what the Meson documentation says, the former does not change the default buildtype=debug, which undesired effects on other settings derived from the value of the buildtype option. Whit the default b_vscrt=from_buildtype option, Meson instructs the MSVC compiler to use the debug version of the VS runtime library when buildtype=debug. This causes the linker look for the debug build of all the linked DLLs. The Python distribution for Windows does not contain a debug version of the python.dll and linking fails. To avoid this issue when the user explicitly asks for a debug build, also set b_vscrt=mt. The b_ndebug=if-release option set by meson-python also looks at the value of the buildtype and not to the value of the debug options. Setting buildtype=release has the desired effect of disabling assertions. The prefix, python.purelibdir, and python.platlibdir build options are no more necessary after the heuristic for determining the location where installed files need to be placer from their installation location has been removed in #280. Remove them. Fixes #381.
I think we can safely drop this now. The CI should agree.