From f7632feefacdf10da30c44874c9d1465e80ca5e3 Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Mon, 20 Nov 2023 18:57:44 -0600 Subject: [PATCH] A few minor updates Signed-off-by: Patrick Avery --- .github/workflows/package.yml | 3 +- .github/workflows/test.yml | 31 +++--- install_build_dependencies.py | 88 --------------- scripts/install/install_build_dependencies.py | 100 ++++++++++++++++++ setup.py | 48 ++++----- 5 files changed, 139 insertions(+), 131 deletions(-) delete mode 100644 install_build_dependencies.py create mode 100755 scripts/install/install_build_dependencies.py diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index bdfebab8c..a728867b6 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -50,9 +50,8 @@ jobs: conda config --set solver libmamba conda activate hexrd - conda install --override-channels -c conda-forge anaconda-client conda-build conda pybind11 + conda install --override-channels -c conda-forge anaconda-client conda-build conda - python install_build_dependencies.py # This is need to ensure ~/.profile or ~/.bashrc are used so the activate # command works. shell: bash -l {0} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c5fd898ff..ea3cd94ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,9 +6,6 @@ on: pull_request: branches: [ master ] -env: - CONDA_PREFIX: ${{ github.workspace }}/miniconda3/envs/hexrd - jobs: pytest: name: ${{ matrix.config.name }} @@ -18,14 +15,21 @@ jobs: matrix: python-version: [3.11] config: - - {name: "Linux", os: ubuntu-latest} - - {name: "MacOSX", os: macos-latest} - - {name: "Windows", os: windows-latest} - + - { + name: "Linux", + os: ubuntu-latest + } + - { + name: "MacOSX", + os: macos-latest + } + - { + name: "Windows", + os: windows-latest + } defaults: run: shell: bash - steps: - name: Set up Python ${{ matrix.python-version }} @@ -56,9 +60,9 @@ jobs: pip install fabio==0.12 if: ${{ matrix.config.os == 'macos-latest'}} - - name: Install Build Dependencies + - name: Install HEXRD run: | - python install_build_dependencies.py + pip install . working-directory: hexrd - name: Install requirements-dev.txt @@ -66,14 +70,9 @@ jobs: pip install -r tests/requirements-dev.txt working-directory: hexrd - - name: Install HEXRD - run: | - pip install . - working-directory: hexrd - - name: Run tests env: HEXRD_EXAMPLE_REPO_PATH: ${{ github.workspace }}/examples run: | pytest -s tests/ - working-directory: hexrd \ No newline at end of file + working-directory: hexrd diff --git a/install_build_dependencies.py b/install_build_dependencies.py deleted file mode 100644 index d9fc0eba7..000000000 --- a/install_build_dependencies.py +++ /dev/null @@ -1,88 +0,0 @@ -import hashlib -import os -from pathlib import Path -import shutil -import tarfile -import tempfile -import urllib.request - -# Define where to place the libraries -CONDA_INCLUDE_PATH = os.path.join(os.getenv('CONDA_PREFIX'), 'include') - -def get_file_md5(filepath): - with open(filepath, 'rb') as rf: - return hashlib.md5(rf.read()).hexdigest() - -def download_and_extract_tgz(url, md5sum, path): - temp_dir = tempfile.gettempdir() - temp_file = Path(temp_dir) / '_hexrd_temp_file' - if temp_file.exists(): - temp_file.unlink() - - urllib.request.urlretrieve(url, temp_file) - - file_md5sum = get_file_md5(temp_file) - if file_md5sum != md5sum: - raise Exception( - f'md5sum "{file_md5sum}" of file from "{url}" ' - f'does not match expected md5sum "{md5sum}"' - ) - - os.makedirs(path, exist_ok=True) - with tarfile.open(temp_file, 'r:gz') as tarball: - tarball.extractall(path) - - temp_file.unlink() - -def download_xsimd(path): - url = 'https://github.com/xtensor-stack/xsimd/archive/refs/tags/7.6.0.tar.gz' - md5sum = '6e52c2af8b3cb4688993a0e70825f4e8' - out_dir_name = 'xsimd-7.6.0' - - with tempfile.TemporaryDirectory() as temp_dir: - download_and_extract_tgz(url, md5sum, temp_dir) - - target_path = Path(path) / 'xsimd' - if target_path.exists(): - shutil.rmtree(target_path) - - os.makedirs(path, exist_ok=True) - shutil.move(str(Path(temp_dir) / out_dir_name / 'include/xsimd'), str(Path(path) / 'xsimd/xsimd')) - - return str(target_path) - - -def download_eigen(path): - url = 'https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz' - md5sum = '4c527a9171d71a72a9d4186e65bea559' - out_dir_name = 'eigen-3.4.0' - - download_and_extract_tgz(url, md5sum, path) - - target_path = Path(path) / 'eigen3' - if target_path.exists(): - shutil.rmtree(target_path) - - shutil.move(str(Path(path) / out_dir_name), str(Path(path) / 'eigen3')) - - return str(target_path) - -def download_pybind11(path): - url = 'https://github.com/pybind/pybind11/archive/refs/tags/v2.11.0.tar.gz' - md5sum = '90c4946e87c64d8d8fc0ae4edf35d780' - out_dir_name = 'pybind11-2.11.0' - - download_and_extract_tgz(url, md5sum, path) - - target_path = Path(path) / 'pybind11' - if target_path.exists(): - shutil.rmtree(target_path) - - shutil.move(str(Path(path) / out_dir_name), str(Path(path) / 'pybind11')) - - return str(target_path) - -# Call the functions to download and place the libraries -download_eigen(CONDA_INCLUDE_PATH) -download_xsimd(CONDA_INCLUDE_PATH) -download_pybind11(CONDA_INCLUDE_PATH) diff --git a/scripts/install/install_build_dependencies.py b/scripts/install/install_build_dependencies.py new file mode 100755 index 000000000..983013deb --- /dev/null +++ b/scripts/install/install_build_dependencies.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 + +import hashlib +import os +from pathlib import Path +import shutil +import tarfile +import tempfile +import urllib.request + + +def get_file_md5(filepath): + with open(filepath, 'rb') as rf: + return hashlib.md5(rf.read()).hexdigest() + + +def download_and_extract_tgz(url, md5sum, path): + temp_dir = tempfile.gettempdir() + temp_file = Path(temp_dir) / '_hexrd_temp_file' + if temp_file.exists(): + temp_file.unlink() + + urllib.request.urlretrieve(url, temp_file) + + file_md5sum = get_file_md5(temp_file) + if file_md5sum != md5sum: + raise Exception( + f'md5sum "{file_md5sum}" of file from "{url}" ' + f'does not match expected md5sum "{md5sum}"' + ) + + os.makedirs(path, exist_ok=True) + with tarfile.open(temp_file, 'r:gz') as tarball: + tarball.extractall(path) + + temp_file.unlink() + + +def download_xsimd(path): + url = 'https://github.com/xtensor-stack/xsimd/archive/refs/tags/7.6.0.tar.gz' # noqa + md5sum = '6e52c2af8b3cb4688993a0e70825f4e8' + out_dir_name = 'xsimd-7.6.0' + + with tempfile.TemporaryDirectory() as temp_dir: + download_and_extract_tgz(url, md5sum, temp_dir) + + target_path = Path(path) / 'xsimd' + if target_path.exists(): + shutil.rmtree(target_path) + + os.makedirs(path, exist_ok=True) + shutil.move(str(Path(temp_dir) / out_dir_name / 'include/xsimd'), + str(Path(path) / 'xsimd/xsimd')) + + return str(target_path) + + +def download_eigen(path): + url = 'https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz' # noqa + md5sum = '4c527a9171d71a72a9d4186e65bea559' + out_dir_name = 'eigen-3.4.0' + + download_and_extract_tgz(url, md5sum, path) + + target_path = Path(path) / 'eigen3' + if target_path.exists(): + shutil.rmtree(target_path) + + shutil.move(str(Path(path) / out_dir_name), str(Path(path) / 'eigen3')) + + return str(target_path) + + +def download_pybind11(path): + url = 'https://github.com/pybind/pybind11/archive/refs/tags/v2.11.0.tar.gz' + md5sum = '90c4946e87c64d8d8fc0ae4edf35d780' + out_dir_name = 'pybind11-2.11.0' + + download_and_extract_tgz(url, md5sum, path) + + target_path = Path(path) / 'pybind11' + if target_path.exists(): + shutil.rmtree(target_path) + + shutil.move(str(Path(path) / out_dir_name), str(Path(path) / 'pybind11')) + + return str(target_path) + + +if __name__ == '__main__': + import sys + + if len(sys.argv) < 2: + sys.exit('