-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feature/builtin compression #19337
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
Merged
memsharded
merged 31 commits into
conan-io:develop2
from
memsharded:feature/builtin_compression
Jan 14, 2026
Merged
Feature/builtin compression #19337
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
278ea02
Add support for zstd compression of binary packages
grossag 682b0e3
Switch to include python-zstandard in the package requirements
grossag 396815c
Add a test case to cover zstd compress and decompress
grossag f0b7813
Downgrade to 0.20.0 to fix CI
grossag a33394d
Two small improvements
grossag bbed1a0
Address review feedback
grossag ea5d948
Merge branch 'develop2' into topic/grossag/zstd3
grossag db87f56
Add file missed by merge
grossag 6a109f4
Fix typo in parameter which broke tests
grossag e5765e6
A few more small fixes in hopes of unbreaking the build
grossag ff29efc
Some more improvements
grossag 0c58aa8
Address some of the review feedback
grossag 79afdae
Flush zstd frames around every 128MB
grossag 890c454
Merge branch 'develop2' into topic/grossag/zstd3
grossag b8f4a57
Fix DeprecationWarning
grossag 44af70b
merged develop2
memsharded ff9cfa3
wip
memsharded 8b33dd9
Merge branch 'develop2' into feature/builtin_compression
memsharded d438303
wip
memsharded ca1fcb1
review
memsharded 16671b5
Merge branch 'develop2' into feature/builtin_compression
memsharded 06e15c3
compression for cache save/restore too
memsharded 60ef29c
fix unit test
memsharded 1c8780e
Merge branch 'develop2' into feature/builtin_compression
memsharded f79080e
fix tests
memsharded 85f8452
fix tests
memsharded cbe990a
review
memsharded b2310b1
fix save/restore with Path
memsharded 17a5b70
Merge branch 'develop2' into feature/builtin_compression
memsharded ef1c8f9
last review
memsharded 985186d
fix tests
memsharded File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| import gzip | ||
| import os | ||
| import shutil | ||
| import sys | ||
| import tarfile | ||
| import time | ||
|
|
||
|
|
@@ -10,8 +11,8 @@ | |
| from conan.internal.source import retrieve_exports_sources | ||
| from conan.internal.errors import NotFoundException | ||
| from conan.errors import ConanException | ||
| from conan.internal.paths import (CONAN_MANIFEST, CONANFILE, EXPORT_SOURCES_TGZ_NAME, | ||
| EXPORT_TGZ_NAME, PACKAGE_TGZ_NAME, CONANINFO) | ||
| from conan.internal.paths import CONAN_MANIFEST, CONANFILE, CONANINFO, COMPRESSIONS, \ | ||
| EXPORT_SOURCES_FILE_NAME, EXPORT_FILE_NAME, PACKAGE_FILE_NAME | ||
| from conan.internal.util.files import (clean_dirty, is_dirty, gather_files, | ||
| set_dirty_context_manager, mkdir, human_size) | ||
|
|
||
|
|
@@ -85,6 +86,26 @@ def __init__(self, app: ConanApp, global_conf): | |
| self._app = app | ||
| self._global_conf = global_conf | ||
|
|
||
| # No compressed file exists, need to compress | ||
| compressformat = self._global_conf.get("core.upload:compression_format", | ||
| default="gz", choices=COMPRESSIONS) | ||
| if compressformat in ("xz", "zst"): | ||
| ConanOutput().warning(f"The {compressformat} compression is highly experimental, " | ||
| f"use it at your own risk and expect issues. Feedback welcome, " | ||
| f"please report it as Github tickets", | ||
| warn_tag="risk") | ||
| if compressformat == "zst" and sys.version_info.minor < 14: | ||
|
Member
Author
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. Add risk warnings because of experimental |
||
| raise ConanException("The 'core.upload:compression_format=zst' is only for Python>=3.14") | ||
| compresslevel = self._global_conf.get("core:compresslevel", check_type=int) | ||
| if compresslevel is None and compressformat == "gz": | ||
| compresslevel = self._global_conf.get("core.gzip:compresslevel", check_type=int) | ||
| if compresslevel is not None: | ||
| ConanOutput().warning("core.gzip:compresslevel is deprecated, " | ||
| "use core.compresslevel instead", warn_tag="deprecated") | ||
|
|
||
| self._compressformat = compressformat | ||
| self._compresslevel = compresslevel | ||
|
|
||
| def prepare(self, pkg_list, enabled_remotes): | ||
| local_url = self._global_conf.get("core.scm:local_url", choices=["allow", "block"]) | ||
| for ref, packages in pkg_list.items(): | ||
|
|
@@ -128,14 +149,6 @@ def _prepare_recipe(self, ref, ref_bundle, conanfile, remotes): | |
| def _compress_recipe_files(self, layout, ref): | ||
| download_export_folder = layout.download_export() | ||
|
|
||
| output = ConanOutput(scope=str(ref)) | ||
| for f in (EXPORT_TGZ_NAME, EXPORT_SOURCES_TGZ_NAME): | ||
| tgz_path = os.path.join(download_export_folder, f) | ||
| if is_dirty(tgz_path): | ||
| output.warning("Removing %s, marked as dirty" % f) | ||
| os.remove(tgz_path) | ||
| clean_dirty(tgz_path) | ||
|
|
||
| export_folder = layout.export() | ||
| files, symlinked_folders = gather_files(export_folder) | ||
| files.update(symlinked_folders) | ||
|
|
@@ -159,18 +172,13 @@ def _compress_recipe_files(self, layout, ref): | |
| files.pop(CONANFILE) | ||
| files.pop(CONAN_MANIFEST) | ||
|
|
||
| def add_tgz(tgz_name, tgz_files): | ||
| tgz = os.path.join(download_export_folder, tgz_name) | ||
| if os.path.isfile(tgz): | ||
| result[tgz_name] = tgz | ||
| elif tgz_files: | ||
| compresslevel = self._global_conf.get("core.gzip:compresslevel", check_type=int) | ||
| tgz = compress_files(tgz_files, tgz_name, download_export_folder, | ||
| compresslevel=compresslevel, ref=ref) | ||
| result[tgz_name] = tgz | ||
|
|
||
| add_tgz(EXPORT_TGZ_NAME, files) | ||
| add_tgz(EXPORT_SOURCES_TGZ_NAME, src_files) | ||
| if files: | ||
| comp = self._compressed_file(EXPORT_FILE_NAME, files, download_export_folder, ref) | ||
| result[comp] = os.path.join(download_export_folder, comp) | ||
| if src_files: | ||
| comp = self._compressed_file(EXPORT_SOURCES_FILE_NAME, src_files, | ||
| download_export_folder, ref) | ||
| result[comp] = os.path.join(download_export_folder, comp) | ||
| return result | ||
|
|
||
| def _prepare_package(self, pref, prev_bundle): | ||
|
|
@@ -181,14 +189,35 @@ def _prepare_package(self, pref, prev_bundle): | |
| cache_files = self._compress_package_files(pkg_layout, pref) | ||
| prev_bundle["files"] = cache_files | ||
|
|
||
| def _compressed_file(self, filename, files, download_folder, ref): | ||
| output = ConanOutput(scope=str(ref)) | ||
|
|
||
| # Check if there is some existing compressed file already | ||
| matches = [] | ||
| for extension in COMPRESSIONS: | ||
| file_name = filename + extension | ||
| package_file = os.path.join(download_folder, file_name) | ||
| if is_dirty(package_file): | ||
| output.warning(f"Removing {file_name}, marked as dirty") | ||
| os.remove(package_file) | ||
| clean_dirty(package_file) | ||
| if os.path.isfile(package_file): | ||
| matches.append(file_name) | ||
| if len(matches) > 1: | ||
| raise ConanException(f"{ref}: Multiple package files found for {filename}: {matches}") | ||
| if len(matches) == 1: | ||
| return matches[0] | ||
|
|
||
| file_name = filename + self._compressformat | ||
| package_file = os.path.join(download_folder, file_name) | ||
| compressed_path = compress_files(files, file_name, download_folder, | ||
| compresslevel=self._compresslevel, ref=ref) | ||
| assert compressed_path == package_file | ||
| assert os.path.exists(package_file) | ||
| return file_name | ||
|
|
||
| def _compress_package_files(self, layout, pref): | ||
| output = ConanOutput(scope=str(pref)) | ||
| download_pkg_folder = layout.download_package() | ||
| package_tgz = os.path.join(download_pkg_folder, PACKAGE_TGZ_NAME) | ||
| if is_dirty(package_tgz): | ||
| output.warning("Removing %s, marked as dirty" % PACKAGE_TGZ_NAME) | ||
| os.remove(package_tgz) | ||
| clean_dirty(package_tgz) | ||
|
|
||
| # Get all the files in that directory | ||
| # existing package | ||
|
|
@@ -209,15 +238,8 @@ def _compress_package_files(self, layout, pref): | |
| files.pop(CONANINFO) | ||
| files.pop(CONAN_MANIFEST) | ||
|
|
||
| if not os.path.isfile(package_tgz): | ||
| tgz_files = {f: path for f, path in files.items()} | ||
| compresslevel = self._global_conf.get("core.gzip:compresslevel", check_type=int) | ||
| tgz_path = compress_files(tgz_files, PACKAGE_TGZ_NAME, download_pkg_folder, | ||
| compresslevel=compresslevel, ref=pref) | ||
| assert tgz_path == package_tgz | ||
| assert os.path.exists(package_tgz) | ||
|
|
||
| return {PACKAGE_TGZ_NAME: package_tgz, | ||
| compressed_file = self._compressed_file(PACKAGE_FILE_NAME, files, download_pkg_folder, pref) | ||
| return {compressed_file: os.path.join(download_pkg_folder, compressed_file), | ||
| CONANINFO: os.path.join(download_pkg_folder, CONANINFO), | ||
| CONAN_MANIFEST: os.path.join(download_pkg_folder, CONAN_MANIFEST)} | ||
|
|
||
|
|
@@ -288,6 +310,19 @@ def compress_files(files, name, dest_dir, compresslevel=None, ref=None, recursiv | |
| tgz_path = os.path.join(dest_dir, name) | ||
| if ref: | ||
| ConanOutput(scope=str(ref) if ref else None).info(f"Compressing {name}") | ||
|
|
||
| if name.endswith("zst"): | ||
| with tarfile.open(tgz_path, "w:zst", level=compresslevel) as tar: # noqa Py314 only | ||
| for filename, abs_path in sorted(files.items()): | ||
| tar.add(abs_path, filename, recursive=recursive) | ||
| return tgz_path | ||
|
|
||
| if name.endswith("xz"): | ||
| with tarfile.open(tgz_path, "w:xz", preset=compresslevel, format=tarfile.PAX_FORMAT) as tar: | ||
| for filename, abs_path in sorted(files.items()): | ||
| tar.add(abs_path, filename, recursive=recursive) | ||
| return tgz_path | ||
|
|
||
| with set_dirty_context_manager(tgz_path), open(tgz_path, "wb") as tgz_handle: | ||
| tgz = gzopen_without_timestamps(name, fileobj=tgz_handle, compresslevel=compresslevel) | ||
| for filename, abs_path in sorted(files.items()): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Maybe we can be more specific about the issues you may have? Like:
And also drop the
use it at your own riskpart? The warning is already marked as risk level.