Fixes from the last review

This commit is contained in:
Alberto Planas 2021-09-28 16:37:49 +02:00
parent 981aeed93d
commit 1883197d9c
2 changed files with 10 additions and 10 deletions

View file

@ -46,7 +46,7 @@ def _cargo_toml(source_path, path, exclude_vendor=True):
if binary_or_cargo_toml in _get_binaries(cargo_toml):
return cargo_toml
raise Exception(f'Cargo.toml not found for binary {binary_or_cargo_toml}')
raise FileNotFoundError(f'Cargo.toml not found for binary {binary_or_cargo_toml}')
def main():
@ -73,8 +73,8 @@ def main():
args.path = os.path.abspath(args.path) if args.path else os.getcwd()
files = args.file or sys.stdin.readlines()
files = [_cargo_toml(args.path, f.rstrip()) for f in files]
files = args.file or [f.rstrip() for f in sys.stdin.readlines()]
files = [_cargo_toml(args.path, f) for f in files]
features = set()
for f in args.features.split(","):
@ -123,7 +123,7 @@ def main():
mds = Metadata.from_file(f, include_members=args.include_workspaces)
for md in mds:
# process_metadata can return an [string], but can be also
# a [Dependency] instances, that once presented have
# a [Dependency] instance, that once presented have
# multiple substrings. If we want to order the data and
# remove all the duplicates we should first normalize it
metadata_lines = []

View file

@ -246,7 +246,7 @@ class Dependency:
for feature in self.features or (None,)]
def __repr__(self):
features = sorted(feature or "" for feature in self.features)
features = sorted(feature for feature in self.features if feature)
return f"<Dependency: {self.name} {self.req} ({', '.join(features)})>"
def __str__(self):
@ -310,9 +310,10 @@ class Metadata:
self._summary = description[:p]
@classmethod
def from_json(cls, metadata):
def from_json(cls, metadata, path):
md = metadata
self = cls(md["name"], md["version"])
self._path = path
self.license = md["license"]
self.license_file = md["license_file"]
@ -375,8 +376,7 @@ class Metadata:
instances = []
members = Metadata.members(path) if include_members else []
for member in (members or [path]):
instance = cls.from_json(Metadata.manifest(member))
instance._path = member
instance = cls.from_json(Metadata.manifest(member), member)
instances.append(instance)
return instances
@ -389,8 +389,8 @@ class Metadata:
try:
result = json.loads(output.stdout)
except json.decoder.JSONDecodeError:
# Pure virtual manifest cannot be readed, we need to use
# one from the different workspaces
# Pure virtual manifest cannot be read, we need to use one
# from the different workspaces
result = {}
return result