-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Compression plugin #18314
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
perseoGI
wants to merge
29
commits into
conan-io:develop2
Choose a base branch
from
perseoGI:pgi/plugin/compression
base: develop2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Compression plugin #18314
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
4cd2811
Proof of concept
perseoGI 156e036
Simplify
perseoGI c7b5dff
Added tar_compressor
perseoGI be30ba2
Extra simplify
perseoGI 1295d4f
Cache the plugin load
perseoGI cc4d3ad
WIP
perseoGI e245a93
Merge with develop2
perseoGI f094d9a
Moved plugin load to ConfigAPI
perseoGI fee5fab
Pass config_api to remote_manager and local_recipe_index
perseoGI 452f774
Restore previous tar_extract fixing tests
perseoGI c1a7320
Removed compression.py module and minimize diff
perseoGI a240c8c
Remove debug print
perseoGI cf7de74
Applied thread suggestions
perseoGI 557f8e0
Remove created pkglist.json on cache restore after usage
perseoGI f82d764
Remove unused and avoid rechecking FS
perseoGI 549e086
Merge branch 'develop2' into pgi/plugin/compression
perseoGI ac1fc45
Added test to check extract failure and issue #18259 test
perseoGI 181a736
Added config to compression.py interface and renamed parameters
perseoGI 3b32ec2
Fix invokation
perseoGI b52bce2
Rename config for conf
perseoGI 91da7a4
Added ref on test
perseoGI e96bd3c
Merge branch 'develop2' into pgi/plugin/compression
perseoGI a024baf
Merge branch 'develop2' into pgi/plugin/compression
perseoGI 989fde9
Move to different approach: tar encapsulation respecting extensions
perseoGI f986651
Fix condition error
perseoGI 8009bed
Addressed some issues
perseoGI 0db1a7b
Make plugin return compressed extension
perseoGI dcbb29e
Adapt changes to support metadata in wrapped files
perseoGI 28e9148
Merged with develop2 and moved compression_plugin to CacheAPI
perseoGI 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import os | ||
| import textwrap | ||
|
|
||
| from conan.test.assets.genconanfile import GenConanfile | ||
| from conan.test.utils.tools import TestClient | ||
|
|
||
|
|
||
| def test_compression_plugin_not_existing(): | ||
| """Test that the compression plugin is not used if it does not exist""" | ||
| c = TestClient() | ||
| c.save({"conanfile.py": GenConanfile("pkg", "1.0")}) | ||
| c.run("create .") | ||
| c.run("cache save 'pkg/*'") | ||
| assert "Compressing conan_cache_save.tgz\n" in c.out | ||
| c.run("cache restore conan_cache_save.tgz") | ||
| # Default decompress does not have any output | ||
| assert "Decompressing conan_cache_save.tgz" not in c.out | ||
perseoGI marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def test_compression_plugin_not_valid(): | ||
| """Test an error is raised if the compression plugin is not valid""" | ||
|
|
||
| c = TestClient() | ||
| compression_plugin = textwrap.dedent( | ||
| """ | ||
| def tar_compress(files, name, dest_dir, compresslevel=None, ref=None, recursive=False): | ||
| return None | ||
| """ | ||
| ) | ||
|
|
||
| c.save( | ||
| { | ||
| os.path.join( | ||
| c.cache_folder, "extensions", "plugins", "compression.py" | ||
| ): compression_plugin, | ||
| "conanfile.py": GenConanfile("pkg", "1.0"), | ||
| } | ||
| ) | ||
| c.run("create .") | ||
| c.run("cache save 'pkg/*'", assert_error=True) | ||
| assert ( | ||
| "ERROR: The 'compression.py' plugin does not contain required `tar_extract` or `tar_compress` functions" | ||
| in c.out | ||
| ) | ||
|
|
||
|
|
||
| def test_compression_plugin_correctly_load(): | ||
| """Test that the compression plugin is correctly loaded and used on: | ||
| - cache save/restore | ||
| - remote upload/download | ||
| """ | ||
| c = TestClient(default_server_user=True) | ||
|
|
||
| compression_plugin = textwrap.dedent( | ||
| """ | ||
| import os | ||
| import tarfile | ||
| from conan.api.output import ConanOutput | ||
| # xz compression | ||
| def tar_compress(files, name, dest_dir, compresslevel=None, ref=None, recursive=False, *args, **kwargs): | ||
| tgz_path = os.path.join(dest_dir, name) | ||
| ConanOutput(scope=str(ref) if ref else "").info(f"Compressing {name} using compression plugin (xz)") | ||
| kwargs = {"preset": compresslevel} if compresslevel else {} | ||
| with tarfile.open(tgz_path, f"w:xz", **kwargs) as tgz: | ||
| for filename, abs_path in sorted(files.items()): | ||
| tgz.add(abs_path, filename, recursive=True) | ||
| return tgz_path | ||
| def tar_extract(src_path, destination_dir, *args, **kwargs): | ||
perseoGI marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ConanOutput().info(f"Decompressing {os.path.basename(src_path)} using compression plugin (xz)") | ||
| with open(src_path, mode='rb') as file_handler: | ||
| the_tar = tarfile.open(fileobj=file_handler) | ||
| the_tar.extraction_filter = (lambda member, path: member) | ||
| the_tar.extractall(path=destination_dir) | ||
| the_tar.close() | ||
| """ | ||
| ) | ||
|
|
||
| c.save( | ||
| { | ||
| os.path.join( | ||
| c.cache_folder, "extensions", "plugins", "compression.py" | ||
| ): compression_plugin, | ||
| "conanfile.py": GenConanfile("pkg", "1.0"), | ||
| } | ||
| ) | ||
| c.run("create .") | ||
| c.run("cache save 'pkg/*'") | ||
| assert "Compressing conan_cache_save.tgz using compression plugin (xz)" in c.out | ||
| c.run("remove pkg/* -c") | ||
| c.run("cache restore conan_cache_save.tgz") | ||
| assert "Decompressing conan_cache_save.tgz using compression plugin (xz)" in c.out | ||
| c.run("list pkg/1.0") | ||
| assert "Found 1 pkg/version recipes matching pkg/1.0 in local cache" in c.out | ||
|
|
||
| # Remove pre existing tgz to force a recompression | ||
| c.run("remove pkg/* -c") | ||
| c.run("create .") | ||
| # Check the plugin is also used on remote interactions | ||
| c.run("upload * -r=default -c") | ||
| assert "Compressing conan_package.tgz using compression plugin (xz)" in c.out | ||
| assert "pkg/1.0: Uploading recipe" in c.out | ||
| c.run("remove pkg/* -c") | ||
| c.run("download 'pkg/*' -r=default") | ||
| assert "Decompressing conan_package.tgz using compression plugin (xz)" in c.out | ||
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.