From 410451d801c20776d19647c8ac6c6907b03ef84e Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Fri, 10 Jan 2025 13:04:37 +0000 Subject: [PATCH 1/3] Don't strip second comment layers This was intended to pass comments with subsequent selectors through, but was stripping everything. Don't do that. --- .github/parse_dependencies.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/parse_dependencies.py b/.github/parse_dependencies.py index 2a8ece864..c4658fe62 100644 --- a/.github/parse_dependencies.py +++ b/.github/parse_dependencies.py @@ -95,12 +95,6 @@ def _merge_dependency_lists(source, merge_into): indices[pkg] = len(merge_into) - 1 -# def _merge_dependency_dictionaries(sources): -# # type: (list[dict[str, Dependency]]) -> dict[str, Dependency] -# """Merge multiple parsed dependency dictionaries into one.""" -# Evidently WIP? - - class DependencySelectorParser(object): """ Parse simple conda-build selectors syntax, with optional variables. @@ -143,13 +137,12 @@ def preprocess(self, data): output_lines = [] for line in data.splitlines(): match = re_selector.search(line) - if match: if self._parse_expression(match.group(1)): - output_lines.append(line) - elif re_pin.search(line): - # Ignore pin_compatible dependencies - continue + output_lines.append(line[: match.start()].rstrip()) + # elif re_pin.search(line): + # # Ignore pin_compatible dependencies + # continue else: output_lines.append(line) return "\n".join(output_lines) @@ -172,9 +165,10 @@ def parse_file(self, filename): output = {} # type: Dependencies current_section = None # type: SectionName | None for n, line in enumerate(data.splitlines()): - if "#" in line: - line = line[: line.index("#")] line = line.strip() + # Ignore pure comment lines + if line.lstrip().startswith("#"): + continue if line.endswith(":"): new_section = line[:-1].strip() assert new_section in VALID_SECTIONS From 890d7e127e43bd655262c8c5e4b970c9718e4946 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Fri, 10 Jan 2025 13:08:32 +0000 Subject: [PATCH 2/3] Generating meta --- .github/meta.yaml.template | 64 ++++++++++++++++++++++++++++++++++ .github/prepare_conda_build.py | 56 +++++++++++++++++++++++++++++ build.bat | 0 build.sh | 0 4 files changed, 120 insertions(+) create mode 100644 .github/meta.yaml.template create mode 100644 .github/prepare_conda_build.py create mode 100644 build.bat create mode 100644 build.sh diff --git a/.github/meta.yaml.template b/.github/meta.yaml.template new file mode 100644 index 000000000..0ad554e37 --- /dev/null +++ b/.github/meta.yaml.template @@ -0,0 +1,64 @@ +{% set name = "dxtbx" %} +{% set version = "3.24.0.dev0" %} + +package: + name: {{ name|lower }} + version: {{ version }} + +source: + path: . + +build: + skip: true # [py<10] + number: 0 + entry_points: + - cxi.image2pickle = dxtbx.command_line.image2pickle:run + - cxi.image_average = dxtbx.command_line.image_average:run + - dev.dxtbx.debug_memory = dxtbx.command_line.debug_memory:run + - dev.dxtbx.read_sequence = dxtbx.command_line.read_sequence:run + - dxtbx.any2nexus = dxtbx.command_line.any2nexus:run + - dxtbx.depends_on = dxtbx.command_line.depends_on:run + - dxtbx.detector_superpose = dxtbx.command_line.detector_superpose:run + - dxtbx.display_parallax_correction = dxtbx.command_line.display_parallax_correction:run + - dxtbx.dlsnxs2cbf = dxtbx.command_line.dlsnxs2cbf:run + - dxtbx.image2pickle = dxtbx.command_line.image2pickle:run + - dxtbx.image_average = dxtbx.command_line.image_average:run + - dxtbx.install_format = dxtbx.command_line.install_format:run + - dxtbx.overload = dxtbx.command_line.overload:run + - dxtbx.plot_detector_models = dxtbx.command_line.plot_detector_models:run + - dxtbx.print_header = dxtbx.command_line.print_header:run + - dxtbx.print_matching_images = dxtbx.command_line.print_matching_images:run + - dxtbx.radial_average = dxtbx.command_line.radial_average:run + - dxtbx.saturation = dxtbx.command_line.saturation:run + - dxtbx.show_mask_info = dxtbx.command_line.show_mask_info:run + - dxtbx.show_matching_formats = dxtbx.command_line.show_matching_formats:run + - dxtbx.show_registry = dxtbx.command_line.show_registry:run + +requirements: + $REQUIRES + +test: + source_files: + - dxtbx/tests + - dxtbx/conftest.py + requires: + $TEST_REQUIRES + imports: + - dxtbx.ext + commands: + - pytest $SRC_DIR/dxtbx/tests --regression # [not win] + - pytest %SRC_DIR%/dxtbx/tests --regression # [win] + - pip check + +about: + home: https://github.com/cctbx/dxtbx + license: BSD-3-Clause + license_family: BSD + license_file: dxtbx/LICENSE.txt + summary: Diffraction Experiment Toolbox + description: | + A cctbx-style toolbox to describe single-crystal diffraction experiments, + where a monochromatic beam is used to illuminate a sample which is rotated + during the exposure and diffraction recorded on a flat area detector. + doc_url: https://dials.github.io/documentation/index.html + dev_url: https://github.com/cctbx/dxtbx diff --git a/.github/prepare_conda_build.py b/.github/prepare_conda_build.py new file mode 100644 index 000000000..f7bfdc6ee --- /dev/null +++ b/.github/prepare_conda_build.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +from __future__ import annotations + +import shlex +import subprocess +import sys +import textwrap +from pathlib import Path + +template = Path(__file__).parent.joinpath("meta.yaml.template").read_text() + + +# Get the indents +def _get_indent_on_line_containing(text: str): + lines = template.splitlines() + for num, line in enumerate(lines): + if text in lines[num]: + break + else: + raise ValueError(f"Could not find {text} in template") + + return len(line) - len(line.lstrip()) + + +# Work out how much we need to indent the requirement sections +DEPS_INDENT = _get_indent_on_line_containing("$REQUIRES") +TEST_INDENT = _get_indent_on_line_containing("$TEST_REQUIRES") + + +def _run_parser(*args): + # Generate the dependency sections + cmd = [ + sys.executable, + Path(__file__).parent / "parse_dependencies.py", + Path(__file__).parent.parent / "dependencies.yaml", + "--conda-build", + *args, + ] + cmd = [str(x) for x in cmd] + print(" + " + shlex.join(cmd)) + proc = subprocess.run(cmd, capture_output=True, check=True, text=True) + return proc.stdout + + +deps = _run_parser("--build", "--host", "--run") +deps_test = textwrap.dedent("\n".join(_run_parser("--test").splitlines()[1:])) + +template = template.replace( + "$REQUIRES", textwrap.indent(deps, " " * DEPS_INDENT).lstrip() +) +template = template.replace( + "$TEST_REQUIRES", textwrap.indent(deps_test, " " * TEST_INDENT).lstrip() +) +out_file = Path(__file__).parent.parent / "meta.yaml" +out_file.write_text(template) +print(f"Written to {out_file}") diff --git a/build.bat b/build.bat new file mode 100644 index 000000000..e69de29bb diff --git a/build.sh b/build.sh new file mode 100644 index 000000000..e69de29bb From b84c141a4c5815ba5437674d506deb195f7f04f7 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Fri, 10 Jan 2025 15:10:23 +0000 Subject: [PATCH 3/3] Add build script --- .github/prepare_conda_build.py | 12 ++++++++++-- build.sh | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/prepare_conda_build.py b/.github/prepare_conda_build.py index f7bfdc6ee..261291dd5 100644 --- a/.github/prepare_conda_build.py +++ b/.github/prepare_conda_build.py @@ -37,8 +37,16 @@ def _run_parser(*args): *args, ] cmd = [str(x) for x in cmd] - print(" + " + shlex.join(cmd)) - proc = subprocess.run(cmd, capture_output=True, check=True, text=True) + try: + proc = subprocess.run( + cmd, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT + ) + except subprocess.CalledProcessError as p: + print("Error getting dependencies " + " ".join(args) + ":") + print(" + " + shlex.join(cmd)) + print(p.stdout) + sys.exit(1) + return proc.stdout diff --git a/build.sh b/build.sh index e69de29bb..907cd318c 100644 --- a/build.sh +++ b/build.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +if [[ $CONDA_TOOLCHAIN_BUILD != $CONDA_TOOLCHAIN_HOST ]]; then + # Conda does some swizzling when cross compiling, including moving + # the site-packages folder to the build prefix. So let's just + # manually add this to the compiler search path. + CFLAGS="-isystem $BUILD_PREFIX/lib/python$PY_VER/site-packages $CXXFLAGS" + CXXFLAGS="-isystem $BUILD_PREFIX/lib/python$PY_VER/site-packages $CXXFLAGS" +fi + +mkdir _build +cd _build +cmake ${CMAKE_ARGS} ../dxtbx "-DCMAKE_INSTALL_PREFIX=$PREFIX" "-DPython_EXECUTABLE=$PYTHON" -GNinja +cmake --build . +cmake --install . +$PYTHON -mpip install ../dxtbx \ No newline at end of file