-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: replace absolute symlinks from cache with correct version (#993)
- Loading branch information
Showing
9 changed files
with
340 additions
and
131 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
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,33 @@ | ||
recipe: | ||
name: cache-symlinks | ||
version: 1.0.0 | ||
|
||
cache: | ||
build: | ||
script: | | ||
mkdir -p $PREFIX/bin | ||
touch $PREFIX/bin/exe | ||
ln -s $PREFIX/bin/exe $PREFIX/bin/exe-symlink | ||
ln -s $PREFIX/bin/exe $PREFIX/bin/absolute-exe-symlink | ||
touch $PREFIX/foo.txt | ||
ln -s $PREFIX/foo.txt $PREFIX/foo-symlink.txt | ||
ln -s $PREFIX/foo.txt $PREFIX/absolute-symlink.txt | ||
ln -s $PREFIX/non-existent-file $PREFIX/broken-symlink.txt | ||
ln -s ./foo.txt $PREFIX/relative-symlink.txt | ||
outputs: | ||
- package: | ||
name: cache-symlinks | ||
build: | ||
files: | ||
include: | ||
- "**/*" | ||
exclude: | ||
- "absolute-symlink.txt" | ||
- "bin/absolute-exe-symlink" | ||
- package: | ||
name: absolute-cache-symlinks | ||
build: | ||
files: | ||
- "absolute-symlink.txt" | ||
- "bin/absolute-exe-symlink" |
35 changes: 35 additions & 0 deletions
35
test/end-to-end/__snapshots__/test_symlinks/test_symlink_cache.json
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,35 @@ | ||
{ | ||
"paths": [ | ||
{ | ||
"_path": "bin/exe", | ||
"path_type": "hardlink", | ||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
"size_in_bytes": 0 | ||
}, | ||
{ | ||
"_path": "bin/exe-symlink", | ||
"path_type": "softlink", | ||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
"size_in_bytes": 3 | ||
}, | ||
{ | ||
"_path": "foo-symlink.txt", | ||
"path_type": "softlink", | ||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
"size_in_bytes": 7 | ||
}, | ||
{ | ||
"_path": "foo.txt", | ||
"path_type": "hardlink", | ||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
"size_in_bytes": 0 | ||
}, | ||
{ | ||
"_path": "relative-symlink.txt", | ||
"path_type": "softlink", | ||
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
"size_in_bytes": 9 | ||
} | ||
], | ||
"paths_version": 1 | ||
} |
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,37 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import pytest | ||
from helpers import RattlerBuild | ||
from syrupy.extensions.json import JSONSnapshotExtension | ||
|
||
|
||
@pytest.fixture | ||
def rattler_build(): | ||
if os.environ.get("RATTLER_BUILD_PATH"): | ||
return RattlerBuild(os.environ["RATTLER_BUILD_PATH"]) | ||
else: | ||
base_path = Path(__file__).parent.parent.parent | ||
executable_name = "rattler-build" | ||
if os.name == "nt": | ||
executable_name += ".exe" | ||
|
||
release_path = base_path / f"target/release/{executable_name}" | ||
debug_path = base_path / f"target/debug/{executable_name}" | ||
|
||
if release_path.exists(): | ||
return RattlerBuild(release_path) | ||
elif debug_path.exists(): | ||
return RattlerBuild(debug_path) | ||
|
||
raise FileNotFoundError("Could not find rattler-build executable") | ||
|
||
|
||
@pytest.fixture | ||
def snapshot_json(snapshot): | ||
return snapshot.use_extension(JSONSnapshotExtension) | ||
|
||
|
||
@pytest.fixture | ||
def recipes(): | ||
return Path(__file__).parent.parent.parent / "test-data" / "recipes" |
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,82 @@ | ||
from pathlib import Path | ||
from subprocess import STDOUT, CalledProcessError, check_output | ||
from typing import Any, Optional | ||
|
||
from conda_package_handling.api import extract | ||
|
||
|
||
class RattlerBuild: | ||
def __init__(self, path): | ||
self.path = path | ||
|
||
def __call__(self, *args: Any, **kwds: Any) -> Any: | ||
try: | ||
return check_output([str(self.path), *args], **kwds).decode("utf-8") | ||
except CalledProcessError as e: | ||
print(e.output) | ||
print(e.stderr) | ||
raise e | ||
|
||
def build_args( | ||
self, | ||
recipe_folder: Path, | ||
output_folder: Path, | ||
variant_config: Optional[Path] = None, | ||
custom_channels: Optional[list[str]] = None, | ||
extra_args: list[str] = None, | ||
): | ||
if extra_args is None: | ||
extra_args = [] | ||
args = ["build", "--recipe", str(recipe_folder), *extra_args] | ||
if variant_config is not None: | ||
args += ["--variant-config", str(variant_config)] | ||
args += ["--output-dir", str(output_folder)] | ||
args += ["--package-format", str("tar.bz2")] | ||
|
||
if custom_channels: | ||
for c in custom_channels: | ||
args += ["--channel", c] | ||
|
||
return args | ||
|
||
def build( | ||
self, | ||
recipe_folder: Path, | ||
output_folder: Path, | ||
variant_config: Optional[Path] = None, | ||
custom_channels: Optional[list[str]] = None, | ||
extra_args: list[str] = None, | ||
): | ||
args = self.build_args( | ||
recipe_folder, | ||
output_folder, | ||
variant_config=variant_config, | ||
custom_channels=custom_channels, | ||
extra_args=extra_args, | ||
) | ||
return self(*args) | ||
|
||
def test(self, package, *args: Any, **kwds: Any) -> Any: | ||
return self("test", "--package-file", package, *args, stderr=STDOUT, **kwds) | ||
|
||
|
||
def get_package(folder: Path, glob="*.tar.bz2"): | ||
if "tar.bz2" not in glob: | ||
glob += "*.tar.bz2" | ||
if "/" not in glob: | ||
glob = "**/" + glob | ||
package_path = next(folder.glob(glob)) | ||
return package_path | ||
|
||
|
||
def get_extracted_package(folder: Path, glob="*.tar.bz2"): | ||
package_path = get_package(folder, glob) | ||
|
||
if package_path.name.endswith(".tar.bz2"): | ||
package_without_extension = package_path.name[: -len(".tar.bz2")] | ||
elif package_path.name.endswith(".conda"): | ||
package_without_extension = package_path.name[: -len(".conda")] | ||
|
||
extract_path = folder / "extract" / package_without_extension | ||
extract(str(package_path), dest_dir=str(extract_path)) | ||
return extract_path |
Oops, something went wrong.