Skip to content

Commit 4b0b332

Browse files
ChrisBarker-NOAAChris Barker
andauthored
Removed kludgy unnecessary adding of lib paths on Windows (#36)
* ugly kludge no longer needed for windows library finding -- at least with conda-forge * cleaned up some lint --------- Co-authored-by: Chris Barker <chris.barker@nos.noaa>
1 parent cd557b2 commit 4b0b332

2 files changed

Lines changed: 6 additions & 44 deletions

File tree

conda_requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ ninja
99
scikit-build-core
1010
cython-cmake
1111
python-build
12+
flake8

py_gd/__init__.py

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,13 @@
1010
from .py_gd import *
1111
"""
1212

13-
import sys
14-
import os
15-
1613
__version__ = "2.3.3"
1714

18-
if sys.platform.startswith('win'):
19-
# This only works for Anaconda / miniconda
20-
# On other systems, logic needs to be added here.
21-
libpath = os.path.join(os.path.split(sys.executable)[0], "Library", "bin")
22-
23-
# UGLY kludge for Windows: load the libgd dll with ctypes so it can be used by the extension
24-
# import ctypes
25-
# # note: need to load up the dependencies, too
26-
# # this is a serious kludge!
27-
# try:
28-
# libpng = ctypes.cdll.LoadLibrary(os.path.join(libpath,'libpng16.dll'))
29-
# zlib = ctypes.cdll.LoadLibrary(os.path.join(libpath,'zlib.dll'))
30-
# libgd = ctypes.cdll.LoadLibrary(os.path.join(libpath,'libgd.dll'))
31-
# except WindowsError as err:
32-
# raise WindowsError("Can't find dlls for libgd, libpng, and libz.\n"
33-
# "This kludge is only written to support Anaconda installs")
34-
35-
# alternative ugly kludge: add lib dir to PATH:
36-
if (os.path.isfile(os.path.join(libpath, 'libpng16.dll')) and
37-
os.path.isfile(os.path.join(libpath, 'zlib.dll')) and
38-
os.path.isfile(os.path.join(libpath, 'libgd.dll'))):
39-
os.environ['PATH'] = libpath + os.pathsep + os.environ['PATH']
40-
41-
# raise RuntimeError("Can't find dlls for libgd, libpng, and libz.\n"
42-
# "This kludge is only written to support Anaconda installs\n",
43-
# "you may need to add some logic for other library locations",
44-
# )
4515
try:
4616
from .py_gd import * # noqa: F401
47-
4817
except ImportError as err:
49-
if str(err).startswith("DLL load failed:"):
50-
if not (os.path.isfile(os.path.join(libpath, 'libpng16.dll')) and
51-
os.path.isfile(os.path.join(libpath, 'zlib.dll')) and
52-
os.path.isfile(os.path.join(libpath, 'libgd.dll'))):
53-
raise RuntimeError("Can't find dlls for libgd, libpng, and libz.\n"
54-
"This kludge is only written to support Anaconda installs\n",
55-
"you may need to add some logic for other library locations",
56-
)
57-
else:
58-
raise
59-
else:
60-
raise
61-
print(err.args)
18+
raise RuntimeError("Can't find dlls for libgd, libpng, and/or libz.\n"
19+
"This system should work with the dependencies from conda-forge\n",
20+
"and the binary wheels provided on PyPI"
21+
"Otherwise, you may need to figure out where they are ...",
22+
) from err

0 commit comments

Comments
 (0)