Skip to content

Commit

Permalink
Resotre CLI cmd and Refactor Quorum configuration managment
Browse files Browse the repository at this point in the history
  • Loading branch information
nivcertora committed Jan 8, 2025
1 parent d321454 commit 7ed98f5
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 134 deletions.
7 changes: 4 additions & 3 deletions Quorum/apis/git_api/git_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
from git import Repo

import Quorum.utils.config as config
from Quorum.utils.quorum_configuration import QuorumConfiguration
import Quorum.utils.pretty_printer as pp

class GitManager:
Expand All @@ -22,11 +22,12 @@ def __init__(self, customer: str, gt_config: dict[str, any]) -> None:
gt_config (dict[str, any]): The ground truth configuration data.
"""
self.customer = customer
self.config = QuorumConfiguration()

self.modules_path = config.MAIN_PATH / self.customer / "modules"
self.modules_path = self.config.main_path / self.customer / "modules"
self.modules_path.mkdir(parents=True, exist_ok=True)

self.review_module_path = config.MAIN_PATH / self.customer / "review_module"
self.review_module_path = self.config.main_path / self.customer / "review_module"
self.review_module_path.mkdir(parents=True, exist_ok=True)

self.repos, self.review_repo = self._load_repos_from_file(gt_config)
Expand Down
4 changes: 2 additions & 2 deletions Quorum/checks/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json5 as json
from pathlib import Path

import Quorum.utils.config as config
from Quorum.utils.quorum_configuration import QuorumConfiguration
from Quorum.apis.block_explorers.source_code import SourceCode
from Quorum.utils.chain_enum import Chain

Expand All @@ -14,7 +14,7 @@ def __init__(self, customer: str, chain: Chain, proposal_address: str, source_co
self.chain = chain
self.proposal_address = proposal_address
self.source_codes = source_codes
self.customer_folder = config.MAIN_PATH / customer
self.customer_folder = QuorumConfiguration().main_path / customer
self.check_folder = self.customer_folder / "checks" / chain / proposal_address / f"{self.__class__.__name__}_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
self.check_folder.mkdir(parents=True, exist_ok=True)

Expand Down
4 changes: 2 additions & 2 deletions Quorum/checks/proposal_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from Quorum.apis.price_feeds.price_feed_utils import PriceFeedProviderBase
from Quorum.apis.governance.data_models import PayloadAddresses
from Quorum.apis.git_api.git_manager import GitManager
import Quorum.utils.config_loader as ConfigLoader
from Quorum.utils.quorum_configuration import QuorumConfiguration


class CustomerConfig(BaseModel):
Expand Down Expand Up @@ -49,7 +49,7 @@ def run_customer_proposal_validation(prop_config: ProposalConfig) -> None:
"""
for config in prop_config.customers_config:
pp.pprint('Run Preparation', pp.Colors.INFO, pp.Heading.HEADING_1)
ground_truth_config = ConfigLoader.load_customer_config(config.customer)
ground_truth_config = QuorumConfiguration().load_customer_config(config.customer)
git_manager = GitManager(config.customer, ground_truth_config)
git_manager.clone_or_update()
price_feed_providers = ground_truth_config.get("price_feed_providers", [])
Expand Down
4 changes: 2 additions & 2 deletions Quorum/entry_points/implementations/ipfs_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from Quorum.apis.block_explorers.chains_api import ChainAPI
from Quorum.llm.chains.ipfs_validation_chain import IPFSValidationChain
import Quorum.utils.config as config
from Quorum.utils.quorum_configuration import QuorumConfiguration
import Quorum.utils.pretty_printer as pp


