Skip to content

Commit

Permalink
Merge pull request #30 from briling/improve-install
Browse files Browse the repository at this point in the history
Improve install
  • Loading branch information
briling authored Apr 15, 2024
2 parents 3177fc9 + b0c5fdf commit eeb1faa
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 20 deletions.
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ attrs==21.4.0
certifi==2021.10.8
h5py==3.6.0
iniconfig==1.1.1
mkl-fft==1.3.1
mkl-service==2.4.0
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.0.6
pyscf==2.0.1
pytest==6.2.5
numpy===1.22.3
scipy==1.7.3
scipy==1.10
toml==0.10.2
scikit-learn==0.24.2
ase==3.22
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

73 changes: 58 additions & 15 deletions setup.py
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']},
)

0 comments on commit eeb1faa

Please sign in to comment.