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

pikepdf 5.1.0 and macports: appears to require a homebrew install? #322

Closed
jowens opened this issue Mar 21, 2022 · 6 comments
Closed

pikepdf 5.1.0 and macports: appears to require a homebrew install? #322

jowens opened this issue Mar 21, 2022 · 6 comments

Comments

@jowens
Copy link

jowens commented Mar 21, 2022

The current macports version is 5.1.0 but (AFAICT) on an ARM MacBook Pro, building 5.1.0 fails because setup.py assumes that there's a homebrew install present.

MacPorts install log snippet:

:debug:build system:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_python_py-pikepdf/py310-pikepdf/work/pikepdf-5.1.0" && /opt/local/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 setup.py --no-user-cfg build -j10
:info:build Traceback (most recent call last):
:info:build   File "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_python_py-pikepdf/py310-pikepdf/work/pikepdf-5.1.0/setup.py", line 35, in <module>
:info:build     raise FileNotFoundError(extra_path)
:info:build FileNotFoundError: /opt/homebrew/include
:info:build Command failed:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_python_py-pikepdf/py310-pikepdf/work/pikepdf-5.1.0" && /opt/local/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10 setup.py --no-user-cfg build -j10
:info:build Exit code: 1
:error:build Failed to build py310-pikepdf: command execution failed
:debug:build Error code: CHILDSTATUS 81667 1
:debug:build Backtrace: command execution failed
:debug:build     while executing
:debug:build "system {*}$notty {*}$callback {*}$nice $fullcmdstring"
:debug:build     invoked from within
:debug:build "command_exec -callback portprogress::target_progress_callback build"
:debug:build     (procedure "portbuild::build_main" line 8)
:debug:build     invoked from within
:debug:build "$procedure $targetname"
:error:build See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_python_py-pikepdf/py310-pikepdf/main.log for details.

setup.py snippet (what happens if there is no /opt/homebrew?)

qpdf_source_tree = environ.get('QPDF_SOURCE_TREE', '')
if qpdf_source_tree:
    # Point this to qpdf source tree built with shared libaries
    extra_includes.append(join(qpdf_source_tree, 'include'))
    extra_library_dirs.append(join(qpdf_source_tree, 'libqpdf/build/.libs'))
if 'bsd' in sys.platform:
    extra_includes.append('/usr/local/include')
elif 'darwin' in sys.platform and machine() == 'arm64':
    extra_includes.append('/opt/homebrew/include')
    extra_library_dirs.append('/opt/homebrew/lib')

with the error happening here (setup.py line 35):

for extra_path in chain([qpdf_source_tree], extra_includes, extra_library_dirs):
    if extra_path and not exists(extra_path):
        raise FileNotFoundError(extra_path)
jowens referenced this issue in macports/macports-ports Mar 21, 2022
Schamschula added a commit to macports/macports-ports that referenced this issue Mar 22, 2022
@jbarlow83
Copy link
Member

What's the proper way to ask macports if it's installed and where to look for libraries/include headers?

@jmroot
Copy link

jmroot commented Mar 26, 2022

The default prefix for MacPorts is /opt/local, but it could be installed in any prefix, and there could be multiple MacPorts installations on one system. You could look at e.g. shutil.which('port') to find what is likely to be the user's primary MacPorts installation, but it's much better for deterministic building if you allow specifying exactly where qpdf is, and only try to automatically locate it if that hasn't been done.

MacPorts itself adds appropriate -I and -L options to the CFLAGS and LDFLAGS environment variables when building python modules, so things should generally just work in that context.

@jbarlow83
Copy link
Member

pip install pikepdf, outside of a package manager, needs to be able to do a source build automatically, and without setting environment variables. That's the expectation users of pip have - people who quite possibly are trying to install some other library with pikepdf as a dependency, and don't have the technical skills of package managers. In short, I need some shims to help out end users, particularly non-x64 users who might have to do source builds.

Is there any environment variable that says "this is a Macports build environment"? I could extend to generally say "if we are being built by a package manager, they know what they are doing, so don't do anything special to discover missing dependencies".

@jmroot
Copy link

jmroot commented Mar 26, 2022

pip install pikepdf, outside of a package manager, needs to be able to do a source build automatically, and without setting environment variables.

Sure, I understand that, and it's fine to try to discover where things are if you haven't been told explicitly.

Is there any environment variable that says "this is a Macports build environment"?

No environment variable specifically. There are a number of telltale signs (like the path of the build directory), but nothing that is guaranteed not to change. Usually if a package needs to care whether it's being built by MacPorts or not, that would mean that MacPorts isn't doing its job well enough.

I could extend to generally say "if we are being built by a package manager, they know what they are doing, so don't do anything special to discover missing dependencies".

That sounds like a better approach, though it could equally apply to users who know what they are doing as well as package managers. Some variable or flag that says "this is where qpdf is located, no need to search for it" would be very helpful.

@Schamschula
Copy link

For the record, MacPorts has patched out the Homebrew specific code.

I first patched it to replace the path with the correct one. See: macports/macports-ports@d5f5499

However, @ryandesign pointed out that this path is redundant, and I subsequently entirely removed the elseif section.
See: macports/macports-ports@5461a9a

@jbarlow83
Copy link
Member

Fixed in 5.1.1

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

4 participants