Skip to content
Merged
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
43 changes: 39 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
import os, sys
from setuptools import setup, find_packages
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import subprocess

class GfortranExtension(Extension):
def __init__(self, name, sourcedir='', input='', output=''):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
self.input = os.path.join(self.sourcedir, input)
self.output = os.path.join(self.sourcedir, output)

class GfortranBuild(build_ext):
def run(self):
try:
out = subprocess.check_output(['gfortran', '--version'])
except OSError:
raise RuntimeError("gfortran must be installed to build the following extensions: " +
", ".join(e.name for e in self.extensions))

for ext in self.extensions:
self.build_extension(ext)

def build_extension(self, ext):
gfortran_args = ['-fPIC',
'-fdefault-real-8',
'-shared',
'-o',
ext.output]

if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)

env = os.environ.copy()
subprocess.check_call(['gfortran', ext.input] + gfortran_args, cwd=self.build_temp, env=env)

setup(name='glmnet_python',
version = '0.2.2',
version = '1.0.0',
description = 'Python version of glmnet, from Stanford University',
long_description=open('README.md').read(),
url="https://github.com/johnlees/glmnet_python",
Expand All @@ -22,5 +54,8 @@
'Programming Language :: Python :: 3.4',
'Operating System :: Unix',
],
keywords='glm glmnet ridge lasso elasticnet'
)
keywords='glm glmnet ridge lasso elasticnet',
ext_modules=[GfortranExtension('GLMnet', 'glmnet_python',
'GLMnet.f', 'GLMnet.so')],
cmdclass={'build_ext': GfortranBuild},
)