-
Notifications
You must be signed in to change notification settings - Fork 56
Add zstd and xz support #2893
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
Draft
david-rundle
wants to merge
19
commits into
metomi:master
Choose a base branch
from
david-rundle:feature/add-zstd-xz
base: master
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.
Draft
Add zstd and xz support #2893
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fc8903c
This commit adds support in rose for zstd and xz (with default option…
david-rundle b1ad44d
now with added flake8 compliance
david-rundle 31b6d0b
Add line after me in Contributors
david-rundle 525a6f3
added support for multithreaded compression (for zstd only) controlle…
david-rundle cadee34
remove extraneous backup file
david-rundle 020099a
flake8 is super cool and clean and makes us write better code
david-rundle 4a4c658
who knew python was so picky about whitespace.
david-rundle 7c946fd
oof. Who even knows their own github username?
david-rundle 800f646
First bash at documentation
david-rundle cc009c5
pass local contributorcheck
david-rundle fc9cca8
Update .mailmap
wxtim 14660d7
Update rose_arch.rst
david-rundle a64df95
update code to use the term 'threads' instead of 'cores' throughout t…
david-rundle d8cb802
commit reviewer comments and fix sphinx documentation
david-rundle a0b86e5
add an integration test
wxtim d1a0ff6
Add a couple of functional tests for rose-arch, and made some suggest…
wxtim c0b61d2
* Made some tests pytest style, not unittest.
wxtim 9951a38
Merge pull request #1 from wxtim/feature/add-zstd-xz
david-rundle 28ffad9
Merge branch 'master' into feature/add-zstd-xz
wxtim 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,19 +25,28 @@ class RoseArchTarGzip: | |
|
|
||
| """Compress archive sources in tar.""" | ||
|
|
||
| SCHEMES = ["pax", "pax.gz", "tar", "tar.gz", "tgz"] | ||
| SCHEME_FORMATS = {"pax": tarfile.PAX_FORMAT, "pax.gz": tarfile.PAX_FORMAT} | ||
| SCHEMES = ["pax", "pax.gz", "pax.zst", "pax.xz", | ||
| "tar", "tar.gz", "tgz", "tar.zst", "tar.xz", "txz"] | ||
| SCHEME_FORMATS = {"pax": tarfile.PAX_FORMAT, | ||
| "pax.gz": tarfile.PAX_FORMAT, | ||
| "pax.zst": tarfile.PAX_FORMAT, | ||
| "pax.xz": tarfile.PAX_FORMAT} | ||
| GZIP_EXTS = ["pax.gz", "tar.gz", "tgz"] | ||
| ZSTD_EXTS = ["pax.zst", "tar.zst"] | ||
| XZ_EXTS = ["pax.xz", "tar.xz", "txz"] | ||
|
|
||
| def __init__(self, app_runner, *args, **kwargs): | ||
| self.app_runner = app_runner | ||
|
|
||
| def compress_sources(self, target, work_dir): | ||
| def compress_sources(self, target, work_dir, threads="1"): | ||
|
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. IMO threads should be cast to int as soon as we parse the config. |
||
| """Create a tar archive of all files in target. | ||
|
|
||
| Use work_dir to dump results. | ||
|
|
||
| """ | ||
| if threads != "1": | ||
| raise NotImplementedError("xz does not support multi-threading") | ||
|
|
||
| sources = list(target.sources.values()) | ||
| if len(sources) == 1 and sources[0].path.endswith( | ||
| "." + target.compress_scheme | ||
|
|
@@ -70,3 +79,23 @@ def compress_sources(self, target, work_dir): | |
| command = "gzip -c '%s' >'%s'" % (tar_name, gz_name) | ||
| self.app_runner.popen.run_simple(command, shell=True) | ||
| self.app_runner.fs_util.delete(tar_name) | ||
|
|
||
| elif target.compress_scheme in self.ZSTD_EXTS: | ||
| fdsec, zst_name = mkstemp( | ||
| suffix="." + target.compress_scheme, dir=work_dir | ||
| ) | ||
| os.close(fdsec) | ||
| target.work_source_path = zst_name | ||
| command = f"zstd --rm -T{threads} -c '{tar_name}' >'{zst_name}'" | ||
| self.app_runner.popen.run_simple(command, shell=True) | ||
| self.app_runner.fs_util.delete(tar_name) | ||
|
|
||
| elif target.compress_scheme in self.XZ_EXTS: | ||
| fdsec, xz_name = mkstemp( | ||
| suffix="." + target.compress_scheme, dir=work_dir | ||
| ) | ||
| os.close(fdsec) | ||
| target.work_source_path = xz_name | ||
| command = "xz -c '%s' >'%s'" % (tar_name, xz_name) | ||
| self.app_runner.popen.run_simple(command, shell=True) | ||
| self.app_runner.fs_util.delete(tar_name) | ||
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,53 @@ | ||
| # Copyright (C) British Crown (Met Office) & Contributors. | ||
| # This file is part of Rose, a framework for meteorological suites. | ||
| # | ||
| # Rose is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # Rose is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with Rose. If not, see <http://www.gnu.org/licenses/>. | ||
| # ----------------------------------------------------------------------------- | ||
| """Compress archive sources using xz.""" | ||
|
|
||
|
|
||
| import os | ||
|
|
||
|
|
||
| class RoseArchXz: | ||
|
|
||
| """Compress archive sources in xz.""" | ||
|
|
||
| SCHEMES = ["xz"] | ||
|
|
||
| def __init__(self, app_runner, *args, **kwargs): | ||
| self.app_runner = app_runner | ||
|
|
||
| def compress_sources(self, target, work_dir, threads="1"): | ||
| """xz each source in target. | ||
|
|
||
| Use work_dir to dump results. | ||
|
|
||
| """ | ||
|
|
||
| if threads != "1": | ||
| raise NotImplementedError("xz does not support multi-threading") | ||
|
|
||
| for source in target.sources.values(): | ||
| if source.path.endswith("." + target.compress_scheme): | ||
| continue # assume already done | ||
| name_xz = source.name + "." + target.compress_scheme | ||
| work_path_xz = os.path.join(work_dir, name_xz) | ||
| self.app_runner.fs_util.makedirs( | ||
| self.app_runner.fs_util.dirname(work_path_xz) | ||
| ) | ||
|
|
||
| command = "xz -c '%s' >'%s'" % (source.path, work_path_xz) | ||
| self.app_runner.popen.run_simple(command, shell=True) | ||
| source.path = work_path_xz |
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,50 @@ | ||
| # Copyright (C) British Crown (Met Office) & Contributors. | ||
| # This file is part of Rose, a framework for meteorological suites. | ||
| # | ||
| # Rose is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License as published by | ||
| # the Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # Rose is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with Rose. If not, see <http://www.gnu.org/licenses/>. | ||
| # ----------------------------------------------------------------------------- | ||
| """Compress archive sources using zstd.""" | ||
|
|
||
|
|
||
| import os | ||
|
|
||
|
|
||
| class RoseArchZstd: | ||
|
|
||
| """Compress archive sources in zstd.""" | ||
|
|
||
| SCHEMES = ["zst", "zstd"] | ||
|
|
||
| def __init__(self, app_runner, *args, **kwargs): | ||
| self.app_runner = app_runner | ||
|
|
||
| def compress_sources(self, target, work_dir, threads="1"): | ||
| """zstd each source in target. | ||
|
|
||
| Use work_dir to dump results. | ||
|
|
||
| """ | ||
| for source in target.sources.values(): | ||
| if source.path.endswith("." + target.compress_scheme): | ||
| continue # assume already done | ||
| name_zst = source.name + "." + target.compress_scheme | ||
| work_path_zst = os.path.join(work_dir, name_zst) | ||
| self.app_runner.fs_util.makedirs( | ||
| self.app_runner.fs_util.dirname(work_path_zst) | ||
| ) | ||
| command = \ | ||
| f"zstd --rm -T{threads} -c {source.path} > {work_path_zst}" | ||
|
|
||
| self.app_runner.popen.run_simple(command, shell=True) | ||
| source.path = work_path_zst |
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.
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.
Tried a very simple check
and got an error:
I think that you need to add the threads argument to
rose_arch_gzip.pyand possibly other items in that folder. You may want to consider emitting a warningif threads != 1 and program_is_single_thread: