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

Add parse and dispatch strategy #198

Conversation

SeanBryan51
Copy link
Collaborator

The current method of executing subcommands can be improved using a "parse and dispatch" strategy. Whereby you don't need to run a conditional to work out which subcommand to use.

This change refactors the Benchcab class so that its "public" methods can be dispatched easily when inspecting the argparse.Namespace object returned by the command line parser.

Fixes #196

Remove tests as they are not compatible with new API changes to the
Benchcab class. Tests relating to executing PBS commands will be a part
of the PBS wrapper implementation.
@SeanBryan51 SeanBryan51 linked an issue Nov 2, 2023 that may be closed by this pull request
Copy link

codecov bot commented Nov 2, 2023

Codecov Report

Merging #198 (474d183) into main (d1192c9) will decrease coverage by 1.55%.
Report is 1 commits behind head on main.
The diff coverage is 45.79%.

@@            Coverage Diff             @@
##             main     #198      +/-   ##
==========================================
- Coverage   86.74%   85.19%   -1.55%     
==========================================
  Files          27       27              
  Lines        1396     1385      -11     
==========================================
- Hits         1211     1180      -31     
- Misses        185      205      +20     
Files Coverage Δ
benchcab/cli.py 100.00% <100.00%> (ø)
tests/test_cli.py 100.00% <100.00%> (ø)
benchcab/main.py 50.00% <50.00%> (ø)
benchcab/benchcab.py 23.12% <23.88%> (-9.84%) ⬇️

@SeanBryan51 SeanBryan51 force-pushed the 196-implement-parse-and-dispatch-strategy-for-executing-subcommands branch 2 times, most recently from 16f9766 to 6e201d6 Compare November 2, 2023 01:41
@SeanBryan51 SeanBryan51 force-pushed the 196-implement-parse-and-dispatch-strategy-for-executing-subcommands branch from 6e201d6 to 2cbdf2a Compare November 2, 2023 02:20
"""A helper method that initialises and returns the `tasks` attribute."""
repos = [
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should call the _get_repos method.

@@ -102,21 +93,41 @@ def _validate_environment(self, project: str, modules: list):
)
sys.exit(1)

def _initialise_tasks(self) -> list[Task]:
@functools.cache
Copy link
Collaborator Author

@SeanBryan51 SeanBryan51 Nov 6, 2023

Choose a reason for hiding this comment

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

After looking at this again, functools.cache might be a bit overkill. It also looks like functions that take in a dictionary cannot be memoized with functools.cache. We can achieve caching here by setting an initial value for self.config to None and only read the config if self.config == None, else return the value of self.config.

The current method of executing subcommands can be improved using a
"parse and dispatch" strategy. Whereby you don't need to run a
conditional to work out which subcommand to use.

This change refactors the Benchcab class so that its "public" methods
can be dispatched easily when inspecting the argparse.Namespace object
returned by the command line parser.

Fixes #196
@SeanBryan51 SeanBryan51 force-pushed the 196-implement-parse-and-dispatch-strategy-for-executing-subcommands branch from 2cbdf2a to 474d183 Compare November 6, 2023 03:38
@SeanBryan51
Copy link
Collaborator Author

Integration tests seem to be working. Merging now.

@SeanBryan51 SeanBryan51 merged commit bc08348 into main Nov 8, 2023
2 of 4 checks passed
@SeanBryan51 SeanBryan51 deleted the 196-implement-parse-and-dispatch-strategy-for-executing-subcommands branch November 8, 2023 23:25
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.

Implement parse and dispatch strategy for executing subcommands
2 participants