aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules/python.py
AgeCommit message (Collapse)AuthorFilesLines
2022-12-09python module: don't overwrite and destroy the .pc dependency nameEli Schwartz1-1/+0
When finding a py.dependency() we try to use pkg-config. We then apply our own custom base class, which replaces self.name with the informative comment "override the name from the "real" dependency lookup", to which I can only say "uhhh why". Why do we want to do that??? It turns out we don't, it was just a really old legacy design because we had a SystemDependency with a .pkgdep attribute hiding the real dependency bizarro-land style. We cleaned that up in commit 4d67dd19e5b7dcec6716840d30984fa41eef55c6 and as part of that, we *shifted over* the self.name assignment to preserve the visible effects, sort of. We didn't have a *reason* to override the name, we just did it because... we weren't sure whether it mattered. Unfortunately it very much does matter the other way -- we don't want it. We can pass this dependency to the pkgconfig module, which uses the name attribute to fill out the `Requires: ` field. Also, the name should name what we have. :p Get rid of this bizarre historic quirk. Since we have proper dependencies here, we should go all in. Fixes https://github.com/ufo-kit/ufo-core/pull/185#issuecomment-1328224996
2022-11-30pylint: enable the set_membership pluginDylan Baker1-2/+2
Which adds the `use-set-for-membership` check. It's generally faster in python to use a set with the `in` keyword, because it's a hash check instead of a linear walk, this is especially true with strings, where it's actually O(n^2), one loop over the container, and an inner loop of the strings (as string comparison works by checking that `a[n] == b[n]`, in a loop). Also, I'm tired of complaining about this in reviews, let the tools do it for me :)
2022-11-24python module: fix broken non-embed dependencyEli Schwartz1-11/+13
The `py.dependency(embed: false)` method is supposed to consistently provide a distutils-like `python.pc` / `python-embed.pc` interface regardless of Python version. It handles both pkg-config and sysconfig scraping. For the latter, we respect the value of self.link_libpython as determined by distutils, and construct a fully custom dependency. For the former, we blindly assume pkg-config is correct. It isn't correct, not until Python 3.8 when embed was added. Before then, we need to process the pkg-config dependency based on link_libpython. We did this, but only inside the extension_module method, which is obviously wrong. Delete the special casing from extension_module, and handle it inside the dependency. Fixes #11097
2022-11-23python: Use correct extension filename suffix on Python < 3.8.7Daniele Nicolodi1-2/+10
On Windows, in Python version prior to 3.8.7, the `sysconfig` modules provides an extension filename suffix that disagrees the one returned by `distutils.sysconfig`. Get the more awesome suffix from the latter when building for a Python version known to present this issue. Simplify the extension module filename suffix lookup to use the same method used by `setuptools`. Adjust project tests accordingly. Fixes #10960.
2022-09-19python module: allow specifying the pure kwarg in the installation objectEli Schwartz1-4/+13
Fixes #10523
2022-08-25Revert "Windows: Improve Python 3.8+ module check on Windows"Eli Schwartz1-13/+1
This reverts commit 99ad11bd9c3249f548dda0b275d9f8dd1b3f6d14. This breaks working setups in conda. It is either wrong or incomplete and thus cannot be used. Fixes #10737
2022-08-22introspection: untangle install_plan implemetation, fix a bunch of wrong onesEli Schwartz1-8/+13
Generally plumb through the values of get_option() passed to install_dir, and use this to establish the install plan name. Fixes several odd cases, such as: - {datadir} being prepended to "share" or "include" - dissociating custom install directories and writing them out as {prefix}/share/foo or {prefix}/lib/python3.10/site-packages This is the second half of #9478 Fixes #10601
2022-08-17modules: use module level information about new and deprecationDylan Baker1-2/+3
Instead of using FeatureNew/FeatureDeprecated in the module. The goal here is to be able to handle information about modules in a single place, instead of having to handle it separately. Each module simply defines some metadata, and then the interpreter handles the rest.
2022-07-08implement the new preserve_path kwarg for install_data tooEli Schwartz1-4/+10
Primarily interesting to me because it is then available for the python module's install_sources method. Based on the new feature in install_headers.
2022-06-19python module: implicitly add python dep to extensionsEli Schwartz1-9/+19
If there isn't a preexisting dependency on python, append one. It's almost assuredly needed, so just do the right thing out of the box.
2022-06-19python module: cache dependency() lookup between invocationsEli Schwartz1-14/+26
Modeled similarly after the installations cache, but using the coredata dependency cache because it has a nice mechanism for handling the cache key.
2022-06-13flake8: don't use f-strings for strings without formattingEli Schwartz1-1/+1
2022-05-09python module: default extensions to hidden symbol visibilityEli Schwartz1-0/+4
python compiled extensions should never need to expose any symbol other than PyInit_* which is declared with default visibility via PyMODINIT_FUNC on supported compilers. Thus, a reasonably sane default is to mark any other symbols as hidden, while still respecting any manually specified visibility. Gate this on the version of python itself, as not all versions decorate PyMODINIT_FUNC properly.
2022-05-02Windows: Improve Python 3.8+ module check on WindowsChun-wei Fan1-1/+13
On Python 3.8.x and later, if the imported module requires non-system DLLs that are not installed nor bundled with the module package, os.add_dll_directory() must be called on every path that contains the required DLLs, so that the module can be imported successfully by Python. Make things easier for people by calling os.add_dll_directory() on the valid directories in %PATH%, so that such module checks can be carried out successfully with much less manual intervention.
2022-04-12python module: windows dll name for pypy needs special casingMatti Picus1-1/+9
2022-04-10Use a temp file to invoke the introspection command.Jussi Pakkanen1-1/+6
This is more reliable as '-c' can, for example, exhaust the maximum command line length.
2022-04-10python module: restore logging for broken pythonEli Schwartz1-5/+12
This check was erroneously removed in commit c5c02b72e132a03ae0284bdd5e15d1675301a37d
2022-03-16python: Remove warning about invalid install pathXavier Claessens1-9/+0
It was originally added because proper detection was not working on Debian, but that has been fixed since. It was causing annoying warning by default when prefix is /usr/local that can only be avoided by setting options.
2022-03-15Revert "devenv: Set PYTHONPATH where we install python modules"Eli Schwartz1-43/+6
This reverts commit 79c6075b560dbf1c3e4e0b30f1c472dc2086421e. # Conflicts: # docs/markdown/snippets/devenv.md # mesonbuild/modules/python.py # test cases/unit/91 devenv/test-devenv.py PYTHONPATH cannot be reliably determined. The standard use case for installing python modules with Meson is mixed pure sources (at least `__init__.py`) and compiled extension_modules or configured files. Unfortunately that doesn't actually work because python will not load the same package hierarchy from two different directories, one a source directory and one a (mandatory) out of tree build directory. (It kind of can, but you need to do what this test case accidentally stumbled upon, which is namespace packages. Namespace packages are a very specific use case and you are NOT SUPPOSED to use them outside that use case, so people are not going to use them just to circumvent Meson devenv stuff as that would have negative install-time effects.) Adding PYTHONPATH anyway will just lead to documentation commitments which we cannot actually uphold, and confusing issues at time of use because some imports *will* work... and some will *not*. The end result will be a half-created tree of modules which just doesn't work together at all, but because it partially works, users attempting to debug it will spend time wondering why parts of it do import. For any case where the automatic devenv would work correctly, it will also work correctly to use `meson.add_devenv()` a single time, which is very easy to manually get correct and doesn't provide any significant value to automate. In the long run, an uninstalled python package environment will require "editable installs" support.
2022-03-10Remove a spurious debug print in Python moduleRalf Gommers1-1/+0
This prints many lines of unwanted "done /absolute/path", I noticed this when testing 0.62.0rc1 with SciPy. [ci skip]
2022-03-07fix correctly detecting whether python is found if link args are emptyEli Schwartz1-1/+1
There are two cases where we can assume we found the python dependency with its requisite libraries using sysconfig: - we found the library with find_library and are prepared to link to it - the library is not actually part of the dependency, so its presence or absence is irrelevant In the latter case, we should consider it found if link_libpython is False. Originally we did this, but the logic was inverted in commit 5b422fce87826beff3bca85e9c9081f22b3f45b7 in an unrelated change and without explanation, likely by accident. Normally this doesn't much matter, since a python invariably comes with a predictably located libpython and the first condition evaluates true. But that is not true for pypy, and in fact that is the reason the link_libpython check was originally added in commit 1bd14b52b26b0f4ec207bf7e38813b82bfc15f86. Restore that original logic. Fixes #8570
2022-03-07merge various TYPE_CHECKING blocks into oneEli Schwartz1-36/+29
A bunch of files have several T.TYPE_CHECKING blocks that each do some things which could just as well be done once, with a single `if` statement. Make them do so.
2022-02-28devenv: Set PYTHONPATH where we install python modulesXavier Claessens1-6/+44
2022-02-28Cache the result of python.find_installation()Xavier Claessens1-29/+34
This avoids running sanity checks everytime find_installation() is called.
2022-02-22python module: add option to specify a python environment to install toEli Schwartz1-0/+21
The default behavior of installing relative to prefix may be unexpected, and is definitely wrong in many cases. Give users control in order to specify that yes, they actually want to install to a venv. This is particularly useful for projects that use meson as a build system for a python module, where *all* files shall be installed into the python site-packages.
2022-01-20python module: only find a pkg-config dependency from the found pythonEli Schwartz1-8/+21
If the found python returns None from sysconfig.get_config_var('LIBPC') then we cannot (and don't) set PKG_CONFIG_LIBDIR from it. In fact, we can virtually guarantee we won't find a PkgConfigDependency either, because any python that doesn't have a LIBPC is presumably not installed to the system pkg-config directory (maybe it's an isolated relocatable install, maybe it just doesn't have pkg-config support for who knows what reason). Trying to find one anyway using pkg-config's builtin search paths can unexpectedly succeed, though, by finding a completely unrelated python installation installed to a system location, which isn't the one we are actually building for. Instead, return early so that we use the system dependency class fallback. While we are at it, add back the debug messages from #3989 which got removed.
2021-11-15Fix to find Python files for Windows virtualenvsMatthew Brett1-2/+6
Virtualenvs do not have their Python DLLs etc in the `sys.prefix` directory, but in the `sys.base_prefix` directory. This directory is the same as `sys.prefix` if not in a virtualenv, so is safe for either case: https://docs.python.org/3/library/sys.html#sys.base_prefix
2021-11-09python: Better detect when install path is not in sys.pathXavier Claessens1-9/+12
Using pathlib ensure propre platform specific path handling, such as case sensitivity.
2021-11-02python.dependency(): Do not stop when first candidate is not foundXavier Claessens1-3/+4
It has to lookup the dependency with required=False otherwise it raises an exception when the first candidate (pkg-config) failed.
2021-10-27fix various flake8 whitespace errorsEli Schwartz1-5/+5
2021-10-26dep.name(): return dependency name even if dependency is not foundThomas Heijligen1-2/+1
The dep.name() function schould always return the name of the dependency as documented. No matter if it was found or not. https://mesonbuild.com/Reference-manual_returned_dep.html#depfound
2021-10-10Fix typos discovered by codespellChristian Clauss1-3/+3
2021-10-08python: Add platlibdir and purelibdir optionsXavier Claessens1-6/+11
2021-10-04f-stringsEli Schwartz1-4/+2
2021-09-29modules: python: better handling of the Python paths for DebianFilipe Laíns1-8/+35
Hardcoding the name is fragile, and enabling it based on the existence of /etc/debian_version (as the is_debianlike helper does) will result in incorrect paths if the Python binary is not provided by Debian. Using the deb_system distuils scheme instead makes sure we use the install path from the current interpreter, which Debian could change between releases, and gives us the correct value on Python installations that are not provided by Debian (eg. deadsnakes, Github Action Python, etc.) Do notice, though, that there is still no guarantee that these are the correct paths, as they assume all schemes paths have the install prefix as a base, see #9284. Signed-off-by: Filipe Laíns <lains@riseup.net>
2021-09-06mintro: add installed_planFilipe Laíns1-1/+5
Signed-off-by: Filipe Laíns <lains@riseup.net>
2021-08-31python module: fix error message mentioning setuptoolsEli Schwartz1-1/+1
We use distutils, not setuptools, for probing information.
2021-08-30Add missing "disabler" kwarg to python.dependency()Xavier Claessens1-0/+1
There is a unit test using it and now fails because the warning about unknown kwarg became fatal.
2021-08-27interpreter: fix cases of `KwargInfo(..., T, default=None)`Dylan Baker1-1/+2
The correct way to mark these is `KwargInfo(..., (T, type(None)))`. There's also a few cases of `(T, None)` which is invalid, as `None` isn't a type
2021-08-27python module: produce the correct install path on every OSEli Schwartz1-1/+1
The sysconfig paths are, by default, correct for every OS -- they are supposed to follow the scheme that python knows about per default. For some reason, this overrode the scheme to posix_prefix, which is the default for posix OSes like linux and macOS, but wrong on Windows. Simply deleting this entirely makes everything that used to work, still work, and a couple new things start working.
2021-08-22python: Workaround broken install pathXavier Claessens1-3/+20
2021-08-18python module: fix extensions without explicit subdir being installed to libdirEli Schwartz1-4/+4
They are documented to go in site-packages, and indeed belong there. Regression from the initial implementation via commit ad296976f079cd185ab7361e3e4b18c6bf684090 Fixes #6331
2021-08-18python module: make external program wrapper have access to useful metadataEli Schwartz1-26/+35
Basically just reorganize code. Try to make it a little neater, while we're at it.
2021-08-18Fix incorrect .name attribute for python programEli Schwartz1-3/+4
It is always set to python3 even if we asked for python2...
2021-08-18fix some confusingly indirect codeEli Schwartz1-3/+3
rsplit(..., 1) always produces exactly one split, by design, there's no need to then join a 1-element list via a generator comprehension after extracting the end of it via pop. If this commit message sounds confusing, then so was I when trying to figure out what this actually did and if it needed extracting to PythonExternalModule.
2021-08-17Add install tagsXavier Claessens1-3/+5
Fixes: #7007.
2021-08-03Fix python module leaving PKG_CONFIG_LIBDIR set in os.environ.Xavier Claessens1-4/+7
2021-07-13modules/python: fix up a few simply typing warnings/errorsDylan Baker1-8/+24
These were spotted by mypy and pyright. One is a string where a Path is expected, another other is a possibly unbound variable, and the third is bound but unused variables.
2021-07-13modules/python: Allow trying a macos framework as well other methodsDylan Baker1-2/+18
2021-07-13modules/python: make some internal helpers protectedDylan Baker1-4/+4