-
Notifications
You must be signed in to change notification settings - Fork 84
feat(integration-tests): Use tar for extracting tarball downloads with optional leading directory component stripping.
#1661
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,6 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IntegrationTestLogs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IntegrationTestPathConfig, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from tests.utils.utils import unlink | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger = logging.getLogger(__name__) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -48,7 +47,18 @@ def _download_and_extract_dataset( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| integration_test_path_config: IntegrationTestPathConfig, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tarball_url: str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| has_leading_directory_component: bool = True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> IntegrationTestLogs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param request: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param integration_test_path_config: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "param name: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param tarball_url: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param has_leading_directory_component: Whether all files inside the tarball are stored under a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| single top level directory. Defaults to True. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :return: The IntegrationTestPathConfig object with its associated logs properly downloaded, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extracted, and permission changed to be overritable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+52
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstring is malformed and does not match the actual return type The function docstring has a stray quote, a missing - """
- :param request:
- :param integration_test_path_config:
- "param name:
- :param tarball_url:
- :param has_leading_directory_component: Whether all files inside the tarball are stored under a
- single top level directory. Defaults to True.
- :return: The IntegrationTestPathConfig object with its associated logs properly downloaded,
- extracted, and permission changed to be overritable.
- """
+ """
+ Download and extract an integration-test log dataset tarball.
+
+ :param request: The pytest fixture request, used for accessing the cache.
+ :param integration_test_path_config: Paths configuration for integration tests.
+ :param name: Dataset name (used for the cache key and file/directory naming).
+ :param tarball_url: URL of the dataset tarball.
+ :param has_leading_directory_component: Whether all files inside the tarball are stored under a
+ single top-level directory. Defaults to True.
+ :return: The IntegrationTestLogs describing the tarball and extraction directory after download.
+ """📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+55
to
+61
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
clarity and typo fixes. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| integration_test_logs = IntegrationTestLogs( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name=name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tarball_url=tarball_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -58,38 +68,56 @@ def _download_and_extract_dataset( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info("Test logs `%s` are up-to-date. Skipping download.", name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return integration_test_logs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| integration_test_logs.tarball_path.unlink(missing_ok=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shutil.rmtree(integration_test_logs.extraction_dir) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| integration_test_logs.extraction_dir.mkdir(parents=True, exist_ok=False) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+71
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Calling - integration_test_logs.tarball_path.unlink(missing_ok=True)
- shutil.rmtree(integration_test_logs.extraction_dir)
- integration_test_logs.extraction_dir.mkdir(parents=True, exist_ok=False)
+ integration_test_logs.tarball_path.unlink(missing_ok=True)
+ try:
+ shutil.rmtree(integration_test_logs.extraction_dir)
+ except FileNotFoundError:
+ pass
+ integration_test_logs.extraction_dir.mkdir(parents=True, exist_ok=False)If you still want the previous “force remove with sudo” behaviour for stubborn paths, you could instead wire this back through 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is correct, I did get an error when I ran this directly after a fresh build. The rabbit's committable suggestion works.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @quinntaylormitchell, thank you for confirming the issue and validating the fix! I appreciate you testing it on a fresh build. The try/except approach should ensure the fixture works reliably on first run while still cleaning up stale directories on subsequent runs. 🧠 Learnings used
Comment on lines
+71
to
+73
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple things about these three lines (in addition to the rabbit comment, which is correct):
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tarball_path_str = str(integration_test_logs.tarball_path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extract_path_str = str(integration_test_logs.extraction_dir) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| curl_bin = shutil.which("curl") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if curl_bin is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err_msg = "curl executable not found" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise RuntimeError(err_msg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # fmt: off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| curl_cmds = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| curl_bin, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--fail", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--location", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--output", str(integration_test_logs.tarball_path), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--show-error", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tarball_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # fmt: on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.run(curl_cmds, check=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unlink(integration_test_logs.extraction_dir) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shutil.unpack_archive( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| integration_test_logs.tarball_path, integration_test_logs.extraction_dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err_msg = f"Failed to download and extract dataset `{name}`." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise RuntimeError(err_msg) from e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Allow the extracted content to be deletable or overwritable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # fmt: off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| curl_cmd = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| curl_bin, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--fail", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--location", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--output", tarball_path_str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--show-error", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tarball_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # fmt: on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.run(curl_cmd, check=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tar_bin = shutil.which("tar") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if tar_bin is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err_msg = "tar executable not found" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise RuntimeError(err_msg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # fmt: off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extract_cmd = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tar_bin, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--extract", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--gzip", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--file", tarball_path_str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "-C", extract_path_str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # fmt: on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if has_leading_directory_component: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extract_cmd.extend(["--strip-components", "1"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.run(extract_cmd, check=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chmod_bin = shutil.which("chmod") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if chmod_bin is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err_msg = "chmod executable not found" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise RuntimeError(err_msg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.run([chmod_bin, "-R", "gu+w", integration_test_logs.extraction_dir], check=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Allow the downloaded and extracted contents to be deletable or overwritable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.run([chmod_bin, "-R", "gu+w", tarball_path_str], check=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.run([chmod_bin, "-R", "gu+w", extract_path_str], check=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info("Downloaded and extracted uncompressed logs for dataset `%s`.", name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| request.config.cache.set(name, True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is a bit awkward; how about
or