Skip to content

Commit

Permalink
A few minor updates
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery committed Nov 21, 2023
1 parent d70f842 commit f7632fe
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 131 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
31 changes: 15 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
pull_request:
branches: [ master ]

env:
CONDA_PREFIX: ${{ github.workspace }}/miniconda3/envs/hexrd

jobs:
pytest:
name: ${{ matrix.config.name }}
Expand All @@ -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 }}
Expand Down Expand Up @@ -56,24 +60,19 @@ 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
run: |
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
working-directory: hexrd
88 changes: 0 additions & 88 deletions install_build_dependencies.py

This file was deleted.

100 changes: 100 additions & 0 deletions scripts/install/install_build_dependencies.py
Original file line number Diff line number Diff line change
@@ -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('<script> <destination')

destination = sys.argv[1]

# Call the functions to download and place the libraries
download_eigen(destination)
download_xsimd(destination)
48 changes: 23 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from pathlib import Path
from setuptools import setup, find_packages, Extension
import subprocess
import sysconfig
import sys

Expand Down Expand Up @@ -38,23 +39,14 @@
else:
compiler_optimize_flags = []

# This a hack to get around the fact that scikit-image on conda-forge doesn't install
# dist info so setuptools can't find it, even though its there, which results in
# pkg_resources.DistributionNotFound, even though the package is available. So we
# only added it if we aren't building with conda.
# appdirs has the same issue.
if os.environ.get('CONDA_BUILD') != '1':
install_reqs.append('scikit-image')
install_reqs.append('appdirs')


# extension for convolution from astropy
def get_convolution_extensions():
c_convolve_pkgdir = Path('hexrd') / 'convolution'

src_files = [str(c_convolve_pkgdir / 'src/convolve.c')]

extra_compile_args=['-UNDEBUG']
extra_compile_args = ['-UNDEBUG']
if not sys.platform.startswith('win'):
extra_compile_args.append('-fPIC')
extra_compile_args += compiler_optimize_flags
Expand All @@ -67,26 +59,32 @@ def get_convolution_extensions():

return [_convolve_ext]


def get_include_path(library_name):
env_var_hint = os.getenv(f"{library_name.upper()}_INCLUDE_DIR")
if env_var_hint is not None and os.path.exists(env_var_hint):
return env_var_hint

conda_include_dir = os.getenv('CONDA_PREFIX')
if conda_include_dir:
conda_include_dir = os.path.join(conda_include_dir, 'include')
full_path = os.path.join(conda_include_dir, library_name)
if os.path.exists(full_path):
return full_path
possible_directories = [
sysconfig.get_path('include'),
"/usr/include",
"/usr/local/include",
]
for directory in possible_directories:
full_path = os.path.join(directory, library_name)
if os.path.exists(full_path):
return full_path
raise Exception(f"The {library_name} library was not found in any known directory.")
full_path = Path(conda_include_dir) / 'include' / library_name
if full_path.exists():
return str(full_path)

build_include_dir = Path(__file__).parent / 'build/include'
full_path = build_include_dir / library_name
if full_path.exists():
return full_path

# If the path doesn't exist, then install it there
scripts_path = Path(__file__).parent / 'scripts'
install_script = scripts_path / 'install/install_build_dependencies.py'

subprocess.run([sys.executable, install_script, str(build_include_dir)])

# It should exist now
return full_path


def get_cpp_extensions():
cpp_transform_pkgdir = Path('hexrd') / 'transforms/cpp_sublibrary'
Expand Down Expand Up @@ -181,7 +179,7 @@ def get_extension_modules():
ext_modules=ext_modules,
packages=find_packages(),
include_package_data=True,
package_data={'':['Anomalous.h5']},
package_data={'': ['Anomalous.h5']},
python_requires='>=3.9',
install_requires=install_reqs
)

0 comments on commit f7632fe

Please sign in to comment.