From 85bb5c5e674feca297a6d7441ad8afc77e362127 Mon Sep 17 00:00:00 2001 From: Simon Billinge Date: Sun, 25 Feb 2024 14:47:07 -0500 Subject: [PATCH 1/3] moving commands dict to commands.py as it is used in multiple places --- regolith/commands.py | 26 ++++++++++++++++++++++++++ regolith/helper_gui_main.py | 14 ++------------ regolith/main.py | 24 +----------------------- regolith/schemas.py | 1 + 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/regolith/commands.py b/regolith/commands.py index 3ff636983..ee92c53fa 100644 --- a/regolith/commands.py +++ b/regolith/commands.py @@ -12,6 +12,8 @@ from regolith.helper import HELPERS, helpr, UPDATER_HELPERS, FAST_UPDATER_WHITELIST from regolith.runcontrol import RunControl from regolith.tools import string_types +from regolith import storage + email = emailer @@ -21,6 +23,8 @@ INGEST_COLL_LU = {".bib": "citations"} + + def add_cmd(rc): """Adds documents to a collection in a database.""" db = rc.client[rc.db] @@ -264,3 +268,25 @@ def validate(rc): # # sys.exit(f"Validation failed on some records\n {cap}") sys.exit(f"Validation failed on some records") + +DISCONNECTED_COMMANDS = { + "add": add_cmd, + "ingest": ingest, + "app": app, + "grade": grade, + "build": build, + "email": email, + "classlist": classlist, + "rc": lambda rc: print(rc._pformat()), + "deploy": deploy, + "store": storage.main, + "json-to-yaml": json_to_yaml, + "yaml-to-json": yaml_to_json, +} + +CONNECTED_COMMANDS = { + "validate": validate, + "helper": helper, + "fs-to-mongo": fs_to_mongo, + "mongo-to-fs": mongo_to_fs +} diff --git a/regolith/helper_gui_main.py b/regolith/helper_gui_main.py index 949549022..0a7b7b5fa 100644 --- a/regolith/helper_gui_main.py +++ b/regolith/helper_gui_main.py @@ -12,20 +12,10 @@ from regolith.runcontrol import DEFAULT_RC, load_rcfile, filter_databases from regolith.schemas import SCHEMAS from regolith.tools import update_schemas +from regolith.commands import CONNECTED_COMMANDS + from gooey import Gooey, GooeyParser -CONNECTED_COMMANDS = { - "add": commands.add_cmd, - "ingest": commands.ingest, - "app": commands.app, - "grade": commands.grade, - "build": commands.build, - "email": commands.email, - "classlist": commands.classlist, - "validate": commands.validate, - "helper": commands.helper, - "fs-to-mongo": commands.fs_to_mongo -} NEED_RC = set(CONNECTED_COMMANDS.keys()) NEED_RC |= {"rc", "deploy", "store"} diff --git a/regolith/main.py b/regolith/main.py index 2cde84cec..d77578650 100644 --- a/regolith/main.py +++ b/regolith/main.py @@ -8,7 +8,6 @@ from regolith.database import connect from regolith import commands -from regolith import storage from regolith.builder import BUILDERS from regolith.commands import INGEST_COLL_LU from regolith.helper import HELPERS @@ -16,28 +15,7 @@ from regolith.schemas import SCHEMAS from regolith.tools import update_schemas from regolith import __version__ - -DISCONNECTED_COMMANDS = { - "rc": lambda rc: print(rc._pformat()), - "deploy": commands.deploy, - "store": storage.main, - "json-to-yaml": commands.json_to_yaml, - "yaml-to-json": commands.yaml_to_json, -} - -CONNECTED_COMMANDS = { - "add": commands.add_cmd, - "ingest": commands.ingest, - "app": commands.app, - "grade": commands.grade, - "build": commands.build, - "email": commands.email, - "classlist": commands.classlist, - "validate": commands.validate, - "helper": commands.helper, - "fs-to-mongo": commands.fs_to_mongo, - "mongo-to-fs": commands.mongo_to_fs -} +from regolith.commands import DISCONNECTED_COMMANDS, CONNECTED_COMMANDS NEED_RC = set(CONNECTED_COMMANDS.keys()) NEED_RC |= {"rc", "deploy", "store"} diff --git a/regolith/schemas.py b/regolith/schemas.py index 7cd1123e0..c53ee2805 100644 --- a/regolith/schemas.py +++ b/regolith/schemas.py @@ -6,6 +6,7 @@ from .sorters import POSITION_LEVELS + SORTED_POSITION = sorted(POSITION_LEVELS.keys(), key=POSITION_LEVELS.get) ACTIVITIES_TYPES = ["teaching", "research"] From 004a3d5338e72804f4b18305902a1ccf7b53edf7 Mon Sep 17 00:00:00 2001 From: Simon Billinge Date: Sun, 25 Feb 2024 14:48:14 -0500 Subject: [PATCH 2/3] news --- news/cmds_to_cmds.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/cmds_to_cmds.rst diff --git a/news/cmds_to_cmds.rst b/news/cmds_to_cmds.rst new file mode 100644 index 000000000..e917a94a4 --- /dev/null +++ b/news/cmds_to_cmds.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* lists of commands now imported from commands.py + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* From a83add514e9c1fbdbf39c162aa7c7fe704efb33f Mon Sep 17 00:00:00 2001 From: Simon Billinge Date: Sun, 25 Feb 2024 15:11:27 -0500 Subject: [PATCH 3/3] fix wrong paste into disconnected commands --- regolith/commands.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/regolith/commands.py b/regolith/commands.py index ee92c53fa..8374b89fd 100644 --- a/regolith/commands.py +++ b/regolith/commands.py @@ -270,13 +270,6 @@ def validate(rc): sys.exit(f"Validation failed on some records") DISCONNECTED_COMMANDS = { - "add": add_cmd, - "ingest": ingest, - "app": app, - "grade": grade, - "build": build, - "email": email, - "classlist": classlist, "rc": lambda rc: print(rc._pformat()), "deploy": deploy, "store": storage.main, @@ -285,6 +278,13 @@ def validate(rc): } CONNECTED_COMMANDS = { + "add": add_cmd, + "ingest": ingest, + "app": app, + "grade": grade, + "build": build, + "email": email, + "classlist": classlist, "validate": validate, "helper": helper, "fs-to-mongo": fs_to_mongo,