mirror of
https://github.com/danieldemus/pyp2spec.git
synced 2026-07-27 21:00:37 +02:00
Improve passing of CLI args in pyp2conf (closes #56)
This commit is contained in:
+10
-18
@@ -99,20 +99,19 @@ def create_package_from_source(
|
||||
|
||||
|
||||
def create_config_contents(
|
||||
package: str,
|
||||
version: str | None = None,
|
||||
session: Session | None = None,
|
||||
compliant: bool = False,
|
||||
python_alt_version: str | None = None,
|
||||
automode: bool = False,
|
||||
compat: str | None = None,
|
||||
options: dict[str, Any],
|
||||
session: Session | None = None
|
||||
) -> dict:
|
||||
"""Use `package` and provided kwargs to create the whole config contents.
|
||||
"""Use `package` and provided options to create the whole config contents.
|
||||
Return pkg_info dictionary.
|
||||
"""
|
||||
|
||||
package = options.get("package")
|
||||
version = options.get("version")
|
||||
compat = options.get("compat")
|
||||
pkg_info = create_package_from_source(package, version, compat, session)
|
||||
|
||||
python_alt_version = options.get("python_alt_version")
|
||||
pkg_info.python_name = prepend_name_with_python(pkg_info.pypi_name, python_alt_version)
|
||||
|
||||
if compat is not None:
|
||||
@@ -128,7 +127,7 @@ def create_config_contents(
|
||||
if pkg_info.license is None:
|
||||
warn("WARNING: No valid license found. Inspect the project manually to find the license")
|
||||
else:
|
||||
if compliant:
|
||||
if options.get("fedora_compliant"):
|
||||
is_compliant, results = check_compliance(pkg_info.license, session=session)
|
||||
if not is_compliant:
|
||||
warn(f"The license '{pkg_info.license}' is not compliant with Fedora")
|
||||
@@ -144,7 +143,7 @@ def create_config_contents(
|
||||
inform(f"Assuming build for Python: {python_alt_version}")
|
||||
pkg_info.python_alt_version = python_alt_version
|
||||
|
||||
if automode:
|
||||
if options.get("automode"):
|
||||
pkg_info.automode = True
|
||||
|
||||
pkg_dict = asdict(pkg_info)
|
||||
@@ -170,14 +169,7 @@ def save_config(contents: dict, output: str | None = None) -> str:
|
||||
def create_config(options: dict) -> str:
|
||||
"""Create and save config file."""
|
||||
|
||||
contents = create_config_contents(
|
||||
options["package"],
|
||||
version=options["version"],
|
||||
compliant=options["fedora_compliant"],
|
||||
python_alt_version=options["python_alt_version"],
|
||||
automode=options["automode"],
|
||||
compat=options["compat"]
|
||||
)
|
||||
contents = create_config_contents(options)
|
||||
return save_config(contents, options["config_output"])
|
||||
|
||||
|
||||
|
||||
+20
-23
@@ -16,7 +16,7 @@ from pyp2spec.pypi_loaders import PackageNotFoundError
|
||||
def test_non_existent_package(betamax_session):
|
||||
with pytest.raises(PackageNotFoundError):
|
||||
create_config_contents(
|
||||
package="definitely-nonexisting-package-name",
|
||||
{"package": "definitely-nonexisting-package-name"},
|
||||
session=betamax_session)
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ def test_non_existent_package(betamax_session):
|
||||
def test_automatically_generated_config_is_valid(betamax_parametrized_session, package, version):
|
||||
"""Run the config rendering in fully automated mode and compare the results"""
|
||||
config = create_config_contents(
|
||||
package=package,
|
||||
version=version,
|
||||
{"package": package,
|
||||
"version": version},
|
||||
session=betamax_parametrized_session,
|
||||
)
|
||||
|
||||
@@ -50,9 +50,9 @@ def test_automatically_generated_config_with_alt_python_is_valid(
|
||||
):
|
||||
"""Run the config rendering in fully automated mode and compare the results"""
|
||||
config = create_config_contents(
|
||||
package=package,
|
||||
version=version,
|
||||
python_alt_version=alt_python,
|
||||
{"package": package,
|
||||
"version": version,
|
||||
"python_alt_version": alt_python},
|
||||
session=betamax_parametrized_session,
|
||||
)
|
||||
|
||||
@@ -72,9 +72,9 @@ def test_automatically_generated_compat_config_is_valid(
|
||||
betamax_parametrized_session, package, compat, version
|
||||
):
|
||||
config = create_config_contents(
|
||||
package=package,
|
||||
version=version,
|
||||
compat=compat,
|
||||
{"package": package,
|
||||
"version": version,
|
||||
"compat": compat},
|
||||
session=betamax_parametrized_session,
|
||||
)
|
||||
|
||||
@@ -89,16 +89,15 @@ def test_config_with_customization_is_valid(betamax_session):
|
||||
This also tests the compliance with Fedora Legal data by making
|
||||
a request to the remote resource.
|
||||
"""
|
||||
package = "aionotion"
|
||||
config = create_config_contents(
|
||||
package=package,
|
||||
version="2.0.3",
|
||||
automode=True,
|
||||
compliant=True,
|
||||
{"package": "aionotion",
|
||||
"version": "2.0.3",
|
||||
"automode": True,
|
||||
"compliant": True},
|
||||
session=betamax_session,
|
||||
)
|
||||
|
||||
with open(f"tests/test_configs/customized_{package}.conf", "rb") as config_file:
|
||||
with open(f"tests/test_configs/customized_aionotion.conf", "rb") as config_file:
|
||||
loaded_contents = tomllib.load(config_file)
|
||||
|
||||
assert config == loaded_contents
|
||||
@@ -106,15 +105,14 @@ def test_config_with_customization_is_valid(betamax_session):
|
||||
|
||||
def test_archful_package(betamax_session):
|
||||
"""Generate config for numpy which is archful"""
|
||||
package = "numpy"
|
||||
config = create_config_contents(
|
||||
package=package,
|
||||
version="1.25.2",
|
||||
automode=True,
|
||||
{"package": "numpy",
|
||||
"version": "1.25.2",
|
||||
"automode": True},
|
||||
session=betamax_session,
|
||||
)
|
||||
|
||||
with open(f"tests/test_configs/default_python-{package}.conf", "rb") as config_file:
|
||||
with open(f"tests/test_configs/default_python-numpy.conf", "rb") as config_file:
|
||||
loaded_contents = tomllib.load(config_file)
|
||||
|
||||
assert config["archful"] == loaded_contents["archful"]
|
||||
@@ -122,13 +120,12 @@ def test_archful_package(betamax_session):
|
||||
|
||||
|
||||
def test_package_with_extras(betamax_session):
|
||||
package = "sphinx"
|
||||
config = create_config_contents(
|
||||
package=package,
|
||||
{"package": "sphinx"},
|
||||
session=betamax_session,
|
||||
)
|
||||
|
||||
with open(f"tests/test_configs/customized_python-{package}.conf", "rb") as config_file:
|
||||
with open(f"tests/test_configs/customized_python-sphinx.conf", "rb") as config_file:
|
||||
loaded_contents = tomllib.load(config_file)
|
||||
|
||||
assert config["extras"] == loaded_contents["extras"]
|
||||
|
||||
Reference in New Issue
Block a user