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): if binary_or_cargo_toml in _get_binaries(cargo_toml):
return 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(): def main():
@ -73,8 +73,8 @@ def main():
args.path = os.path.abspath(args.path) if args.path else os.getcwd() args.path = os.path.abspath(args.path) if args.path else os.getcwd()
files = args.file or sys.stdin.readlines() files = args.file or [f.rstrip() for f in sys.stdin.readlines()]
files = [_cargo_toml(args.path, f.rstrip()) for f in files] files = [_cargo_toml(args.path, f) for f in files]
features = set() features = set()
for f in args.features.split(","): for f in args.features.split(","):
@ -123,7 +123,7 @@ def main():
mds = Metadata.from_file(f, include_members=args.include_workspaces) mds = Metadata.from_file(f, include_members=args.include_workspaces)
for md in mds: for md in mds:
# process_metadata can return an [string], but can be also # 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 # multiple substrings. If we want to order the data and
# remove all the duplicates we should first normalize it # remove all the duplicates we should first normalize it
metadata_lines = [] metadata_lines = []

View file

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