Expand Down Expand Up @@ -54,7 +54,7 @@ def run_ipfs_validator(args: argparse.Namespace):
run_ipfs_validator(args)
"""
# Check if the Anthropic API key is set in environment variables
if not config.ANTHROPIC_API_KEY:
if not QuorumConfiguration().anthropic_api_key:
raise ValueError("ANTHROPIC_API_KEY environment variable is not set. Please set it to use this functionality.")

# Initialize Chain API and fetch source codes
Expand Down
62 changes: 24 additions & 38 deletions Quorum/entry_points/quorum_cli.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Quorum/entry_points/quorum_cli.py

import argparse
from pydantic import BaseModel
from typing import Callable

import Quorum.entry_points.cli_arguments as cli_args
from Quorum.entry_points.implementations.check_proposal import run_single
from Quorum.entry_points.implementations.check_proposal_config import run_config
from Quorum.entry_points.implementations.check_proposal_id import run_proposal_id
from Quorum.entry_points.implementations.create_report import run_create_report
from Quorum.entry_points.implementations.ipfs_validator import run_ipfs_validator
from Quorum.entry_points.implementations.setup_quorum import run_setup_quorum


class Command(BaseModel):
name: str
help: str
arguments: list[cli_args.Argument]
func: Callable[[argparse.Namespace], None]


COMMAND_REGISTRY = [
Expand All @@ -18,20 +28,23 @@ class Command(BaseModel):
cli_args.CUSTOMER_ARGUMENT,
cli_args.CHAIN_ARGUMENT,
cli_args.PROPOSAL_ADDRESS_ARGUMENT
]
],
func=run_single
),
Command(
name="validate-batch",
help="Run a batch check from a JSON config file.",
arguments=[cli_args.CONFIG_ARGUMENT]
arguments=[cli_args.CONFIG_ARGUMENT],
func=run_config
),
Command(
name="validate-by-id",
help="Check proposals by proposal ID.",
arguments=[
cli_args.CUSTOMER_ARGUMENT,
cli_args.PROPOSAL_ID_ARGUMENT
]
],
func=run_proposal_id
),
Command(
name="create-report",
Expand All @@ -40,7 +53,8 @@ class Command(BaseModel):
cli_args.PROPOSAL_ID_ARGUMENT,
cli_args.TEMPLATE_ARGUMENT,
cli_args.GENERATE_REPORT_PATH_ARGUMENT
]
],
func=run_create_report
),
Command(
name="validate-ipfs",
Expand All @@ -50,12 +64,14 @@ class Command(BaseModel):
cli_args.CHAIN_ARGUMENT,
cli_args.PROPOSAL_ADDRESS_ARGUMENT,
cli_args.PROMPT_TEMPLATES_ARGUMENT
]
],
func=run_ipfs_validator
),
Command(
name="setup",
help="Initial Quorum environment setup.",
arguments=[cli_args.WORKING_DIR_ARGUMENT]
arguments=[cli_args.WORKING_DIR_ARGUMENT],
func=run_setup_quorum
)
]

Expand Down Expand Up @@ -89,37 +105,7 @@ def main():
help=subcmd.help
)
add_arguments(subparser, subcmd.arguments)

if subcmd.name == "validate-address":
def run(args):
from Quorum.entry_points.implementations.check_proposal import run_single
run_single(args)
subparser.set_defaults(func=run)
elif subcmd.name == "validate-batch":
def run(args):
from Quorum.entry_points.implementations.check_proposal_config import run_config
run_config(args)
subparser.set_defaults(func=run)
elif subcmd.name == "validate-by-id":
def run(args):
from Quorum.entry_points.implementations.check_proposal_id import run_proposal_id
run_proposal_id(args)
subparser.set_defaults(func=run)
elif subcmd.name == "create-report":
def run(args):
from Quorum.entry_points.implementations.create_report import run_create_report
run_create_report(args)
subparser.set_defaults(func=run)
elif subcmd.name == "validate-ipfs":
def run(args):
from Quorum.entry_points.implementations.ipfs_validator import run_ipfs_validator
run_ipfs_validator(args)
subparser.set_defaults(func=run)
elif subcmd.name == "setup":
def run(args):
from Quorum.entry_points.implementations.setup_quorum import run_setup_quorum
run_setup_quorum(args)
subparser.set_defaults(func=run)
subparser.set_defaults(func=subcmd.func)

args = parser.parse_args()

Expand All @@ -128,4 +114,4 @@ def run(args):


if __name__ == "__main__":
main()
main()
13 changes: 7 additions & 6 deletions Quorum/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Generator

from Quorum.apis.block_explorers.source_code import SourceCode
import Quorum.utils.config as config
from Quorum.utils.quorum_configuration import QuorumConfiguration


RESOURCES_DIR = Path(__file__).parent / 'resources'
Expand All @@ -24,11 +24,12 @@ def source_codes(request: pytest.FixtureRequest) -> list[SourceCode]:

@pytest.fixture
def tmp_output_path() -> Generator[Path, None, None]:
og_path = config.MAIN_PATH
config.MAIN_PATH = Path(__file__).parent / 'tmp'
yield config.MAIN_PATH # Provide the temporary path to the test
shutil.rmtree(config.MAIN_PATH)
config.MAIN_PATH = og_path
config = QuorumConfiguration()
og_path = config.main_path
config.main_path = Path(__file__).parent / 'tmp'
yield config.main_path # Provide the temporary path to the test
shutil.rmtree(config.main_path)
config.main_path = og_path


@pytest.fixture
Expand Down
27 changes: 0 additions & 27 deletions Quorum/utils/config.py

This file was deleted.

53 changes: 0 additions & 53 deletions Quorum/utils/config_loader.py

This file was deleted.

Loading

0 comments on commit 7ed98f5

Please sign in to comment.