Skip to content
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

fix handling of cargo.lock outside a workspace #273

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,6 @@ def disable_copystat():
res = run(
[
"nix",
"--extra-experimental-features",
"flakes nix-command",
"build",
"-L",
"--no-link",
Expand Down Expand Up @@ -310,7 +308,17 @@ def disable_copystat():
cwd=tempdir,
)

shutil.copy(tempdir + "/Cargo.lock", Path(filename).parent / "Cargo.lock")
if (
lockfile_in_subdir := Path(tempdir)
/ opts.lockfile_metadata_path
/ "Cargo.lock"
).exists():
# if Cargo.toml is outside a workspace, Cargo.lock is generated in the same directory as Cargo.toml
lockfile = lockfile_in_subdir
else:
lockfile = Path(tempdir) / "Cargo.lock"

shutil.copy(lockfile, Path(filename).parent / "Cargo.lock")


def update_composer_deps_hash(opts: Options, filename: str, current_hash: str) -> None:
Expand Down
47 changes: 47 additions & 0 deletions tests/test_cargo_lock_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,50 @@ def test_with_lockfile_metadata_path(helpers: conftest.Helpers) -> None:
assert (
"https://github.com/lancedb/lancedb/compare/python-v0.11.0...0.12.0" in diff
)


def test_with_lockfile_metadata_path_outside_workspace(
helpers: conftest.Helpers,
) -> None:
"""A test for a project where the target Cargo.toml is outside a workspace.

In this case, Cargo.lock is generated in the subdirectory where Cargo.toml is located, not in the project root.
For example, https://github.com/lancedb/lance/blob/v0.16.1/Cargo.toml
"""
with helpers.testpkgs(init_git=True) as path:
main(
[
"--file",
str(path),
"--commit",
"cargoLock.generate.with-lockfile-metadata-path-outside-workspace",
"--version",
"v0.16.1",
"--generate-lockfile",
"--lockfile-metadata-path",
"python",
]
)
subprocess.run(
[
"nix",
"eval",
"--raw",
"--extra-experimental-features",
"nix-command",
"-f",
path,
"cargoLock.generate.with-lockfile-metadata-path-outside-workspace.cargoDeps",
],
check=True,
text=True,
stdout=subprocess.PIPE,
).stdout.strip()
diff = subprocess.run(
["git", "-C", path, "show"],
text=True,
stdout=subprocess.PIPE,
check=True,
).stdout.strip()
print(diff)
assert "https://github.com/lancedb/lance/compare/v0.15.0...v0.16.1" in diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ python3Packages
, rustPlatform
, fetchFromGitHub
}:

python3Packages.buildPythonPackage rec {
pname = "pylance";
version = "0.15.0";

src = fetchFromGitHub {
owner = "lancedb";
repo = "lance";
rev = "v${version}";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};

nativeBuildInputs = [
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];

cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; };
}
1 change: 1 addition & 0 deletions tests/testpkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
cargoLock.expand = pkgs.callPackage ./cargo-lock-expand { };
cargoLock.generate.simple = pkgs.callPackage ./cargo-lock-generate/simple { };
cargoLock.generate.with-lockfile-metadata-path = pkgs.callPackage ./cargo-lock-generate/with-lockfile-metadata-path { };
cargoLock.generate.with-lockfile-metadata-path-outside-workspace = pkgs.callPackage ./cargo-lock-generate/with-lockfile-metadata-path-outside-workspace { };
cargoLock.update = pkgs.callPackage ./cargo-lock-update { };
composer = pkgs.callPackage ./composer.nix { };
crate = pkgs.callPackage ./crate.nix { };
Expand Down