From 66d0e22639c34bf773fc18b4ee5ca92d14c67d18 Mon Sep 17 00:00:00 2001 From: Ksenia Briling <30023616+briling@users.noreply.github.com> Date: Thu, 8 Feb 2024 23:20:06 +0100 Subject: [PATCH 1/7] Try to get version automatically --- setup.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 6cb1694..1c2bf08 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,19 @@ from setuptools import setup, find_packages, Extension +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: + print("Cannot run git to get a version number") + return "0.0.0-unknown" + version = p.communicate()[0] + return version.strip() + setup( name='qstack', - version='0.0.0', + 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', install_requires=[], From 13d964d735477ebf5cf876c850d7af4591073fa9 Mon Sep 17 00:00:00 2001 From: Ksenia Briling <30023616+briling@users.noreply.github.com> Date: Thu, 8 Feb 2024 23:25:01 +0100 Subject: [PATCH 2/7] Update setup.py --- setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.py b/setup.py index 1c2bf08..86c0b7c 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,6 @@ from setuptools import setup, find_packages, Extension +import subprocess + def get_git_version_hash(): """Get tag/hash of the latest commit. @@ -11,6 +13,7 @@ def get_git_version_hash(): version = p.communicate()[0] return version.strip() + setup( name='qstack', version=get_git_version_hash(), From e7a4a8c9f7563099110dbcdbd20fa9ec7068643a Mon Sep 17 00:00:00 2001 From: Ksenia Date: Thu, 8 Feb 2024 23:50:52 +0100 Subject: [PATCH 3/7] Fix --- setup.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 86c0b7c..47e0195 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ from setuptools import setup, find_packages, Extension import subprocess +VERSION="0.0.1" def get_git_version_hash(): """Get tag/hash of the latest commit. @@ -8,10 +9,10 @@ def get_git_version_hash(): try: p = subprocess.Popen(["git", "describe", "--tags", "--dirty", "--always"], stdout=subprocess.PIPE) except EnvironmentError: - print("Cannot run git to get a version number") - return "0.0.0-unknown" + return VERSION + "+unknown" version = p.communicate()[0] - return version.strip() + print(version) + return VERSION+'+'+version.strip().decode() setup( From 3d999170c0fab6a7aacf7912a6838fe0a2f9e79f Mon Sep 17 00:00:00 2001 From: Ksenia Date: Fri, 9 Feb 2024 11:49:36 +0100 Subject: [PATCH 4/7] Do not install examples/ and tests/ --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 47e0195..ab9ced4 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def 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', install_requires=[], - packages=find_packages(), + packages=setuptools.find_packages(exclude=['tests', 'examples']), ext_modules=[Extension('manh', ['qstack/regression/lib/manh.c'], extra_compile_args=['-fopenmp'], From 1c4afedd02b967e0116e94159de06211157af62d Mon Sep 17 00:00:00 2001 From: Ksenia Date: Fri, 9 Feb 2024 12:00:24 +0100 Subject: [PATCH 5/7] Fix installation of binary extensions --- setup.cfg | 2 -- setup.py | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 2d16412..0000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[build_ext] -build-lib=./qstack/regression/lib/ diff --git a/setup.py b/setup.py index ab9ced4..da1a46c 100644 --- a/setup.py +++ b/setup.py @@ -22,10 +22,12 @@ def get_git_version_hash(): url='https://github.com/lcmd-epfl/Q-stack', install_requires=[], packages=setuptools.find_packages(exclude=['tests', 'examples']), - ext_modules=[Extension('manh', + ext_modules=[Extension('qstack.regression.lib.manh', ['qstack/regression/lib/manh.c'], extra_compile_args=['-fopenmp'], extra_link_args=['-lgomp']) ], + include_package_data=True, + package_data={'': ['regression/lib/manh.c']}, ) From ac79a87b97bea04c4087a2d27f7682267aa44887 Mon Sep 17 00:00:00 2001 From: Ksenia Date: Fri, 9 Feb 2024 12:23:16 +0100 Subject: [PATCH 6/7] Build C extensions with OpenMP only if available --- setup.py | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index da1a46c..f0cf876 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,10 @@ from setuptools import setup, find_packages, Extension import subprocess +import os, tempfile, shutil VERSION="0.0.1" + def get_git_version_hash(): """Get tag/hash of the latest commit. Thanks to https://gist.github.com/nloadholtes/07a1716a89b53119021592a1d2b56db8""" @@ -15,19 +17,38 @@ def get_git_version_hash(): return VERSION+'+'+version.strip().decode() -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', - install_requires=[], - packages=setuptools.find_packages(exclude=['tests', 'examples']), - ext_modules=[Extension('qstack.regression.lib.manh', - ['qstack/regression/lib/manh.c'], - extra_compile_args=['-fopenmp'], - extra_link_args=['-lgomp']) - ], - include_package_data=True, - package_data={'': ['regression/lib/manh.c']}, -) +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 + + +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', + install_requires=[], + packages=setuptools.find_packages(exclude=['tests', 'examples']), + ext_modules=[Extension('qstack.regression.lib.manh', + ['qstack/regression/lib/manh.c'], + extra_compile_args=['-fopenmp'] if openmp_enabled else [], + extra_link_args=['-lgomp'] if openmp_enabled else []) + ], + include_package_data=True, + package_data={'': ['regression/lib/manh.c']}, + ) From 0284625c8290241b1136e13c87ec8a93fcdab88f Mon Sep 17 00:00:00 2001 From: Ksenia Date: Fri, 9 Feb 2024 18:01:34 +0100 Subject: [PATCH 7/7] Use requirements.txt in setup.py --- requirements.txt | 4 +--- setup.py | 10 +++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5e77066..1145e9a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,8 +2,6 @@ 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 @@ -11,7 +9,7 @@ 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 equistore-core @ git+https://github.com/lab-cosmo/equistore.git@e5b9dc365369ba2584ea01e9d6a4d648008aaab8#subdirectory=python/equistore-core diff --git a/setup.py b/setup.py index f0cf876..8e65c9d 100644 --- a/setup.py +++ b/setup.py @@ -34,6 +34,13 @@ def check_for_openmp(): 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() @@ -42,7 +49,8 @@ def check_for_openmp(): 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', - install_requires=[], + 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'],