Skip to content

Commit

Permalink
Use tomllib instead of cargo-metadata to get version
Browse files Browse the repository at this point in the history
cargo-metadata seems a bit heavyweight for this task, and we access the
metadata through cargo-metadata in a JSON format, rather than directly.

This change requires Python 3.11.

Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Sep 19, 2023
1 parent 54c264b commit feb075e
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions release_management/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"""

# isort: STDLIB
import json
import os
import subprocess
import tarfile
import tomllib
from datetime import datetime
from getpass import getpass
from urllib.parse import urlparse
Expand Down Expand Up @@ -130,21 +130,10 @@ def get_package_info(manifest_abs_path, package_name):
"""
assert os.path.isabs(manifest_abs_path)

command = [
"cargo",
"metadata",
"--format-version=1",
"--no-deps",
f"--manifest-path={manifest_abs_path}",
]
with open(manifest_abs_path, "rb") as manifest:
metadata = tomllib.load(manifest)

with subprocess.Popen(command, stdout=subprocess.PIPE) as proc:
metadata_str = proc.stdout.readline()

metadata = json.loads(metadata_str)
packages = metadata["packages"]
assert len(packages) == 1, "Unexpected Cargo metadata format"
package = packages[0]
package = metadata["package"]
assert package["name"] == package_name, (
f'crate name in Cargo.toml ({package["name"]}) != specified'
f"package name ({package_name})"
Expand Down

0 comments on commit feb075e

Please sign in to comment.