minor fixes and added type annotations to make mypy checks pass
This commit is contained in:
parent
d1bb5c3cfc
commit
05cfcd8aee
4 changed files with 35 additions and 12 deletions
|
@ -2,7 +2,7 @@ import configparser
|
|||
import os
|
||||
import sys
|
||||
import tomllib
|
||||
from typing import Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
import jsonschema
|
||||
|
||||
|
@ -258,17 +258,17 @@ class IniConf:
|
|||
if lib_requires := merged.get("lib.requires"):
|
||||
if "lib_requires" not in settings.keys():
|
||||
settings["lib_requires"] = dict()
|
||||
settings["lib_requires"][None] = to_list(lib_requires)
|
||||
settings["lib_requires"][None] = to_list(lib_requires) # type: ignore
|
||||
|
||||
for feature in features:
|
||||
if lib_feature_requires := merged.get(f"lib+{feature}.requires"):
|
||||
if "lib_requires" not in settings.keys():
|
||||
settings["lib_requires"] = dict()
|
||||
settings["lib_requires"][feature] = to_list(lib_feature_requires)
|
||||
settings["lib_requires"][feature] = to_list(lib_feature_requires) # type: ignore
|
||||
|
||||
settings["conf_file"] = len(confs) == 1
|
||||
|
||||
return IniConf(**settings)
|
||||
return IniConf(**settings) # type: ignore
|
||||
|
||||
|
||||
class TomlConf:
|
||||
|
@ -292,16 +292,22 @@ class TomlConf:
|
|||
def package_summary(self) -> Optional[str]:
|
||||
if package := self._package:
|
||||
return package.get("summary")
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def package_description(self) -> Optional[str]:
|
||||
if package := self._package:
|
||||
return package.get("description")
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def package_supported_arches(self) -> Optional[list[str]]:
|
||||
if package := self._package:
|
||||
return package.get("supported-arches")
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def _features(self) -> Optional[dict]:
|
||||
|
@ -311,16 +317,22 @@ class TomlConf:
|
|||
def features_enable_all(self) -> Optional[bool]:
|
||||
if features := self._features:
|
||||
return features.get("enable-all")
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def features_enable(self) -> Optional[list[str]]:
|
||||
if features := self._features:
|
||||
return features.get("enable")
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def features_hide(self) -> Optional[list[str]]:
|
||||
if features := self._features:
|
||||
return features.get("hide")
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def _requires(self) -> Optional[dict]:
|
||||
|
@ -330,26 +342,36 @@ class TomlConf:
|
|||
def requires_build(self) -> Optional[list[str]]:
|
||||
if requires := self._requires:
|
||||
return requires.get("build")
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def requires_test(self) -> Optional[list[str]]:
|
||||
if requires := self._requires:
|
||||
return requires.get("test")
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def requires_lib(self) -> Optional[list[str]]:
|
||||
if requires := self._requires:
|
||||
return requires.get("lib")
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def requires_bin(self) -> Optional[list[str]]:
|
||||
if requires := self._requires:
|
||||
return requires.get("bin")
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def requires_features(self) -> Optional[dict[str, list[str]]]:
|
||||
if requires := self._requires:
|
||||
return requires.get("features")
|
||||
else:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def load(path: str, features: set[str]) -> "TomlConf":
|
||||
|
@ -374,9 +396,9 @@ class TomlConf:
|
|||
|
||||
@staticmethod
|
||||
def from_conf(conf: IniConf) -> "TomlConf":
|
||||
settings = dict()
|
||||
settings: dict[str, Any] = dict()
|
||||
|
||||
package = dict()
|
||||
package: dict[str, Any] = dict()
|
||||
if conf.summary:
|
||||
package["summary"] = conf.summary
|
||||
if conf.supported_arches:
|
||||
|
@ -384,7 +406,7 @@ class TomlConf:
|
|||
if package:
|
||||
settings["package"] = package
|
||||
|
||||
features = dict()
|
||||
features: dict[str, Any] = dict()
|
||||
if conf.all_features is not None:
|
||||
features["enable-all"] = conf.all_features
|
||||
if conf.enabled_features:
|
||||
|
@ -394,7 +416,7 @@ class TomlConf:
|
|||
if features:
|
||||
settings["features"] = features
|
||||
|
||||
requires = dict()
|
||||
requires: dict[str, Any] = dict()
|
||||
if conf.buildrequires:
|
||||
requires["build"] = conf.buildrequires
|
||||
if conf.testrequires:
|
||||
|
|
|
@ -180,7 +180,7 @@ def process_project_local(
|
|||
name, version = guess_local_project_version_from_path(project)
|
||||
|
||||
log.warn(f"Falling back to {name!r} as the name of the project (based on the name of the containing folder).")
|
||||
diffs = (None, None)
|
||||
diffs: tuple[Optional[list[str]], Optional[list[str]]] = (None, None)
|
||||
|
||||
else:
|
||||
package = metadata.packages[0]
|
||||
|
@ -211,7 +211,7 @@ def resolve_version(crate: str, version: str) -> Optional[str]:
|
|||
log.info("Resolving partial version ...")
|
||||
|
||||
available_versions = query_available_versions(crate)
|
||||
resolved_version = max(filter(lambda x: x in parsed_version, available_versions), default=None)
|
||||
resolved_version = max(filter(lambda x: x in parsed_version, available_versions), default=None) # type: ignore
|
||||
|
||||
if resolved_version is None:
|
||||
log.warn("Partial version does not match any available version.")
|
||||
|
|
|
@ -490,9 +490,9 @@ def spec_render_workspace(
|
|||
else:
|
||||
cargo_args = ""
|
||||
|
||||
license_strs = {package.license for package in metadata.packages if package.license}
|
||||
license_strs = list({package.license for package in metadata.packages if package.license})
|
||||
if len(license_strs) == 1:
|
||||
rpm_license_tag, rpm_license_comments = translate_license(target, list(license_strs)[0])
|
||||
rpm_license_tag, rpm_license_comments = translate_license(target, license_strs[0])
|
||||
else:
|
||||
is_composite = (
|
||||
lambda x: (" " in x and " WITH " not in x and "(" not in x and ")" not in x) or "(" in x or ")" in x
|
||||
|
|
1
tox.ini
1
tox.ini
|
@ -33,6 +33,7 @@ setenv =
|
|||
deps =
|
||||
mypy
|
||||
pytest
|
||||
types-jsonschema
|
||||
types-requests
|
||||
types-tqdm
|
||||
-rrequirements.txt
|
||||
|
|
Loading…
Reference in a new issue