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

customize calc namespace to have most used function at the top level #375

Merged
2 commits merged into from
Oct 15, 2024
Merged
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
18 changes: 18 additions & 0 deletions hutch_python/calc_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,26 @@ def collect_functions(modules):
return HelpfulNamespace(**functions)


# import specific function to have at the top level of the namespace
funcs = {}
try:
from pcdscalc.diffraction import bragg_angle, darwin_width
funcs['bragg_angle'] = bragg_angle
funcs['darwin_width'] = darwin_width
except ImportError:
print("Failed to import functions from pcdscalc.diffraction")

try:
from pcdscalc.xray import transmission
funcs['transmission'] = transmission
except ImportError:
print("Failed to import functions from pcdscalc.xray")
vespos marked this conversation as resolved.
Show resolved Hide resolved

calc_namespace = HelpfulNamespace(
be_lens=collect_functions(['pcdscalc.be_lens_calcs']),
common=collect_functions(['pcdscalc.common']),
diffraction=collect_functions(['pcdscalc.diffraction']),
xray=collect_functions(['pcdscalc.xray']),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't pcdscalc.xray new? collect_functions will try to import it and raise if I understand correctly. That means it probably should have similar handling as funcs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I think we need to be consistent here: either everything in this module retains backwards compatibility with old versions as implemented above, OR we jettison all of this complexity and simply update the dependency pin on pcdscalc.

Copy link
Contributor Author

@vespos vespos Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really have a strong preference here. This module is widely underutilized across the hutches at the moment, so I dont think it will create much chaos to just move forward with a dependency update

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think either way is totally reasonable

**funcs

)