Repository navigation
Wizard rewrite #54
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
Merged
Merged
Wizard rewrite #54
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
bbe0f85
starting on the wizard rewrite
dwhswenson 3cafb36
Merge branch 'main' into wizard-rewrite
dwhswenson f1df73f
Wizard rewrite for engines
dwhswenson ac15c65
clean up engines; rewrite cvs
dwhswenson 3c45137
clean up CVs
dwhswenson 4453c3a
Wizard works again!
dwhswenson c357976
passing tests for most of CVs and half volumes
dwhswenson 1be9867
only 3 failing tests now
dwhswenson abdbead
fix most tests
dwhswenson 59b5770
tests pass locally
dwhswenson 1bf6a89
Add missing files; make more args kwarg-only
dwhswenson 37323f3
Merge branch 'main' of github.com:openpathsampling/openpathsampling-c…
dwhswenson 366dc73
Merge branch 'main' of github.com:openpathsampling/openpathsampling-c…
dwhswenson 425f925
tests for wizard/helper.py
dwhswenson 3660805
some tests & docstrings
dwhswenson bba408f
Rename plugins => plugin_registration
dwhswenson 6cfc536
Start plugin_classes with LoadFromOPS
dwhswenson 47c744a
move wizard object plugins into plugin_classes
dwhswenson 36c887d
move WrapCategory to plugin_classes
dwhswenson f02a367
tests for wizard.parameters,standard_categories
dwhswenson 7e6b55e
add test_parameters.py
dwhswenson 0bc8270
unittest.mock
dwhswenson 8290154
tests for plugin_registration
dwhswenson bf38703
refactor get_text_from_context
dwhswenson 0d706e6
start to tests for plugin_classes
dwhswenson 0f0e0e0
Tests for object plugin classes
dwhswenson 0a7b981
tests for WrapCategory
dwhswenson 64572a7
finish plugin classes tests
dwhswenson 93e5f9e
missing wizard tests
dwhswenson 934040a
looks like all tests pass with full coverage
dwhswenson a88a677
some docstrings
dwhswenson b898478
docstrings
dwhswenson f8d0db4
add EvalHelperFunc, help for CVs, lambda_min/max
dwhswenson d7ec33d
fix use of LoadFromOPSFile
dwhswenson 448088e
tests for EvalHelperFunc
dwhswenson 7649c93
Apply suggestions from code review
dwhswenson 9129def
import mock_wizard from mock_wizard
dwhswenson 1474c8d
add debug logging to plugin registration
dwhswenson da5acdc
Error on duplicate WizardObjectPlugins
dwhswenson 3696d69
Fix lack of context in negated volume
dwhswenson 20aba5a
Apply suggestions from code review
dwhswenson 750bb55
Update the negated volume intro text
dwhswenson 1399860
Merge branch 'wizard-rewrite' of github.com:dwhswenson/openpathsampli…
dwhswenson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Wizard rewrite for engines
- Loading branch information
commit f1df73f1a2c4e18eda84e3657d72c02f3be4056f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| NO_PARAMETER_LOADED = object() | ||
|
|
||
| from .helper import Helper | ||
|
|
||
| class WizardProxyParameter: | ||
| def __init__(self, name, ask, helper, error): | ||
| self.name = name | ||
| self.ask = ask | ||
| self.helper = Helper(helper) | ||
| self.error = error | ||
| self.loader = None | ||
|
|
||
| def register_loader(self, loader): | ||
| if self.loader is not None: | ||
| raise RuntimeError("Already have a loader for this parameter") | ||
| self.loader = loader | ||
|
|
||
| def _process_input(self, user_str): | ||
| if user_str[0] in ['?', '!']: | ||
| pass | ||
|
|
||
| def __call__(self, wizard): | ||
| obj = NO_PARAMETER_LOADED | ||
| while obj is NO_PARAMETER_LOADED: | ||
| obj = wizard.ask_load(self.ask, self.loader, self.helper) | ||
|
|
||
| return obj | ||
|
|
||
|
|
||
| class WrapCompilerWizardPlugin: | ||
| def __init__(self, name, category, parameters, compiler_plugin, | ||
| prerequisite=None, intro=None, description=None): | ||
| self.parameters = parameters | ||
| self.compiler_plugin = compiler_plugin | ||
| self.prerequisite = prerequisite | ||
| self.intro = intro | ||
| self.description = description | ||
| loaders = {p.name: p.loader for p in self.compiler_plugin.parameters} | ||
| for param in self.parameters: | ||
| param.register_loader(loaders[param.name]) | ||
|
|
||
| def __call__(self, wizard): | ||
| if self.intro is not None: | ||
| wizard.say(self.intro) | ||
|
|
||
| if self.prerequisite is not None: | ||
| self.prerequisite(wizard) | ||
|
|
||
| dct = {param.name: param(wizard) for param in self.parameters} | ||
| result = self.compiler_plugin.builder(**dct) | ||
|
|
||
| return result | ||
|
|
||
| class CategoryHelpFunc: | ||
| def __init__(self, category, basic_help=None): | ||
| self.category = category | ||
| if basic_help is None: | ||
| basic_help = f"Sorry, no help available for {category.name}." | ||
| self.basic_help = basic_help | ||
|
|
||
| def __call__(self, help_args, context): | ||
| if not help_args: | ||
| return self.basic_help | ||
| help_dict = {} | ||
| for num, (name, obj) in enumerate(self.category.choices.items()): | ||
| try: | ||
| help_str = obj.description | ||
| except Exception: | ||
| help_str = f"Sorry, no help available for '{name}'." | ||
| help_dict[str(num+1)] = help_str | ||
| help_dict[name] = help_str | ||
|
|
||
| try: | ||
| result = help_dict[help_args] | ||
| except KeyError: | ||
| result = None | ||
| return result | ||
|
|
||
|
|
||
| class WrapCategory: | ||
| def __init__(self, name, ask, helper=None, intro=None): | ||
| self.name = name | ||
| if isinstance(intro, str): | ||
| intro = [intro] | ||
| self.intro = intro | ||
| self.ask = ask | ||
| if helper is None: | ||
| helper = Helper(CategoryHelpFunc(self)) | ||
| if isinstance(helper, str): | ||
| helper = Helper(CategoryHelpFunc(self, helper)) | ||
|
|
||
| self.helper = helper | ||
| self.choices = {} | ||
|
|
||
| def register_plugin(self, plugin): | ||
| self.choices[plugin.name] = plugin | ||
|
|
||
| def __call__(self, wizard): | ||
| for line in self.intro: | ||
| wizard.say(line) | ||
|
|
||
| selected = wizard.ask_enumerate_dict(self.ask, self.choices, | ||
| self.helper) | ||
| obj = selected(wizard) | ||
| return obj | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.