Skip to content

Commit

Permalink
Merge pull request #473 from mulkieran/use-tomllib
Browse files Browse the repository at this point in the history
Use tomllib instead of cargo-metadata to get version
  • Loading branch information
mulkieran authored Sep 19, 2023
2 parents 54c264b + feb075e commit fd3e72b
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 fd3e72b

Please sign in to comment.