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.
With this change File objects created with the builtin files() function
can be used with the fs submodule like normal strings.
All methods that seem reasonable support FileOrSting arguments.
For example fs.exists() still only takes str arguments because meson
already ensures that File objects do exist when creating them with files().
Each user facing function of the fs module has an additional FeatureNew
check when used with File objects.
The test cases for fs are extended appropriately with tests for File objects.
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
- 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.
Following #7890, this patch introduces the ability to read the contents
of a file to the fs module.
This patch introduces the ability to read files at configure time, but
has some restrictions:
- binary files are not supported (I don't think this will prove a
problem, and if people are wanting to do something with binary
files, they should probably be shelling out to their own script).
- Only files outside the build directory allowed. This limitation
should prevent build loops.
Given that reading an arbitrary file at configure time can affect the
configuration in almost arbitrary ways, meson should force a reconfigure
when the given file changes. This is non-configurable, but this can
easily be changed with a future keyword argument.
D lang compilers have an option -release (or similar) which turns off
asserts, contracts, and other runtime type checking. This patch wires
that up to the b_ndebug flag.
Fixes#7082
is_samepath better reflects the nature of this function--that files
and directories can be compared.
Also, instead of raising exceptions, simply return False when one
or both .is_samepath(path1, path1) don't exist. This is more
intuitive behavior and avoids having an extra if fs.exist() to go
with every fs.is_samepath()