Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work towards a standalone conda package generation #779

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/meta.yaml.template
Original file line number Diff line number Diff line change
@@ -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
20 changes: 7 additions & 13 deletions .github/parse_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
64 changes: 64 additions & 0 deletions .github/prepare_conda_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/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]
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


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}")
Empty file added build.bat
Empty file.
16 changes: 16 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -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
Loading