Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions morgan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,9 @@ def mirror(args: argparse.Namespace):
"""

m = Mirrorer(args)
if not m.config.has_section("requirements"):
msg = f"Config file {args.config} has no [requirements] section"
raise ValueError(msg)
for package in m.config["requirements"]:
reqs = m.config["requirements"][package].splitlines()
if not reqs:
Expand Down
29 changes: 29 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import packaging.version
import pytest

import morgan
from morgan import (
PYPI_ADDRESS,
Mirrorer,
Expand Down Expand Up @@ -761,3 +762,31 @@ def test_process_file_rejects_escaping_path(self, mirrorer, monkeypatch):
with pytest.raises(ValueError, match="Unsafe file path"):
# pylint: disable=W0212
mirrorer._process_file(requirement, fileinfo) # noqa: SLF001


class TestMirrorConfigValidation:
def test_mirror_reports_missing_requirements_section(self, tmp_path):
config_path = os.path.join(tmp_path, "morgan.ini")
with open(config_path, "w", encoding="utf-8") as f:
f.write(
"""
[env.test_env]
python_version = 3.10
sys_platform = linux
platform_machine = x86_64
""",
)
args = argparse.Namespace(
index_path=str(tmp_path),
index_url=PYPI_ADDRESS,
config=config_path,
mirror_all_versions=False,
package_type_regex=r"(whl|zip|tar\.gz)",
mirror_all_wheels=False,
target_url=None,
use_pypi_metadata=False,
skip_server_copy=True,
)

with pytest.raises(ValueError, match=r"no \[requirements\] section"):
morgan.mirror(args)