trivial: Use same codestyle

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
This commit is contained in:
Igor Gnatenko 2019-03-16 15:10:14 +01:00
parent 47597fcad7
commit 2b20b9e369
No known key found for this signature in database
GPG key ID: 695714BD1BBC5F4C
3 changed files with 27 additions and 27 deletions

View file

@ -24,13 +24,14 @@ DEFAULT_EDITOR = "vi"
XDG_CACHE_HOME = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache")) XDG_CACHE_HOME = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))
CACHEDIR = os.path.join(XDG_CACHE_HOME, "rust2rpm") CACHEDIR = os.path.join(XDG_CACHE_HOME, "rust2rpm")
API_URL = "https://crates.io/api/v1/" API_URL = "https://crates.io/api/v1/"
JINJA_ENV = jinja2.Environment(loader=jinja2.ChoiceLoader([ JINJA_ENV = jinja2.Environment(
jinja2.FileSystemLoader(["/"]), loader=jinja2.ChoiceLoader([
jinja2.PackageLoader("rust2rpm", "templates"), jinja2.FileSystemLoader(["/"]),
]), jinja2.PackageLoader("rust2rpm", "templates"),
extensions=["jinja2.ext.do"], ]),
trim_blocks=True, extensions=["jinja2.ext.do"],
lstrip_blocks=True) trim_blocks=True,
lstrip_blocks=True)
def get_default_target(): def get_default_target():
# TODO: add fallback for /usr/lib/os-release # TODO: add fallback for /usr/lib/os-release
@ -122,8 +123,7 @@ def download(crate, version):
req = requests.get(url, stream=True) req = requests.get(url, stream=True)
req.raise_for_status() req.raise_for_status()
total = int(req.headers["Content-Length"]) total = int(req.headers["Content-Length"])
with remove_on_error(cratef), \ with remove_on_error(cratef), open(cratef, "wb") as f:
open(cratef, "wb") as f:
for chunk in tqdm.tqdm(req.iter_content(), f"Downloading {cratef_base}".format(cratef_base), for chunk in tqdm.tqdm(req.iter_content(), f"Downloading {cratef_base}".format(cratef_base),
total=total, unit="B", unit_scale=True): total=total, unit="B", unit_scale=True):
f.write(chunk) f.write(chunk)
@ -183,7 +183,7 @@ def make_diff_metadata(crate, version, patch=False, store=False):
cratef, crate, version = local_crate(crate, version) cratef, crate, version = local_crate(crate, version)
else: else:
if store: if store:
raise ValueError('--store-crate can only be used for a crate') raise ValueError("--store-crate can only be used for a crate")
toml, crate, version = local_toml(crate, version) toml, crate, version = local_toml(crate, version)
diff = make_patch(toml, enabled=patch, tmpfile=True) diff = make_patch(toml, enabled=patch, tmpfile=True)
@ -234,7 +234,7 @@ def main():
return return
if args.crate is None: if args.crate is None:
parser.error('required crate/path argument missing') parser.error("required crate/path argument missing")
crate, diff, metadata = make_diff_metadata(args.crate, args.version, crate, diff, metadata = make_diff_metadata(args.crate, args.version,
patch=args.patch, patch=args.patch,
@ -254,7 +254,7 @@ def main():
kwargs["target"] = args.target kwargs["target"] = args.target
kwargs["all_features"] = args.all_features kwargs["all_features"] = args.all_features
bins = [tgt for tgt in metadata.targets if tgt.kind == "bin"] bins = [tgt for tgt in metadata.targets if tgt.kind == "bin"]
libs = [tgt for tgt in metadata.targets if tgt.kind in ("lib", "rlib", "proc-macro")] libs = [tgt for tgt in metadata.targets if tgt.kind in {"lib", "rlib", "proc-macro"}]
is_bin = len(bins) > 0 is_bin = len(bins) > 0
is_lib = len(libs) > 0 is_lib = len(libs) > 0
if is_bin: if is_bin:
@ -271,7 +271,7 @@ def main():
else: else:
kwargs["auto_changelog_entry"] = True kwargs["auto_changelog_entry"] = True
if args.target in ("fedora", "mageia", "opensuse"): if args.target in {"fedora", "mageia", "opensuse"}:
kwargs["include_build_requires"] = True kwargs["include_build_requires"] = True
kwargs["include_provides"] = False kwargs["include_provides"] = False
kwargs["include_requires"] = False kwargs["include_requires"] = False

View file

@ -17,12 +17,12 @@ def translate_slashes(license):
def spdx_to_fedora_map(): def spdx_to_fedora_map():
with open(SPDX_TO_FEDORA_CSV, newline='') as f: with open(SPDX_TO_FEDORA_CSV, newline='') as f:
reader = _csv.DictReader(f) reader = _csv.DictReader(f)
return {line['SPDX License Identifier'] : line['Fedora Short Name'] return {line['SPDX License Identifier']: line['Fedora Short Name']
for line in reader for line in reader
if line['SPDX License Identifier']} if line['SPDX License Identifier']}
def dump_sdpx_to_fedora_map(file): def dump_sdpx_to_fedora_map(file):
for k,v in spdx_to_fedora_map().items(): for k, v in spdx_to_fedora_map().items():
print(f"{k}{v}", file=file) print(f"{k}{v}", file=file)
def translate_license_fedora(license): def translate_license_fedora(license):
@ -39,7 +39,7 @@ def translate_license_fedora(license):
if mapped is None: if mapped is None:
comments += f'# FIXME: Upstream uses unknown SPDX tag {tag}!' comments += f'# FIXME: Upstream uses unknown SPDX tag {tag}!'
final.append(tag) final.append(tag)
elif mapped is '': elif mapped == '':
comments += f"# FIXME: Upstream SPDX tag {tag} not listed in Fedora's good licenses list.\n" comments += f"# FIXME: Upstream SPDX tag {tag} not listed in Fedora's good licenses list.\n"
comments += "# FIXME: This package might not be allowed in Fedora!\n" comments += "# FIXME: This package might not be allowed in Fedora!\n"
final.append(tag) final.append(tag)

View file

@ -25,13 +25,13 @@ class Dependency:
@classmethod @classmethod
def from_json(cls, metadata): def from_json(cls, metadata):
features = set(metadata['features']) features = set(metadata["features"])
if metadata['uses_default_features']: if metadata["uses_default_features"]:
features.add('default') features.add("default")
kwargs = {'name': metadata['name'], kwargs = {"name": metadata["name"],
'req': metadata['req'], "req": metadata["req"],
'optional': metadata['optional'], "optional": metadata["optional"],
'features': features} "features": features}
return cls(**kwargs) return cls(**kwargs)
@staticmethod @staticmethod
@ -45,7 +45,7 @@ class Dependency:
# Any means any # Any means any
continue continue
ver = req.spec ver = req.spec
if req.kind in (req.KIND_NEQ, req.KIND_EMPTY): if req.kind in {req.KIND_NEQ, req.KIND_EMPTY}:
raise NotImplementedError(f"'!=' and empty kinds are not supported: {req}") raise NotImplementedError(f"'!=' and empty kinds are not supported: {req}")
coerced = str(semver.Version.coerce(str(ver))) coerced = str(semver.Version.coerce(str(ver)))
if ver.prerelease: if ver.prerelease:
@ -54,7 +54,7 @@ class Dependency:
ver = ver.next_patch() ver = ver.next_patch()
if req.kind == req.KIND_EQUAL: if req.kind == req.KIND_EQUAL:
req.kind = req.KIND_SHORTEQ req.kind = req.KIND_SHORTEQ
if req.kind in (req.KIND_CARET, req.KIND_COMPATIBLE): if req.kind in {req.KIND_CARET, req.KIND_COMPATIBLE}:
if ver.major == 0: if ver.major == 0:
if ver.minor is not None: if ver.minor is not None:
if ver.minor != 0 or ver.patch is None: if ver.minor != 0 or ver.patch is None:
@ -74,11 +74,11 @@ class Dependency:
upper = ver.next_minor() upper = ver.next_minor()
reqs.append((">=", coerced)) reqs.append((">=", coerced))
reqs.append(("<", upper)) reqs.append(("<", upper))
elif req.kind in (req.KIND_SHORTEQ, elif req.kind in {req.KIND_SHORTEQ,
req.KIND_GT, req.KIND_GT,
req.KIND_GTE, req.KIND_GTE,
req.KIND_LT, req.KIND_LT,
req.KIND_LTE): req.KIND_LTE}:
reqs.append((str(req.kind), coerced)) reqs.append((str(req.kind), coerced))
else: else:
raise AssertionError(f"Found unhandled kind: {req.kind}") raise AssertionError(f"Found unhandled kind: {req.kind}")