Commit Graph

42 Commits

Author SHA1 Message Date
Dylan Baker
348d8610db Set the encoding parameter for all open() calls that write in text mode
This was generated with a regex search/replace in vscode using:
`(open\(.*, 'w\+?')` -> `$1, encoding='utf-8')`

This should silence a bunch of warnings, and seems to fix issues seen in
the Windows CI. This seems to likely be to a "helpful feature" in
msbuild that treats certain text in stdout/stderr as errors, which it
sometimes decides that the warning about not having the encoding set
triggers.
2026-05-01 11:18:47 -04:00
Michał Górny
74395f67e7 tests: Skip limited API test on freethreading Python versions
Skip the limited API test when the CPython version used indicates
being built with GIL disabled, i.e. the freethreaded build.
The freethreaded versions of Python 3.13 and 3.14 do not support
the limited API, and attempting to build the test case results
in compilation failures.

The check is limited to <3.15, so we don't forget to reenable it
once limited API is supported.

Signed-off-by: Michał Górny <mgorny@quansight.com>
2025-11-14 01:37:49 -05:00
L. E. Segovia
555502761e tests: Add test for checking get_executable_serialization with interpreted executables 2025-06-03 20:10:45 +05:30
Eli Schwartz
f41c0f5436 tests: work around broken PyPy globbing by removing inert code
We check to see if a test extension exists, and if so add its path to
sys.path... immediately before unconditionally importing it, obviously.

This raises the question: why bother checking? Can it ever fail? What if
it does fail, do we simply not add path entries and then expect the rest
of the test file to work??? The whole thing seems silly and useless.

In fact it can fail, if the python interpreter and/or standard library
is broken. This is the case for the initial release of PyPy 3.11, in
which `'*tachyon*'` fails to glob correctly (and `'tachyon*'` would
work, funnily enough -- this is valid too for our use case although
still just as pointless).

Delete the useless check. It's technically correct to delete it, and it
*also* works around the PyPy breakage as a bonus.

Closes: https://github.com/mesonbuild/meson/issues/14307
2025-02-28 03:11:58 -05:00
Andrew McNulty
d1abdce88f Python: add load test to limited API test
Based on the example in GH issue #13167, the limited API test has been
extended with a test to load the compiled module to ensure it can be
loaded correctly.
2024-06-11 19:47:31 +02:00
Charles Brunet
b290a82541 Fix KeyError in Python module
0e7fb07 introduced a subtile bug in the Python module.
If a python version is found, but is missing a required module,
it is added to the list of python installations, but the
`run_bytecompile` attribute for that version was not initialized.
Therefore, if any other python version added something to install, it
was raising a KeyError when trying to read the `run_bytecompile`
attribute for the python version with missing module.
2024-02-19 21:52:09 +02:00
Eli Schwartz
ecf261330c tests: fix test case to not import distutils on python 3.12
Testing the correctness of the `modules: ` kwarg can be done with other
guaranteed stdlib modules that are even more guaranteed since they
didn't get deprecated for removal.
2023-10-02 23:53:39 -04:00
Andrew McNulty
c730807696 Python: Add 'limited_api' kwarg to extension_module
This commit adds a new keyword arg to extension_module() that enables
a user to target the Python Limited API, declaring the version of the
limited API that they wish to target.

Two new unittests have been added to test this functionality.
2023-08-14 20:02:09 -04:00
Christoph Reiter
6671b7359f tests: fix "4 custom target depends extmodule" with Python 3.8+ on Windows
Since CPython 3.8 .pyd files no longer look in PATH for loading libraries,
but require the DLL directory to be explicitely added via os.add_dll_directory().
This resulted in those tests failing with 3.8+ on Windows.

Add the DLL build directory with os.add_dll_directory() to fix them.

This was never noticed in CI because it only uses Python 3.7 and the
MSYS2 CPython still used the old behaviour until now.
2023-08-08 16:32:39 -04:00
Ralf Gommers
91c7e79519 Use release buildtype in Cython tests, and skip unless ninja backend
This matches the tests for Python extensions.

Also include some other cleanups to these `meson.build` files:

Adding `python_dep` is no longer needed, this is automatic now.
Use a single line for `import('python').find_installation()`,
because the result of `import('python')` by itself is not used
for anything.
2023-05-05 12:23:52 -04:00
Eli Schwartz
6a1427401c tests: add a python test for bytecode compilation
Some tweaks are added to the test case so that it supports python2 as
well.
2023-05-02 19:28:35 -04:00
Eli Schwartz
0e7fb07f91 python module: add an automatic byte-compilation step
For all source `*.py` files installed via either py.install_sources() or
an `install_dir: py.get_install_dir()`, produce `*.pyc` files at install
time. Controllable via a module option.
2023-05-02 19:28:35 -04:00
Charles Brunet
bda799dff2 fix python.version() not working in some cases
import('python').find_installation('python').version() causes exception
because of a missing initialization, when `find_installation()` receives
a name or a path.
2023-04-23 23:03:25 -04:00
Josh Soref
cf9fd56bc9 fix various spelling issues
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-11 19:21:05 -04:00
Eli Schwartz
9d98b4cb84 test that python modules nominally compile without warnings
Because we poke around with the dependency, so we might introduce some,
and have at least once.
2023-03-28 15:15:45 -04:00
Eli Schwartz
a024d75e15 backends: add a new "none" backend
It can only be used for projects that don't have any rules at all, i.e.
they are purely using Meson to:

