Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current hard-coded pycairo flags in setup.py hinder installs where Python and pycairo have different prefixes #234

Open
jwilges opened this issue Nov 13, 2020 · 1 comment

Comments

@jwilges
Copy link

jwilges commented Nov 13, 2020

Issue

As in the title, the current hard-coded pycairo flags in setup.py hinder installs where Python and pycairo have different prefixes.

Clarification

In a nutshell, if pycairo resides outside of Python's sys.exec_prefix, the current setup.py behavior is incorrect.

See this Dockerfile gist for an example of this issue in a python:3.8-slim-based container that uses Debian's python3-cairo-dev package to provide pycairo.

Reference

Current setup.py:

if os.environ.get("PYCAIRO", "false") == "true":
    try:
        extra_comp_args.append('-DHAVE_PYCAIRO')
        print("-I%s/include/pycairo".format(sys.exec_prefix))
        extra_comp_args.append("-I{0}/include/pycairo".format(sys.exec_prefix))
        #extra_comp_args.extend(check_output(["pkg-config", '--cflags', 'pycairo']).strip().split(' '))
        #linkflags.extend(check_output(["pkg-config", '--libs', 'pycairo']).strip().split(' '))
    except:
        raise Exception("Failed to find compiler options for pycairo")

It looks like someone tried to leverage pkg-config at some point but ultimately disabled it.

Suggestion

I am attaching a patch that aims to give us the best of both worlds: flags sourced from pkg-config when viable with backward compatible fallback flag values when pkg-config detection fails.

This could be rolled up into a slightly better generic pkg-config pattern if other dependencies could benefit from similar behavior but I made the patch solely for pycairo since that was the only preexisting use case of pkg-config in setup.py.

jwilges added a commit to jwilges/python-mapnik that referenced this issue Nov 13, 2020
Allow pkg-config to detect flags for either:
- `py3cairo`, or
- `pycairo`

The previous method of always using `sys.exec_prefix` to locate pycairo
headers is insufficient on systems where Python and pycairo have
different install prefixes (e.g. `/usr` vs. `/usr/local`).

For backward compatibility, the previous method is still the default
behavior when `pkg-config` cannot detect appropriate flags at runtime.

Resolves issue mapnik#234.
jwilges added a commit to jwilges/python-mapnik that referenced this issue Nov 13, 2020
Allow pkg-config to detect flags for either:
- `py3cairo`, or
- `pycairo`

The previous method of always using `sys.exec_prefix` to locate pycairo
headers is insufficient on systems where Python and pycairo have
different install prefixes (e.g. `/usr` vs. `/usr/local`).

For backward compatibility, the previous method is still the default
behavior when `pkg-config` cannot detect appropriate flags at runtime.

Resolves issue mapnik#234
@tobwen
Copy link

tobwen commented Feb 6, 2022

Thanks for this patch, but maybe we should also expose this as a system variable. I've installed pycairo in a venv and it doesn't come with a pkg-config configuration. So neither the original one nor your code finds the files inside the venv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants