[PyQt] [SIP] Multi-platform pyproject.toml (platform dependent values)

Phil Thompson phil at riverbankcomputing.com
Thu Dec 12 14:37:01 GMT 2019


On 12/12/2019 13:46, Matteo Bertini wrote:
> This quick and dirty patch does what I suggested:
> 
>     diff -r d82ebe4b05b2 sipbuild/bindings.py
>     --- a/sipbuild/bindings.py      Fri Oct 04 23:29:15 2019 +0100
>     +++ b/sipbuild/bindings.py      Thu Dec 12 14:33:07 2019 +0100
>     @@ -245,7 +245,25 @@
>                          copy_nonshared_sources(project.abi_version,
>                                  buildable.build_dir))
> 
>     -        buildable.include_dirs.extend(self.include_dirs)
>     +        from packaging.markers import Marker
>     +
>     +        def filter_markers(values):
>     +            return [item for item in (filter_marker(v) for v in
> values) if item is not None]
>     +
>     +        def filter_marker(value):
>     +            if ";" not in value:
>     +                return value
>     +            value, marker = value.split(";", 1)
>     +            if Marker(marker).evaluate():
>     +                return value
>     +
>     +        def abspath_from_root_dir(path):
>     +            if os.path.isabs(path):
>     +                return path
>     +            else:
>     +                return os.path.join(project.root_dir, path)
>     +
>     +        buildable.include_dirs.extend([abspath_from_root_dir(path) 
> for
> path in filter_markers(self.include_dirs)])
>              buildable.sources.extend(self.sources)
> 
>              if self.protected_is_public:
>     @@ -254,8 +272,8 @@
> 
>              buildable.define_macros.extend(self.define_macros)
> 
>     -        buildable.libraries.extend(self.libraries)
>     -        buildable.library_dirs.extend(self.library_dirs)
>     +        buildable.libraries.extend(filter_markers(self.libraries))
>     +        buildable.library_dirs.extend([abspath_from_root_dir(path) 
> for
> path in filter_markers(self.library_dirs)])
> 
>              return buildable
> 
> This allows to use this syntax in `pyproject.toml`:
> 
>     [tool.sip.bindings.somemodule]
>     include-dirs = [".",
>                     "linux; 'linux' in sys_platform",
>                     "win32; 'win32' in sys_platform"]
>     library-dirs = ["linux; 'linux' in sys_platform",
>                     "win32; 'win32' in sys_platform"]
>     libraries = ["somelib64; 'linux' in sys_platform and 'x86_64' in
> platform_machine",
>                  "somelib32; 'linux' in sys_platform and 'x86_64' not 
> in
> platform_machine",
>                  "usb-1.0;   'linux' in sys_platform",
>                  "user32;    'win32' in sys_platform"]
> 
> Notable changes:
> 
> 1) non-absolute paths are considered relative to `project.root_dir` aka 
> the
> `pyptoject.toml` folder if I'm correct,
> 2) a bunch of fields are filtered if containing `;` and
> `packaging.markers.Marker` is used to do the real work.
> 
> I'm quite confident that 1) is an expected behaviour, perhaps with some
> check or better error / warning message if the joined path is invalid.
> 
> Instead 2) can result in unwanted errors, because the presence of the 
> `;`
> is used to activate a parsing that may fail with some existing user 
> input.
> 
> Can we provide a list variable to let the user opt-in the marker
> evaluation? Something like:
> 
>     [tool.sip.bindings.somemodule]
>     evaluate-markers = ["include-dirs", "library-dirs", "libraries"]
> 
> We can perhaps find a default set of fields that one can enable with a
> single boolean option, just to avoid the listing, something like:
> 
>     [tool.sip.metadata]
>     name = "somemodule"
>     evaluate-default-markers = true
> 
> Should I move this config into a custom `project.py` or integrate it 
> better
> into the mainline one (open to suggestions)?

I'm happy to take this on as is for SIP v5.1. I didn't realise it would 
be so easy - I didn't know about packaging.markers.

Thanks,
Phil


More information about the PyQt mailing list