crate: fix restoring original Cargo.toml for local projects

This commit is contained in:
Fabio Valentini 2023-10-09 23:28:18 +02:00
parent f579129792
commit 519f079729
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF

View file

@ -155,12 +155,11 @@ def guess_local_project_version_from_path(project: str) -> tuple[str, str]:
@contextlib.contextmanager @contextlib.contextmanager
def toml_temp_copy(toml_path: str): def toml_temp_copy(toml_path: str):
with tempfile.TemporaryDirectory() as temp_dir: with open(toml_path, "rb") as toml_file:
temp_path = f"{temp_dir}/Cargo.toml" orig = toml_file.read()
with open(temp_path, "w") as file: yield
with open(toml_path) as orig: with open(toml_path, "wb") as toml_file:
file.write(orig.read()) toml_file.write(orig)
yield temp_path
def process_project_local( def process_project_local(
@ -199,14 +198,14 @@ def process_project_local(
version = package.version version = package.version
features = package.get_feature_names() features = package.get_feature_names()
with toml_temp_copy(toml_path) as temp_toml: with toml_temp_copy(toml_path):
diffs = make_patches(name, package.version, patch, patch_foreign, temp_toml, features) diffs = make_patches(name, package.version, patch, patch_foreign, toml_path, features)
# ensure metadata is up-to-date with changes from patches # ensure metadata is up-to-date with changes from patches
metadata = Metadata.from_cargo(temp_toml) metadata = Metadata.from_cargo(toml_path)
if vendor: if vendor:
vendor_tarball = generate_vendor_tarball(temp_toml, name, package.version) vendor_tarball = generate_vendor_tarball(toml_path, name, package.version)
else: else:
vendor_tarball = None vendor_tarball = None