Commit Graph

94 Commits

Author SHA1 Message Date
Eli Schwartz 8947352889 fix various flake8 whitespace errors 2021-10-27 09:51:52 -04:00
Thomas Heijligen ecdf192f46 dep.name(): return dependency name even if dependency is not found
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-26 09:36:22 -04:00
Christian Clauss a5020857f3 Fix typos discovered by codespell 2021-10-10 16:12:25 -04:00
Xavier Claessens 329d111709 python: Add platlibdir and purelibdir options 2021-10-08 17:47:35 -04:00
Eli Schwartz d06cc042eb
f-strings 2021-10-04 16:29:32 -04:00
Filipe Laíns 05b5a1e56f modules: python: better handling of the Python paths for Debian
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-29 08:54:05 -04:00
Filipe Laíns af8b55d49b mintro: add installed_plan
Signed-off-by: Filipe Laíns <lains@riseup.net>
2021-09-06 18:10:55 +02:00
Eli Schwartz 34ac77d619 python module: fix error message mentioning setuptools
We use distutils, not setuptools, for probing information.
2021-08-31 08:42:27 -07:00
Xavier Claessens 276063a1d2 Add missing "disabler" kwarg to python.dependency()
There is a unit test using it and now fails because the warning about
unknown kwarg became fatal.
2021-08-30 14:00:54 -04:00
Dylan Baker 11fbaf29d8 interpreter: fix cases of `KwargInfo(..., T, default=None)`
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-27 14:54:29 -07:00
Eli Schwartz 6170f1175e python module: produce the correct install path on every OS
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-27 07:46:58 -04:00
Xavier Claessens 0063eb251e python: Workaround broken install path 2021-08-22 22:14:59 -04:00
Eli Schwartz b0ffb80ecf
python module: fix extensions without explicit subdir being installed to libdir
They are documented to go in site-packages, and indeed belong there.

Regression from the initial implementation via commit ad296976f0

Fixes #6331
2021-08-18 17:58:30 -04:00
Eli Schwartz d9a9c3b5da
python module: make external program wrapper have access to useful metadata
Basically just reorganize code. Try to make it a little neater, while
we're at it.
2021-08-18 17:54:52 -04:00
Eli Schwartz 445f08869b
Fix incorrect .name attribute for python program
It is always set to python3 even if we asked for python2...
2021-08-18 17:54:52 -04:00
Eli Schwartz 9eac9e0ff2
fix some confusingly indirect code
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-18 17:54:51 -04:00
Xavier Claessens 8c5aa031b5 Add install tags
Fixes: #7007.
2021-08-17 15:19:18 -04:00
Xavier Claessens 3f71779f8a Fix python module leaving PKG_CONFIG_LIBDIR set in os.environ. 2021-08-03 14:44:03 -04:00
Dylan Baker b4e826bff3 modules/python: fix up a few simply typing warnings/errors
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-13 16:43:14 -07:00
Dylan Baker eac2d5eec5 modules/python: Allow trying a macos framework as well other methods 2021-07-13 16:43:14 -07:00
Dylan Baker d6e606166e modules/python: make some internal helpers protected 2021-07-13 16:43:14 -07:00
Dylan Baker 4d67dd19e5 modules/python: use factory for dependency
This removes the odd 'pkgdep' attribute thing, and makes it behave more
like a proper dependency
2021-07-13 16:43:14 -07:00
Dylan Baker a881e849b5 modules/python: simplify a number of interfaces
Including not calling back into `Interpreter.func_*`, which is not a
good idea both from a type saftey and perforamance point of view.
Instead there's now a shared _impl method
2021-07-13 16:43:14 -07:00
Dylan Baker 9eec2a131b modules/python: use typed_pos_args
And note that the way that find_installation works is completely broken
in regards to machine files
2021-07-13 16:43:14 -07:00
Dylan Baker 1f7ab2f010 modules/python: Add type annotations
There's still a number of things that don't properly type check, that's
expected though as the input is often unvalidated and assumed good.
2021-07-13 16:43:14 -07:00
Dylan Baker 3b3c580817 modules/python: sort imports 2021-07-13 16:41:37 -07:00
Daniel Mensinger 7c757dff71 holders: Fix the remaining code to respect the holder changes 2021-06-18 23:48:33 +02:00
Eli Schwartz bbcc91c1e5
expose SystemDependency and BuiltinDependency as toplevel classes
mesonbuild.dependencies.__init__ exposes configtool, pkgconfig, cmake
and more in __init__.py, so there's no reason we should be tying
SystemDependency to the internal organization implementation of the
subpackage!

In the 2nd previous commit it took quite some effort to figure out that
the python module "does not exist" because of import errors while
refactoring something completely different.
2021-06-17 13:22:25 -04:00
Eli Schwartz 493dc6ed10
move base class for system dependencies into base.py
In accordance with review comments; it's small enough this seems fitting.
2021-06-17 13:22:25 -04:00
Dylan Baker 203a548d60 dependencies: Use the SystemDependency
This fixes these dependencies, which currently return the name of the
dependency as the type.

Fixes #8877
2021-06-14 09:09:32 -07:00
Daniel Mensinger 95b70bcb97 deps: Split dependencies.base
Split the Factory and dependency classes out
of the base.py script to improve maintainability.
2021-06-03 10:23:27 -07:00
Xavier Claessens 2e02ef6592 modules: Add methods dict everywhere
This fix calling random internal methods from meson.build as long as
they were not prefixed by underscore.
2021-05-28 15:17:10 -04:00
Xavier Claessens 723c5227a4 modules: Remove snippet methods
The only advantage they have is they have the interpreter in arguments,
but it's already available as self.interpreter. We should discourage
usage of the interpreter API and rely on ModuleState object instead in
the future.

