From e8c2c928083999b9a317d053279b85cf55be99c4 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Sun, 23 Jun 2024 15:29:08 +0900 Subject: [PATCH] Create dxtbx.any2nexus dispatcher through setuptools (#739) Previously, this was only created through libtbx build mechanisms, because the build script looked for defined run functions, not imported ones. --- build.py | 5 ++++- newsfragments/739.misc | 1 + src/dxtbx/format/nxmx_writer.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 newsfragments/739.misc diff --git a/build.py b/build.py index c610bae40..66c4d1ca0 100644 --- a/build.py +++ b/build.py @@ -37,7 +37,10 @@ def get_entry_point(filename: Path, prefix: str, import_path: str) -> List[str]: tree = ast.parse(contents) # Find root functions named "run" has_run = any( - x for x in tree.body if isinstance(x, ast.FunctionDef) and x.name == "run" + x + for x in tree.body + if (isinstance(x, ast.FunctionDef) and x.name == "run") + or (isinstance(x, ast.ImportFrom) and "run" in [a.name for a in x.names]) ) if not has_run: return [] diff --git a/newsfragments/739.misc b/newsfragments/739.misc new file mode 100644 index 000000000..b695ba18f --- /dev/null +++ b/newsfragments/739.misc @@ -0,0 +1 @@ +Add any2nexus to formal dispatcher mechanisms. diff --git a/src/dxtbx/format/nxmx_writer.py b/src/dxtbx/format/nxmx_writer.py index 0c1768b77..57cfce018 100644 --- a/src/dxtbx/format/nxmx_writer.py +++ b/src/dxtbx/format/nxmx_writer.py @@ -820,7 +820,7 @@ def add_crystal(self, multi_crystal_group_name, crystal): ) -def run(args): +def run(args: list[str] | None = None): usage = "dials.python nxmx_writer.py " parser = ArgumentParser( usage=usage,