-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix version in requirements to comply with stricter setuptools. (#2604) Co-authored-by: Lorenzo Stella <[email protected]> * Backport: Add gluonts.util.safe_extract (#2606) * Expose aggregation method in ensemble NBEATS, fix forecast shape (#2598) * Disable Py36 tests, fix version. * Fixup. * Cap numpy compatibility in `mxnet` extra requirements (#2506) * xfail multivariate grouper test Co-authored-by: Lorenzo Stella <[email protected]> Co-authored-by: Jasper <[email protected]> --------- Co-authored-by: Lorenzo Stella <[email protected]> Co-authored-by: Lorenzo Stella <[email protected]>
- Loading branch information
1 parent
be1a39e
commit c9a6f96
Showing
12 changed files
with
130 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pyarrow>=6.*; python_version=='3.6.*' | ||
pyarrow>=6.0; python_version=='3.6' | ||
pyarrow~=8.0; python_version>='3.7' |
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
rpy2>=2.9.*,<3.* | ||
rpy2>=2.9.0,<3.0 |
This file contains 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 |
---|---|---|
@@ -1 +1,4 @@ | ||
# upper bound added since numpy==1.24 broke importing mxnet, | ||
# see https://github.com/awslabs/gluonts/pull/2506 | ||
numpy<1.24 | ||
mxnet~=1.7 |
This file contains 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 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 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 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 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,48 @@ | ||
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# A copy of the License is located at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
import tarfile | ||
|
||
from pathlib import Path | ||
|
||
|
||
def will_extractall_into(tar: tarfile.TarFile, path: Path) -> None: | ||
""" | ||
Check that the content of ``tar`` will be extracted within ``path`` | ||
upon calling ``extractall``. | ||
Raise a ``PermissionError`` if not. | ||
""" | ||
path = Path(path).resolve() | ||
|
||
for member in tar.getmembers(): | ||
member_path = (path / member.name).resolve() | ||
|
||
try: | ||
member_path.relative_to(path) | ||
except ValueError: | ||
raise PermissionError(f"'{member.name}' extracts out of target.") | ||
|
||
|
||
def safe_extractall( | ||
tar: tarfile.TarFile, | ||
path: Path = Path("."), | ||
members=None, | ||
*, | ||
numeric_owner=False, | ||
): | ||
""" | ||
Safe wrapper around ``TarFile.extractall`` that checks all destination | ||
files to be strictly within the given ``path``. | ||
""" | ||
will_extractall_into(tar, path) | ||
tar.extractall(path, members, numeric_owner=numeric_owner) |
This file contains 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 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,51 @@ | ||
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# A copy of the License is located at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
import tempfile | ||
import tarfile | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
import pytest | ||
|
||
from gluonts.util import will_extractall_into | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"arcname, expect_failure", | ||
[ | ||
(None, False), | ||
("./file.txt", False), | ||
("/a/../file.txt", False), | ||
("/a/../../file.txt", True), | ||
("../file.txt", True), | ||
], | ||
) | ||
def test_will_extractall_into(arcname: Optional[str], expect_failure: bool): | ||
with tempfile.TemporaryDirectory() as tempdir: | ||
file_path = Path(tempdir) / "a" / "file.txt" | ||
file_path.parent.mkdir(parents=True) | ||
file_path.touch() | ||
|
||
with tarfile.open(Path(tempdir) / "archive.tar.gz", "w:gz") as tar: | ||
tar.add(file_path, arcname=arcname) | ||
|
||
if expect_failure: | ||
with pytest.raises(PermissionError): | ||
with tarfile.open( | ||
Path(tempdir) / "archive.tar.gz", "r:gz" | ||
) as tar: | ||
will_extractall_into(tar, Path(tempdir) / "b") | ||
else: | ||
with tarfile.open(Path(tempdir) / "archive.tar.gz", "r:gz") as tar: | ||
will_extractall_into(tar, Path(tempdir) / "b") |