- configure files
- run (script?) tests
- install files that exist by the end of the setup stage

This can be useful e.g. for Meson itself, a pure python project.
2023-03-20 17:22:50 -04:00
Eli Schwartz
aa84c55bef tests: fix edge case where non-default python is used, by skipping it
In a couple of python module tests, we try to test things that rely on
the default python being the same one we look up in the python module.
This is unsolvable for the deprecated python3 module, as it actually
uses the in-process version of python for everything. For the python
module, we could actually look up the default system python instead of
the one we are running with, but then we wouldn't be testing the
functionality of that alternative python... and also the install
manifest tests would see files installed for the wrong version of
python, and report a combination of missing+extra files...

Solve both tests by just skipping the parts we cannot check.
2022-11-14 19:16:57 -05:00
Eli Schwartz
eb69fed2f6 python module: allow specifying the pure kwarg in the installation object
Fixes #10523
2022-09-19 21:13:37 -04:00
Eli Schwartz
e7d87b6f58 implement the new preserve_path kwarg for install_data too
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-07-08 01:58:23 -04:00
Eli Schwartz
22dcb692ad python module: implicitly add python dep to extensions
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-19 21:44:17 +03:00
Eli Schwartz
041c372048 tests: make python2 dependency on 32-bit windows non-fatal
Apparently Azure provides 64-bit python2 when we try to test 32-bit, and
that breaks everything on the 32-bit test runner.

I don't understand the environment setup, and that runner is
disappearing soon anyway. Hopefully this shuts up the known breakage.
2022-03-18 18:21:21 +02:00
Eli Schwartz
fe2c0ff1e2 tests: don't skip python version tests if python is found but its dep is broken
If a version of python is installed for testing against, we should
assume it's actually important to test against it.
2022-03-17 07:29:55 -04:00
Eli Schwartz
4b0c0810df unittests: convert python tests to project tests
Perhaps when this test case was originally created, project tests could
not use a matrix of options? This is certainly possible today, so don't
write special unittest handling for this instead.

This adds proper visibility into what gets run and what doesn't. Now we
know which python executables got tested and which got skipped.
2022-03-16 18:39:02 -04:00
Xavier Claessens
329d111709 python: Add platlibdir and purelibdir options 2021-10-08 17:47:35 -04:00
Filipe Laíns
59b8e00249 tests: take into account Debian Python paths
Signed-off-by: Filipe Laíns <lains@riseup.net>
2021-09-29 08:54:05 -04:00
Eli Schwartz
1f46b4ce64 tests: python module should install files correctly
- default to python site-packages
- subdir to site-packages/subdir
- arbitrary install_dir
2021-08-18 17:58:30 -04:00
Xavier Claessens
a2f110ff77 interpreter: Fix holder_map not being updated when subproject fails
Fixes: #9038
2021-08-16 12:03:33 -04:00
Jussi Pakkanen
3340d373fb Revert "interpreter: Fix holder_map not being updated when subproject fails"
This reverts commit 566383c727.
2021-08-15 13:18:35 +03:00
Xavier Claessens
566383c727 interpreter: Fix holder_map not being updated when subproject fails
Fixes: #9038
2021-08-09 14:11:42 -04:00
Eli Schwartz
6a0fabc647 mass rewrite of string formatting to use f-strings everywhere
performed by running "pyupgrade --py36-plus" and committing the results
2021-03-04 17:16:11 -05:00
Michael Hirsch
c9d8d4628e simplify/correct test logic
before this, tests were being skipped on Ubuntu 20.04 with Anaconda Python
Now, all 5 tests success
2020-07-12 09:53:26 -04:00
Michael Hirsch
895de87b90 some python test cases don't care about backend, so run them in any case 2020-07-12 09:12:16 -04:00
Michael Hirsch
4f1a240bc2 raise SystemExit() generally preferred to sys.exit(1) 2020-07-12 09:08:04 -04:00
Michael Hirsch
173d1624cb c lang not needed for this test 2020-07-12 09:04:59 -04:00
Michael Hirsch
ab72f52743 setuptools is not stdlib, but distutils is 2020-07-12 09:01:55 -04:00
Jussi Pakkanen
ad1cfbe7ec Disable extension module tests with Python 3.8 and VS2015. 2019-10-20 13:30:17 +03:00
Dylan Baker
15ab1f64f9 modules/python: add a modules keyword argument
This mirrors the modules keyword argument that some dependencies (such
as qt and llvm) take. This allows an easier method to determine if
modules are installed.
2019-06-12 14:13:20 +03:00
Dylan Baker
82346a2bd2 modules/python: Report program found in find_installation()
Currently find_installation is silent, which is pretty annoying. Let's
log it.
2019-04-03 14:48:29 -07:00
Dylan Baker
978e6fb88f tests: Add tests for the python module
This doesn't touch everything as it's just based on the python3 module
tests, ported to the python module. It's still better than the one very
basic test in the unit test module.
2018-12-12 12:23:37 -08:00
Nirbheek Chauhan
575ffec62e python module: Move tests to test cases/unit
The tests are only run via unit tests, so that's where they should be.
2018-05-03 18:56:34 +05:30
Mathieu Duponchelle
33abe0cf55 [fixup]: Rename find to find_installation 2018-04-09 15:43:25 +02:00
Mathieu Duponchelle
e1b138a21b Implement a generic python module
With contributions from Håvard Graff
2018-04-06 22:43:35 +02:00