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 setup for the tool usage #59

Merged
merged 22 commits into from
Jan 2, 2025
Merged

Add setup for the tool usage #59

merged 22 commits into from
Jan 2, 2025

Conversation

nivcertora
Copy link
Contributor

@nivcertora nivcertora commented Dec 31, 2024

https://certora.atlassian.net/browse/CERT-7888

Title: Refactor Configuration Management and Introduce Setup Command


Description:

This Pull Request introduces key enhancements to the Quorum project, focusing on improving configuration management, streamlining the setup process, and enhancing the overall codebase structure. The changes aim to provide a more efficient onboarding experience, ensure better code organization, and maintain high performance standards.


Key Changes:

  1. Configuration Management:

    • Renamed Configuration Module:
      • Renamed Quorum/config.py to Quorum/utils/config.py to better reflect its utility purpose.
    • Adopted JSON5:
      • Replaced the standard json module with json5 across multiple files to allow for more flexible JSON parsing (e.g., comments, trailing commas).
      • Updated exception handling to accommodate JSONDecodeError and ValueError.
    • Removed Automatic Config Copying:
      • Eliminated the automatic copying of ground_truth.json and execution.json within the configuration script.
      • Introduced explicit error handling to raise FileNotFoundError if essential configuration files are missing.
  2. Setup Command Introduction:

    • New Entry Point SetupQuorum:
      • Added SetupQuorum as a new CLI entry point in setup.py, enabling users to initialize their Quorum environment effortlessly.
    • Added setup_quorum.py:
      • Created a dedicated setup script that automates the copying of essential template files (ground_truth.json, execution.json, .env.example, Readme.md) to the specified working directory.
      • Ensures that existing files are not overwritten, providing warnings to prevent accidental data loss.
  3. CLI Enhancements:

    • Moved Scripts to entry_points:
      • Relocated existing scripts (check_proposal.py, create_report.py, ipfs_validator.py) to the Quorum/entry_points/ directory for better organization.
    • Updated CLI Commands:
      • Updated the console_scripts in setup.py to reflect the new locations of the entry point scripts.
  4. CI Pipeline Adjustments:

    • Updated CI.yml:
      • Changed QUORUM_PATH from . to Quorum/tests to align with the new project structure.
      • Modified the path to regression.json in the regression tests to Quorum/tests/regression.json.
  5. Dependency Updates:

    • Added json5 to requirements.txt:
      • Included json5 as a dependency to support the new JSON parsing requirements.
  6. Documentation Updates:

    • Enhanced README.md:
      • Updated the README to include detailed instructions for the new SetupQuorum command.
      • Removed redundant sections that are now covered by the setup command.
      • Added a Quick Setup section to guide users through the initial configuration process using the new setup script.
  7. Template Management:

    • Added templates Directory:
      • Introduced a Quorum/templates/ directory containing template configuration files (ground_truth.json, execution.json, .env.example, Readme.md) to standardize setup procedures.

@nivcertora nivcertora self-assigned this Dec 31, 2024
@nivcertora nivcertora requested a review from a team as a code owner December 31, 2024 14:39
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@liav-certora liav-certora left a comment

Choose a reason for hiding this comment

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

Minor naming changes to avoid future confusions.

I think using json5 is unnecessary since you are using it because of the templates, but:

  1. You shouldn't open these template files, just copy them for the user (correct me if I'm wrong).
  2. The user has to configure these templates either and they will most likely remove the comments because the files are formatted as json and their IDE will tell them there are errors.
    This introduces another third party dependency which we don't need.

Repo organization looks great. Setup tool implementation is clean.

@@ -3,7 +3,7 @@
from typing import Optional
from pydantic import BaseModel, Field
from pathlib import Path
import json
import json5 as json
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change that to simply import json5. I'm afraid that down the line it will get confusing because these 2 packages do act a little bit differently in certain things (as you saw).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The difference between them is agnostic, if it will cause any issue in the future we can change it. for now, i prefer it to be called json instead of a variable with number name just for apperance.

@@ -1,6 +1,6 @@
import requests
from dataclasses import dataclass
import json
import json5 as json
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same

@@ -1,9 +1,9 @@
from abc import ABC
from datetime import datetime
import json
import json5 as json
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

@@ -1,5 +1,6 @@
import argparse
import json
from json import JSONDecodeError
import json5 as json
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

