Skip to content

Commit

Permalink
Do frozen app check for GEOS before conda env check on macos
Browse files Browse the repository at this point in the history
Resolves #1301
  • Loading branch information
sgillies committed May 3, 2022
1 parent 7a63b45 commit c04f8c6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
6 changes: 4 additions & 2 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Changes
=======

1.8.2 (TBD)
-----------
1.8.2 (2022-05-04)
------------------

- Perform frozen app check for GEOS before conda env check on macos as we
already do on linux (#1301).
- Fix leak of GEOS coordinate sequence in nearest_points reported in #1098.

1.8.1.post1 (2022-02-17)
Expand Down
61 changes: 34 additions & 27 deletions shapely/geos.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ def load_dll(libname, fallbacks=None, mode=DEFAULT_MODE):
libname, fallbacks or []))

_lgeos = None


def exists_conda_env():
"""Does this module exist in a conda environment?"""
return os.path.exists(os.path.join(sys.prefix, 'conda-meta'))


if sys.platform.startswith('linux'):
# Test to see if we have a wheel repaired by auditwheel which contains its
# own libgeos_c. Note: auditwheel 3.1 changed the location of libs.
Expand Down Expand Up @@ -127,36 +128,39 @@ def exists_conda_env():
_lgeos = CDLL(geos_whl_dylib[-1])
LOG.debug("Found GEOS DLL: %r, using it.", _lgeos)

elif hasattr(sys, "frozen"):
try:
# .app file from py2app
alt_paths = [
os.path.join(
os.environ["RESOURCEPATH"], "..", "Frameworks", "libgeos_c.dylib"
)
]
except KeyError:
alt_paths = [
# binary from pyinstaller
os.path.join(sys.executable, "libgeos_c.dylib"),
# .app from cx_Freeze
os.path.join(os.path.dirname(sys.executable), "libgeos_c.1.dylib"),
]
if hasattr(sys, "_MEIPASS"):
alt_paths.append(os.path.join(sys._MEIPASS, "libgeos_c.1.dylib"))

elif exists_conda_env():
# conda package.
_lgeos = CDLL(os.path.join(sys.prefix, 'lib', 'libgeos_c.dylib'))

else:
if hasattr(sys, 'frozen'):
try:
# .app file from py2app
alt_paths = [os.path.join(
os.environ['RESOURCEPATH'], '..', 'Frameworks',
'libgeos_c.dylib')]
except KeyError:
alt_paths = [
# binary from pyinstaller
os.path.join(sys.executable, 'libgeos_c.dylib'),
# .app from cx_Freeze
os.path.join(os.path.dirname(sys.executable), 'libgeos_c.1.dylib')]
if hasattr(sys, '_MEIPASS'):
alt_paths.append(
os.path.join(sys._MEIPASS, 'libgeos_c.1.dylib'))
else:
alt_paths = [
# The Framework build from Kyng Chaos
"/Library/Frameworks/GEOS.framework/Versions/Current/GEOS",
# macports
'/opt/local/lib/libgeos_c.dylib',
# homebrew Intel
'/usr/local/lib/libgeos_c.dylib',
# homebrew Apple Silicon
'/opt/homebrew/lib/libgeos_c.dylib',
]
alt_paths = [
# The Framework build from Kyng Chaos
"/Library/Frameworks/GEOS.framework/Versions/Current/GEOS",
# macports
"/opt/local/lib/libgeos_c.dylib",
# homebrew Intel
"/usr/local/lib/libgeos_c.dylib",
# homebrew Apple Silicon
"/opt/homebrew/lib/libgeos_c.dylib",
]
_lgeos = load_dll('geos_c', fallbacks=alt_paths)

free = CDLL(None).free
Expand All @@ -165,8 +169,10 @@ def exists_conda_env():

elif sys.platform == 'win32':
_conda_dll_path = os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll')

if exists_conda_env() and os.path.exists(_conda_dll_path):
_lgeos = CDLL(_conda_dll_path)

else:
geos_whl_dll = glob.glob(
os.path.abspath(
Expand All @@ -181,6 +187,7 @@ def exists_conda_env():
# CDLL(geos_whl_so[0])
_lgeos = CDLL(geos_whl_dll[-1])
LOG.debug("Found GEOS DLL: %r, using it.", _lgeos)

else:
try:
egg_dlls = os.path.abspath(
Expand Down

0 comments on commit c04f8c6

Please sign in to comment.