Skip to content

Commit

Permalink
Building GLPK shared library as extension; need to switch to using it…
Browse files Browse the repository at this point in the history
… by default and see if Windows freaks out
  • Loading branch information
mckib2 committed Jul 29, 2020
1 parent a845518 commit cb5c552
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
'''Install scikit-glpk bindings.'''

from setuptools import find_packages, setup
from distutils.core import Extension
import pathlib

GLPK_SRC_DIR = pathlib.Path('glpk-4.65/src')

def scrape_makefile_list(filename, START_TOKEN, END_TOKEN):
with open(filename, 'r', encoding='utf-8') as f:
_contents = f.read()
sidx = _contents.find(START_TOKEN)
eidx = _contents.find(END_TOKEN)
lines = _contents[sidx+len(START_TOKEN):eidx].splitlines()
return [str(_l.replace('\\', '').strip()) for _l in lines]

# Get sources for GLPK
makefile = GLPK_SRC_DIR / 'Makefile.am'
sources = scrape_makefile_list(makefile, 'libglpk_la_SOURCES = \\\n', '\n## eof ##')
sources = [str(GLPK_SRC_DIR / _s) for _s in sources]

# Get include dirs for GLPK
include_dirs = scrape_makefile_list(makefile, 'libglpk_la_CPPFLAGS = \\\n', '\nlibglpk_la_LDFLAGS')
include_dirs = [str(GLPK_SRC_DIR / _d[len('-I($srcdir)/'):]) for _d in include_dirs]


setup(
name='scikit-glpk',
Expand All @@ -15,4 +37,13 @@
keywords='glpk linprog scikit',
install_requires=open('requirements.txt').read().split(),
python_requires='>=3.5',

ext_modules=[
Extension(
'glpk4_65',
sources=sources,
include_dirs=include_dirs,
language='c',
)
],
)

0 comments on commit cb5c552

Please sign in to comment.