This also lift the restriction that a module method cannot add build
targets, but that was not enforced for snippet methods anyway (and some
modules were doing it) and it's really loose restriction as it should
check for many other things if we wanted to make it consistent.
2021-05-28 15:17:10 -04:00
Xavier Claessens ed57646475 interpreter: 'embed' kwarg is only valid in python module 2021-05-08 21:31:55 +03:00
Xavier Claessens 7ffe1b4a66 interpreter: Split permitted_kwargs dict 2021-04-12 21:30:00 +03:00
Dylan Baker 40e3577a65 split program related classes and functions out of dependencies
Dependencies is already a large and complicated package without adding
programs to the list. This also allows us to untangle a bit of spaghetti
that we have.
2021-03-19 08:47:10 -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
Eli Schwartz 4340bf34fa
various python neatness cleanups
All changes were created by running

"pyupgrade --py3-only --keep-percent-format"

and committing the results. I have not touched string formatting for
now.

- use set literals
- simplify .format() parameter naming
- remove __future__
- remove default "r" mode for open()
- use OSError rather than compatibility aliases
- remove stray parentheses in function(generator) scopes
2021-03-04 17:11:26 -05:00
Xavier Claessens ba9bfd2bd8 Simplify module API
- ModuleState is now a real class that will have methods in the future
  for actions modules needs, instead of using interpreter internal API.
- New ModuleObject base class, similar to InterpreterObject, that should
  be used by all objects returned by modules. Its methods gets the
  ModuleState passed as first argument. It has a `methods` dictionary to
  define what is public API that can be called from build definition.
- Method return value is not required to be a ModuleReturnValue any
  more, it can be any type that interpreter can holderify, including
  ModuleObject.
- Legacy module API is maintained until we port all modules.

In the future modules should be updated:
- Use methods dict.
- Remove snippets.
- Custom objects returned by modules should all be subclass of
  ModuleObject to get the state iface in their methods.
- Modules should never call into interpreter directly and instead state
  object should have wrapper API.
- Stop using ModuleReturnValue in methods that just return simple
  objects like strings. Possibly remove ModuleReturnValue completely
  since all objects that needs to be processed by interpreter (e.g.
  CustomTarget) should be created through ModuleState API.
2021-03-04 11:33:22 -05:00
Dylan Baker e81acbd606 Use a single coredata dictionary for options
This patches takes the options work to it's logical conclusion: A single
flat dictionary of OptionKey: UserOptions. This allows us to simplify a
large number of cases, as we don't need to check if an option is in this
dict or that one (or any of 5 or 6, actually).
2021-01-04 12:20:58 -08:00
Dylan Baker f6672c7a19 use real pathlib module
We added the _pathlib module to work around defeciencies in python 3.5's
implementation, since we now rely on 3.6 lets drop this
2020-11-20 15:08:40 -08:00
Xavier Claessens 8b20852b0f python.dependency() is not respecting 'required' kwarg 2020-10-06 19:15:59 -04:00
Daniel Mensinger 1dfaccfd91 pathlib: Fix resolve() by overriding it in Python 3.5 2020-10-04 10:45:48 +02:00
Marc-André Lureau efb86088bc python: install_sources() should default to pure, following the doc
As stated by the doc, default to install python sources to purelib
location, as they should not depend on platform.

This also fixes discrepancy between get_install_dir() and
install_sources() locations.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-05-10 20:08:41 +03:00
Xavier Claessens 39a69d1fb0 find_program: Fixes when the program has been overridden by executable
- ExternalProgramHolder has path() method while CustomTargetHolder and
  BuildTargetHolder have full_path().
- The returned ExternalProgramHolder's path() method was broken, because
  build.Executable object has no get_path() method, it needs the
  backend.
- find_program('overridden_prog', version : '>=1.0') was broken because
  it needs to execute the exe that is not yet built. Now assume the
  program has the (sub)project version.
- If the version check fails, interpreter uses
  ExternalProgramHolder.get_name() for the error message but
  build.Executable does not implement get_name() method.
2020-04-28 01:39:56 +03:00
John Ericson 3a4388e51d Fix legacy env var support with cross
Fix #3969
2020-03-23 17:51:36 +02:00
Nirbheek Chauhan 40b58be100 modules/python: Do not error out if positional args are passed
Also update the documentation.

Fixes https://github.com/mesonbuild/meson/issues/6470
2020-02-17 00:38:57 +02:00
Dylan Baker fd892ad7ce dependencies: Make Dependency initializer signatures match
Currently PkgConfig takes language as a keyword parameter in position 3,
while the others take it as positional in position 2. Because most
dependencies don't actually set a language (they use C style linking),
using a positional argument makes more sense. ExtraFrameworkDependencies
is even more different, and duplicates some arguments from the base
ExternalDependency class.

For later changes I'm planning to make having all of the dependencies
use the same signature is really, really helpful.
2020-01-29 09:11:24 -08:00
Daniel Mensinger 09b53c534f types: import typing as T (fixes #6333) 2020-01-08 15:28:17 +01:00
Daniel Mensinger c4649704c8 python: add embed to the python dependency function 2019-12-18 01:19:16 +02:00