-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from briling/improve-install
Improve install
- Loading branch information
Showing
3 changed files
with
59 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,61 @@ | ||
from setuptools import setup, find_packages, Extension | ||
import subprocess | ||
import os, tempfile, shutil | ||
|
||
setup( | ||
name='qstack', | ||
version='0.0.0', | ||
description='Stack of codes for dedicated pre- and post-processing tasks for Quantum Machine Learning', | ||
url='https://github.com/lcmd-epfl/Q-stack', | ||
install_requires=[], | ||
packages=find_packages(), | ||
ext_modules=[Extension('manh', | ||
['qstack/regression/lib/manh.c'], | ||
extra_compile_args=['-fopenmp', '-std=gnu11'], | ||
extra_link_args=['-lgomp']) | ||
], | ||
include_package_data=True, | ||
package_data={'': ['spahm/rho/basis_opt/*.bas']}, | ||
) | ||
VERSION="0.0.1" | ||
|
||
def get_git_version_hash(): | ||
"""Get tag/hash of the latest commit. | ||
Thanks to https://gist.github.com/nloadholtes/07a1716a89b53119021592a1d2b56db8""" | ||
try: | ||
p = subprocess.Popen(["git", "describe", "--tags", "--dirty", "--always"], stdout=subprocess.PIPE) | ||
except EnvironmentError: | ||
return VERSION + "+unknown" | ||
version = p.communicate()[0] | ||
print(version) | ||
return VERSION+'+'+version.strip().decode() | ||
|
||
|
||
def check_for_openmp(): | ||
"""Check if there is OpenMP available | ||
Thanks to https://stackoverflow.com/questions/16549893/programatically-testing-for-openmp-support-from-a-python-setup-script""" | ||
omp_test = 'void main() { }' | ||
tmpdir = tempfile.mkdtemp() | ||
curdir = os.getcwd() | ||
os.chdir(tmpdir) | ||
filename = r'test.c' | ||
with open(filename, 'w') as file: | ||
file.write(omp_test) | ||
with open(os.devnull, 'w') as fnull: | ||
result = subprocess.call(['cc', '-fopenmp', '-lgomp', filename], stdout=fnull, stderr=fnull) | ||
os.chdir(curdir) | ||
shutil.rmtree(tmpdir) | ||
return not result | ||
|
||
|
||
def get_requirements(): | ||
fname = f"{os.path.dirname(os.path.realpath(__file__))}/requirements.txt" | ||
with open(fname) as f: | ||
install_requires = f.read().splitlines() | ||
return install_requires | ||
|
||
|
||
if __name__ == '__main__': | ||
openmp_enabled = check_for_openmp() | ||
|
||
setup( | ||
name='qstack', | ||
version=get_git_version_hash(), | ||
description='Stack of codes for dedicated pre- and post-processing tasks for Quantum Machine Learning', | ||
url='https://github.com/lcmd-epfl/Q-stack', | ||
python_requires='==3.9.*', | ||
install_requires=get_requirements(), | ||
packages=setuptools.find_packages(exclude=['tests', 'examples']), | ||
ext_modules=[Extension('qstack.regression.lib.manh', | ||
['qstack/regression/lib/manh.c'], | ||
extra_compile_args=['-fopenmp', '-std=gnu11'] if openmp_enabled else ['-std=gnu11'], | ||
extra_link_args=['-lgomp'] if openmp_enabled else []) | ||
], | ||
include_package_data=True, | ||
package_data={'': ['regression/lib/manh.c', 'spahm/rho/basis_opt/*.bas']}, | ||
) |