<div dir="ltr">This quick and dirty patch does what I suggested:<br><br> diff -r d82ebe4b05b2 sipbuild/bindings.py<br> --- a/sipbuild/bindings.py Fri Oct 04 23:29:15 2019 +0100<br> +++ b/sipbuild/bindings.py Thu Dec 12 14:33:07 2019 +0100<br> @@ -245,7 +245,25 @@<br> copy_nonshared_sources(project.abi_version,<br> buildable.build_dir))<br> <br> - buildable.include_dirs.extend(self.include_dirs)<br> + from packaging.markers import Marker<br> +<br> + def filter_markers(values):<br> + return [item for item in (filter_marker(v) for v in values) if item is not None]<br> +<br> + def filter_marker(value):<br> + if ";" not in value:<br> + return value<br> + value, marker = value.split(";", 1)<br> + if Marker(marker).evaluate():<br> + return value<br> +<br> + def abspath_from_root_dir(path):<br> + if os.path.isabs(path):<br> + return path<br> + else:<br> + return os.path.join(project.root_dir, path)<br> +<br> + buildable.include_dirs.extend([abspath_from_root_dir(path) for path in filter_markers(self.include_dirs)])<br> buildable.sources.extend(self.sources)<br> <br> if self.protected_is_public:<br> @@ -254,8 +272,8 @@<br> <br> buildable.define_macros.extend(self.define_macros)<br> <br> - buildable.libraries.extend(self.libraries)<br> - buildable.library_dirs.extend(self.library_dirs)<br> + buildable.libraries.extend(filter_markers(self.libraries))<br> + buildable.library_dirs.extend([abspath_from_root_dir(path) for path in filter_markers(self.library_dirs)])<br> <br> return buildable<br><br>This allows to use this syntax in `pyproject.toml`:<br><br> [tool.sip.bindings.somemodule]<br> include-dirs = [".",<br> "linux; 'linux' in sys_platform",<br> "win32; 'win32' in sys_platform"]<br> library-dirs = ["linux; 'linux' in sys_platform",<br> "win32; 'win32' in sys_platform"]<br> libraries = ["somelib64; 'linux' in sys_platform and 'x86_64' in platform_machine",<br> "somelib32; 'linux' in sys_platform and 'x86_64' not in platform_machine",<br> "usb-1.0; 'linux' in sys_platform",<br> "user32; 'win32' in sys_platform"]<br><br>Notable changes:<br><br>1) non-absolute paths are considered relative to `project.root_dir` aka the `pyptoject.toml` folder if I'm correct,<br>2) a bunch of fields are filtered if containing `;` and `packaging.markers.Marker` is used to do the real work.<br><br>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.<br><br>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.<br><br>Can we provide a list variable to let the user opt-in the marker evaluation? Something like:<br><br> [tool.sip.bindings.somemodule]<br> evaluate-markers = ["include-dirs", "library-dirs", "libraries"]<br><div><br></div><div> 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:<br></div><div><br></div><div> [tool.sip.metadata]<br> name = "somemodule"</div><div> evaluate-default-markers = true</div><div><br></div><div>Should I move this config into a custom `project.py` or integrate it better into the mainline one (open to suggestions)?</div><div><br></div><div>Cheers,<br></div><div>Matteo<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Dec 12, 2019 at 11:18 AM Phil Thompson <<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 12/12/2019 09:15, Matteo Bertini wrote:<br>
> On Wed, Dec 11, 2019 at 11:04 PM Phil Thompson <br>
> <<a href="mailto:phil@riverbankcomputing.com" target="_blank">phil@riverbankcomputing.com</a>><br>
> wrote:<br>
> <br>
>> On 11/12/2019 15:46, Matteo Bertini wrote:<br>
>> ><br>
>> > I tried using this syntax<br>
>> > <a href="https://www.python.org/dev/peps/pep-0566/#environment-markers" rel="noreferrer" target="_blank">https://www.python.org/dev/peps/pep-0566/#environment-markers</a>:<br>
>> ><br>
>> > libraries = ["usb-1.0; 'linux' in sys_platform"]<br>
>> ><br>
>> > But seems to be unsupported.<br>
>> <br>
>> If you need to do any introspection (ie. you need to write code) then<br>
>> you need a project.py file.<br>
>> <br>
> <br>
> Can you point me to some documentation or example? Searching the <br>
> filename<br>
> gives me a lot of unrelated results.<br>
<br>
<a href="https://www.riverbankcomputing.com/static/Docs/sip/examples.html#package-projects" rel="noreferrer" target="_blank">https://www.riverbankcomputing.com/static/Docs/sip/examples.html#package-projects</a><br>
<br>
> <br>
> Alternatively, is there some interest in supporting the linked<br>
> environment-markers syntax? (or even, if I spend some time on the <br>
> feature,<br>
> are you interested in merging it?)<br>
<br>
I'd consider it. My concern would be that the vast majority of cases <br>
would need a project.py file anyway.<br>
<br>
>> > 2) I tried using paths relative to `pyproject.toml` bus sip fails not<br>
>> > finding my `.h` files (found using the absolute path), what is the best<br>
>> > practice here?<br>
>> <br>
>> Configure 'include_dirs'?<br>
>> <br>
> <br>
> Let me explain, my project is in `/home/matteo/someproject`, with<br>
> `pyproject.toml` and `somename.sip` + `somename.h` in the root of the<br>
> project.<br>
> <br>
> [tool.sip.bindings.somename]<br>
> include-dirs = ["."]<br>
> <br>
> ^^^ fails, instead the absolute path below works:<br>
> <br>
> [tool.sip.bindings.somename]<br>
> include-dirs = ["/home/matteo/someproject"]<br>
<br>
Using ".." might be better as the current directory should be the build <br>
directory which (by default) is a sub-directory of the root directory <br>
(the one containing pyproject.toml). However that would break in the <br>
case with a different build directory.<br>
<br>
The normal thing would be to set include_dirs in project.py based on the <br>
value of the "root_dir" attribute. As I've said, at the moment at least, <br>
a project.py file is needed in all but the most trivial of cases but I'm <br>
open to suggestions as to how that can be improved. For example allowing <br>
you to say something like...<br>
<br>
include-dirs = ["$ROOT_DIR"]<br>
<br>
Phil<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>/ Matteo Bertini</div><div>\ <a href="mailto:naufraghi@develer.com" target="_blank">naufraghi@develer.com</a><br></div></div></div>