Skip to content

Commit

Permalink
fix handling of cargo.lock outside a workspace
Browse files Browse the repository at this point in the history
if Cargo.toml is outside a workspace, Cargo.lock is generated in the
same directory as Cargo.toml
  • Loading branch information
natsukium authored and mergify[bot] committed Aug 21, 2024
1 parent b3ee74a commit 737121e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
12 changes: 11 additions & 1 deletion nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,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
Empty file.
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

0 comments on commit 737121e

Please sign in to comment.