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

This makes setup.py work well with Darwin + Homebrew #21

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion libarchive/library.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
import logging
import os
import platform
import json
import subprocess

def _check_homebrew():
if platform.system() == 'Darwin':
try:
# From homebrew on libarchive:
# This formula is keg-only, which means it was not symlinked
# into /usr/local.
#
# macOS already provides this software and installing
# another version in parallel can cause all kinds of
# trouble.
#
# so... let's see if we can't find it ourselves and set the
# envvar
# /Usr/local/opt/libarchive/lib/
libarchive_info = json.loads(
subprocess.check_output(['brew', 'info', '--json=v1',
'libarchive']))
libarchive_version = libarchive_info[0]['installed'][0]['version']
# set the direct dylib envvar
libarchive_path = os.path.join(subprocess.check_output([ 'brew',
'--cellar', 'libarchive'])[:-1], libarchive_version, 'lib',
'libarchive.dylib')
return libarchive_path
except Exception as e:
return ''
else:
return ''

import ctypes
import ctypes.util

_logger = logging.getLogger(__name__)

_FILEPATH = os.environ.get('LA_LIBRARY_FILEPATH', '')
_FILEPATH = os.environ.get('LA_LIBRARY_FILEPATH', _check_homebrew())
if _FILEPATH == '':
_FILEPATH = ctypes.util.find_library('libarchive')
if _FILEPATH is None:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import setuptools
import setuptools.command.install
import os.path

def _pre_install():
print("Verifying that the library is accessible.")

Expand Down