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

Refactor find_spots and import to not depend on __main__, deprecate ImageImporter #2080

Merged
merged 8 commits into from
Apr 21, 2022

Conversation

ndevenish
Copy link
Member

Both dials.find_spots and dials.import check if they are imported as __main__ to decide whether to configure logging (and thus show any output). This assumption fails if running from a standard console_scripts entry point.

This refactors both scripts away from the legacy a = Script(); a.run() pattern more into the style of https://github.com/dials/dials/blob/main/doc/examples/boilerplate.py, which advocates splitting the run() method from a do_X method that assumes the logging is already set up.

Import was... slightly complex here - because the heavy lifting for import is implicitly done when parsing the arguments, and it does a first pass to determine the logging level, the function is quite intertangled with the ArgumentParser flow. Thus, I've added a configure_logging= function parameter which toggles this. I've kept but deprecated the ImageImporter class because it seems more likely that this is used elsewhere. I've updated the tests that used this directly.

There are also tests that assume that the find_spots.run function returns the experiments and reflection table, and passes in argument-style parameters. For this reason, find_spots.run here returns if passed return_results=True. The tests should probably be refactored into running as-a-subprocess for this.

ndevenish and others added 6 commits April 14, 2022 12:00
The previous onion-shaped import class has been kept but marked as deprecated
Can't return be default because this causes extra output from console_scripts.

Tests currently rely on this having a return value, and the do_find_spots
doesn't take "argument-like" arguments.
@ndevenish ndevenish merged commit 809bb6b into dials:main Apr 21, 2022
@ndevenish ndevenish deleted the no___main__ branch April 21, 2022 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants