Skip to content

feat(consume): add --extract-to parameter for direct fixture extraction #1861

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

richardgreg
Copy link
Contributor

🗒️ Description

Add new --extract-to flag to consume cache command that extracts fixtures directly to a specified directory, bypassing the normal cache structure. This replaces the need for separate download scripts like 'download-and-extract-fixtures.sh' by integrating the functionality into the existing consume tooling.

Usage:

uvx --from git+https://github.com/ethereum/execution-spec-tests \
    consume cache [email protected] --extract-to=./zkevm-fixtures

🔗 Related Issues or PRs

Fixes #1835

✅ Checklist

  • All: Ran fast tox checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:
    uvx --with=tox-uv tox -e lint,typecheck,spellcheck,markdownlint
  • All: PR title adheres to the repo standard - it will be used as the squash commit message and should start type(scope):.
  • All: Considered adding an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.

@danceratopz danceratopz self-requested a review July 7, 2025 18:40
Copy link
Member

@danceratopz danceratopz left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks a lot for this.

I tried it directly from your branch and it just worked:

uvx --from git+https://github.com/richardgreg/execution-spec-tests@feat/extract-to-flag-for-consume \
          consume cache [email protected] --extract-to=./zkevm-fixtures
    Updated https://github.com/richardgreg/execution-spec-tests (bee9a798163e6f97aa2350c81a2214247790c1af)
    Updated https://github.com/spencer-tb/ethereum-spec-evm-resolver (ee273e7344e24a739ebfbf0ea1f758530c4d032b)
      Built ethereum-execution-spec-tests @ git+https://github.com/richardgreg/execution-spec-tests@bee9a798163e6f97aa2350c81a2214247790c1af
Installed 70 packages in 7ms
Exit: Fixtures downloaded and extracted to specified directory.
Path: zkevm-fixtures/fixtures
Input: https://github.com/ethereum/execution-spec-tests/releases/download/zkevm%40v0.1.0/fixtures_zkevm.tar.gz
Release page: https://github.com/ethereum/execution-spec-tests/releases/tag/zkevm%40v0.1.0

However, I think we can simplify the logic here and achieve the same goal:

  • See the "major quibble" 😆 in the FixtureDownloader below, and,
  • The over-complicated logic in pytest_configure() - FixturesSource exists to not have so much of this boilerplate present in pytest_configure().

Perhaps you can give add this feedback to Claude's context and he can refactor it for you. Make a backup of your branch before you start just in case. You can also make a separate PR if that's easier (if so move this PR to "Draft") and then we can merge the other one if it's cleaner.

Thanks for work @richardgreg.

Comment on lines 406 to 409
if (
hasattr(config.option, "extract_to_folder")
and config.option.extract_to_folder is not None
):
Copy link
Member

Choose a reason for hiding this comment

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

This condition should be something more inline with the checks below. Something like:

Suggested change
if (
hasattr(config.option, "extract_to_folder")
and config.option.extract_to_folder is not None
):
if config.fixtures_source.extract_to_local_path:

This attribute will of course have to be added to the FixturesSource class and set appropriately.

# Validate --extract-to usage
if hasattr(config.option, "extract_to_folder") and config.option.extract_to_folder is not None:
if "cache" not in sys.argv:
pytest.exit("The --extract-to flag is only valid with the 'cache' command.")
Copy link
Member

Choose a reason for hiding this comment

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

I think checking whether the extract_to_folder is available is overly cautious and unnecessary as it's defined above in this plugin. If that is removed, you could try simplifying the condition here and keeping it to a single if statement. Similar to the other pytest.exit() condition below in L401.

Comment on lines 387 to 393
extract_to_path = None
if (
hasattr(config.option, "extract_to_folder")
and config.option.extract_to_folder is not None
):
extract_to_path = Path(config.option.extract_to_folder)

Copy link
Member

Choose a reason for hiding this comment

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

FixturesSource exists to abstract/avoid this kind of code in pytest_configure(). I would suggest removing this check and passing config.option.extract_to_folder directly to FixturesSource.from_input(). Then FixturesSource should handle the option.

help=(
"Extract downloaded fixtures to the specified directory. Only valid with 'cache' "
"command. When used, fixtures are extracted directly to this path instead of the "
"cache structure."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"cache structure."
"user's execution-spec-tests cache directory."

Comment on lines 103 to 126
def extract_to_directory(self, target_dir: Path) -> Path:
"""
Download and extract fixtures directly to the specified directory.
This bypasses the normal cache structure and extracts to the target directory.
"""
# Download the archive to a temporary location first
temp_archive = target_dir.parent / f"temp_{self.archive_name}.tar.gz"
response = requests.get(self.url)
response.raise_for_status()

# Write the archive to temp location
temp_archive.write_bytes(response.content)

target_dir.mkdir(parents=True, exist_ok=True)

# Extract directly to target directory
with tarfile.open(temp_archive, mode="r:gz") as tar:
tar.extractall(path=target_dir, filter="data")

temp_archive.unlink()

# Detect if there's a single top-level directory and return its path
extracted_dirs = [d for d in target_dir.iterdir() if d.is_dir() and d.name != ".meta"]
return extracted_dirs[0] if len(extracted_dirs) == 1 else target_dir
Copy link
Member

Choose a reason for hiding this comment

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

This is my major quibble with this PR as-is: It duplicates quite a bit of code from fetch_and_extract().

The CLI UX and the hooks pytest_addoption() and pytest_configure() could stay the same... and I'm not entirely sure, but I've got a hunch that FixturesSource could be refactored to combine the cache_folder and extract_to values to one variable which holds the target destination for the folder. Then FixtureDownloader could be agnostic as to whether we're extracting to a cache folder or a user-specified local folder.

Copy link
Member

@danceratopz danceratopz left a comment

Choose a reason for hiding this comment

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

Oops, approved in previous review by mistake. Have to do submit another review to prevent it getting merged.

@danceratopz danceratopz changed the title feat(consume): add --extract-to parameter for direct fixture extraction feat(consume): add --extract-to parameter for direct fixture extraction Jul 11, 2025
Add new --extract-to flag to consume cache command that extracts fixtures
directly to a specified directory, bypassing the normal cache structure.
This replaces the need for separate download scripts like
'download-and-extract-fixtures.sh' by integrating the functionality into
the existing consume tooling.

Usage:
uvx --from git+https://github.com/ethereum/execution-spec-tests \
    consume cache [email protected] --extract-to=./zkevm-fixtures
@richardgreg richardgreg force-pushed the feat/extract-to-flag-for-consume branch from bee9a79 to b16f567 Compare July 13, 2025 16:38
@richardgreg richardgreg requested a review from danceratopz July 13, 2025 17:12
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.

feat(consume): add a --extract-to flag to consume cache
2 participants