import shutil
import argparse
from pathlib import Path
import Quorum.utils.pretty_printer as pp
Copy link
Contributor

Choose a reason for hiding this comment

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

Blank line above please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines +39 to +48
for file_name in template_files:
src = templates_dir / file_name
dest = target_dir / '.env' if file_name == '.env.example' else target_dir / file_name

if dest.exists():
pp.pretty_print(f"File exists: {dest}. Skipping.", pp.Colors.WARNING)
continue

shutil.copy(src, dest)
pp.pretty_print(f"Copied {file_name} to {dest}", pp.Colors.SUCCESS)
Copy link
Contributor

Choose a reason for hiding this comment

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

I checked and if .env is in a subdirectory it won't be found automatically so you can rename .env.example to .env without worrying. With that you can just use shutil.copytree instead of the whole for loop but that means everything will be overridden, unlike how you skip existing files. Which I actually think can be better because if a user messes his directory or one of the files he can easily just run this tool again.
You have the option, whatever you prefer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer the current state, and also i would suggest to not upload a .env to the repo.

Copy link
Contributor

Choose a reason for hiding this comment

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

I already told you that I think changing the expected file instead of changing the code is principally wrong. Yes even for the smallest of differences like ", especially when the fix involves adding 3 words.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand your point and yet if the output is improved i am not seeing any issue with modify the test for the better output.

@@ -5,7 +5,7 @@
from Quorum.utils.chain_enum import Chain
from Quorum.apis.price_feeds import PriceFeedData, ChainLinkAPI, ChronicleAPI, CoinGeckoAPI

import json
import json5 as json
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

@@ -4,7 +4,7 @@

from Quorum.apis.block_explorers.source_code import SourceCode

import json
import json5 as json
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

@@ -1,6 +1,6 @@
import json
import json5 as json
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

@nivcertora
Copy link
Contributor Author

nivcertora commented Jan 2, 2025

Minor naming changes to avoid future confusions.

I think using json5 is unnecessary since you are using it because of the templates, but:

  1. You shouldn't open these template files, just copy them for the user (correct me if I'm wrong).
  2. The user has to configure these templates either and they will most likely remove the comments because the files are formatted as json and their IDE will tell them there are errors.
    This introduces another third party dependency which we don't need.

Repo organization looks great. Setup tool implementation is clean.

I honestly don't see any difference in terms of using json5 over json. as long as it dosent introduce any issues its preferred to be used just in case the user will leave comments in the templates instead of crashing the tool. and most users use sublime text and not a real ide for just general knowledge.

Comment on lines +39 to +50
template_files = [f.name for f in templates_dir.iterdir() if f.is_file()]

for file_name in template_files:
src = templates_dir / file_name
dest = target_dir / '.env' if file_name == '.env.example' else target_dir / file_name

if dest.exists():
pp.pretty_print(f"File exists: {dest}. Skipping.", pp.Colors.WARNING)
continue

shutil.copy(src, dest)
pp.pretty_print(f"Copied {file_name} to {dest}", pp.Colors.SUCCESS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
template_files = [f.name for f in templates_dir.iterdir() if f.is_file()]
for file_name in template_files:
src = templates_dir / file_name
dest = target_dir / '.env' if file_name == '.env.example' else target_dir / file_name
if dest.exists():
pp.pretty_print(f"File exists: {dest}. Skipping.", pp.Colors.WARNING)
continue
shutil.copy(src, dest)
pp.pretty_print(f"Copied {file_name} to {dest}", pp.Colors.SUCCESS)
template_files = [f for f in templates_dir.iterdir() if f.is_file()]
for file in template_files:
dest = target_dir / '.env' if file.name == '.env.example' else target_dir / file.name
if dest.exists():
pp.pretty_print(f"File exists: {dest}. Skipping.", pp.Colors.WARNING)
continue
shutil.copy(file, dest)
pp.pretty_print(f"Copied {file.name} to {dest}", pp.Colors.SUCCESS)

Last one since functionality changed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure its going to work for the .env check. so ill keep it for now

Copy link
Contributor

Choose a reason for hiding this comment

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

It will work as you iterate on absolute files

@nivcertora nivcertora merged commit 5ef29c5 into main Jan 2, 2025
12 checks passed
@nivcertora nivcertora deleted the niv/CERT-7888-Add-Setup branch January 2, 2025 08:08
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.

3 participants