From 89a4da4fc5a5f4f443bf8989d74be45c85d3da09 Mon Sep 17 00:00:00 2001 From: adigitoleo Date: Fri, 23 Jun 2023 10:50:56 +1000 Subject: [PATCH 1/3] dev: Add dev install script Convenient development version installer for unix shell --- tools/venv_install.sh | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 tools/venv_install.sh diff --git a/tools/venv_install.sh b/tools/venv_install.sh new file mode 100755 index 00000000..0bf84aaf --- /dev/null +++ b/tools/venv_install.sh @@ -0,0 +1,44 @@ +#!/bin/env sh +set -eu +readonly SCRIPTNAME="${0##*/}" +usage() { + printf 'Usage: %s [-h]\n' "$SCRIPTNAME" + printf ' %s [-u]\n' "$SCRIPTNAME" +} +helpf() { + echo 'Options:' + echo '-u Update pydrex and dependencies in the venv' + echo ' and compile new requirements.txt' + echo + echo 'Install local pydrex tree in a Python venv (virtual environment),' + echo 'in editable mode with development dependencies.' + echo 'This script should be executed in a context which has access to a' + echo 'Python binary of the appropriate version (check requires-python in' + echo 'pyproject.toml). If the necessary version is not available on your' + echo 'system, you can install it using pyenv' + echo '(https://github.com/pyenv/pyenv) and this script will prefer the' + echo 'local pyenv binary over the system one.' + echo + echo 'Backups of the last requirements.txt are stored in requirements.bak' +} + +upgrade() { + . .venv-"${PWD##*/}"/bin/activate + [ -f requirements.txt ] && mv -i requirements.txt requirements.bak + pip install --upgrade pip pip-tools && pip-compile --resolver=backtracking && pip-sync + pip install -e "$PWD"\[dev\] +} + +if [ $# -eq 0 ]; then # first install + [ -d .venv-"${PWD##*/}" ] && exit 0 # venv already exists, no-op + "$(2>/dev/null pyenv prefix||printf '/usr')"/bin/python -m venv .venv-"${PWD##*/}" + upgrade +fi + +while getopts "hu" OPT; do + case $OPT in + h ) usage && helpf; exit 0;; + u ) upgrade;; + * ) usage; exit 1;; + esac +done From d23b559b63021e65badb4493d3c8e459309ac5de Mon Sep 17 00:00:00 2001 From: adigitoleo Date: Sat, 22 Jul 2023 14:50:18 +1000 Subject: [PATCH 2/3] dev: Fix h5part reader script --- tools/h5part_reader.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tools/h5part_reader.py b/tools/h5part_reader.py index 7f97b932..0bbb0d96 100755 --- a/tools/h5part_reader.py +++ b/tools/h5part_reader.py @@ -17,8 +17,7 @@ import h5py import numpy as np -from pydrex import core as _core -from pydrex import minerals as _minerals +from pydrex import MineralFabric, MineralPhase, Mineral def _get_args() -> argparse.Namespace: @@ -76,14 +75,14 @@ def _get_args() -> argparse.Namespace: for particle_id in file["Step#0/id"][:]: option_map = { - "olivine": _core.MineralPhase.olivine, - "enstatite": _core.MineralPhase.enstatite, - "A": _minerals.OlivineFabric.A, - "B": _minerals.OlivineFabric.B, - "C": _minerals.OlivineFabric.C, - "D": _minerals.OlivineFabric.D, - "E": _minerals.OlivineFabric.E, - "N": _minerals.EnstatiteFabric.A, + "olivine": MineralPhase.olivine, + "enstatite": MineralPhase.enstatite, + "A": MineralFabric.olivine_A, + "B": MineralFabric.olivine_B, + "C": MineralFabric.olivine_C, + "D": MineralFabric.olivine_D, + "E": MineralFabric.olivine_E, + "N": MineralFabric.enstatite_AB, } # Temporary data arrays. @@ -115,7 +114,7 @@ def _get_args() -> argparse.Namespace: _postfix = str(particle_id) _fractions = list(fractions) _orientations = list(orientations) - mineral = _minerals.Mineral( + mineral = Mineral( phase=option_map[args.fabric], fabric=option_map[args.phase], n_grains=args.ngrains, From 0ab079037e3fdeb15aeb3eeb1d45dca54c688528 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Jul 2023 04:56:29 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tools/h5part_reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/h5part_reader.py b/tools/h5part_reader.py index 0bbb0d96..82d25aa3 100755 --- a/tools/h5part_reader.py +++ b/tools/h5part_reader.py @@ -17,7 +17,7 @@ import h5py import numpy as np -from pydrex import MineralFabric, MineralPhase, Mineral +from pydrex import Mineral, MineralFabric, MineralPhase def _get_args() -> argparse.Namespace: