-
Notifications
You must be signed in to change notification settings - Fork 33
[WIP] Refactor Command to Avoid Checking for Help and Version #822
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
Draft
michaelmckinsey1
wants to merge
21
commits into
develop
Choose a base branch
from
refactor-cmd
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
I wanted to just add a few options that @michaelmckinsey1 and I discussed relating to this. The 3 options we discussed (and the 3 most viable options besides what @michaelmckinsey1 has already done and without getting into some really complex and esoteric stuff IMO) are:
from functools import wraps
from importlib import import_module
# Each path string takes the form of "module[:sym0[,sym1[,sym2...]]]"
def benchpark_imports(*import_path_strs):
def inner_decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
# Loop over the path strings provided to the decorator
for path_str in import_path_strs:
# Split the path string into the module name and symbols to import (if provided)
module_name_and_imports = path_str.split(":")
# If both module name and symbols to import were provided, ...
if len(module_name_and_imports) == 2:
# Import the module with importlib
mod = import_module(module_name_and_imports[0])
# Split the symbols to import into individual names
syms_to_import = module_name_and_imports[1].split(",")
# For each symbol to import, get the symbol from the loaded module.
# Then, save it into the decorated function's __builtins__.
# This entire process is equivalent to running the following inside the decorated function:
# >> from <module_name> import <sym0>, <sym1>, <sym2>, ...
for sym in syms_to_import:
func.__builtins__[sym] = getattr(mod, sym)
# Else, if only the module name was provided, ...
elif len(module_name_and_imports) == 1:
# Use built_mod to iteratively build the module name up
built_mod = []
# Split the module name into individual subpackages/submodules
for partial_mod in module_name_and_imports[0].split("."):
# Build the current module/package name to import
built_mod.append(partial_mod)
curr_mod = ".".join("built_mod)
# Import the current module/package
pmod = import_module(curr_mod)
# Save the current module/package into the decorated function's __builtins__.
# This entire process is equivalent to something like:
# >> import os
# >> import os.path
func.__builtins__[curr_mod] = pmod
# Otherwise, the user input is invalid
else:
raise ValueError(
"Invalid path/import specifier: {}".format(path_str)
)
# Call the actual decorated function
return func(*args, **kwargs)
return wrapper
return inner_decorator
# Using the decorator here is equivalent to putting the following
# inside of the main function:
# >> from test_print import test
@benchpark_imports("test_print:test")
def main():
print("Hit main")
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
benchpark setup
#784Adding/modifying a system (docs: Adding a System)
systems/system_name/system.py
filesystem_name
in.github/workflows/run.yml
systems/all_hardware_descriptions/hardware_name/hardware_description.yaml
which will appear in the docs catalogueAdding/modifying a benchmark (docs: Adding a Benchmark)
repo/benchmark_name/package.py
plus: create, self-assign, and link here a follow up issue with a link to the PR in the Spack repo.repo/benchmark_name/application.py
plus: create, self-assign, and link here a follow up issue with a link to the PR in the Ramble repo.application.py
or inrepo/benchmark_name/application.py
will appear in the docs catalogueexperiments/benchmark_name/experiment.py
to define a single node and multi-node experiments.github/workflows/run.yml
Adding/modifying core functionality, CI, or documentation:
.github/workflows
and.gitlab/tests
unit tests (if needed)