Skip to content

Commit

Permalink
Require a literal match to project requirements and install extras fo…
Browse files Browse the repository at this point in the history
…r the requirement
  • Loading branch information
rmartin16 committed May 29, 2023
1 parent 63bfd32 commit 1c54499
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions install_requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def parse_args():
type=str,
nargs="*",
help=(
"List of project requirements to install. Any project requirements that "
"start with any of these values will be installed. For instance, including "
"'pytest' in this list would install both pytest and pytest-xdist."
"List of project requirements to install. If the project defines extras for "
"a requirement, do not include them in this list; they will be included "
"automatically when the requirement is installed. For instance, if "
"coverage[toml] is a project requirement, just include coverage in this list."
),
)
parser.add_argument(
Expand Down Expand Up @@ -119,13 +120,13 @@ def gather_requirements(
matching_requirements = [
requirement
for requirement in project_requirements
if any(requirement.name.startswith(req) for req in requested_requirements)
if requirement.name in requested_requirements
]

if not matching_requirements:
raise NoRequirementsFound(
f"No requirements matched requested requirements: "
f"{', '.join(requested_requirements)}.\n\n"
f"{', '.join(requested_requirements)}\n\n"
f"The requirements below were evaluated for matching:\n "
f"{f'{chr(10)} '.join(req.name for req in project_requirements)}",
error_no=1,
Expand All @@ -137,7 +138,8 @@ def gather_requirements(
def install_requirements(requirements: list[Requirement]):
"""Install requirements from PyPI."""
for requirement in requirements:
requirement_str = f"{requirement.name}{requirement.specifier}"
extras = f"[{','.join(requirement.extras)}]" if requirement.extras else ""
requirement_str = f"{requirement.name}{extras}{requirement.specifier}"
print(f"Installing {requirement_str}...")
subprocess.run(
[
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ deps =
wheel
commands_pre =
python --version
python -m install_requirement --extra dev --project-root "{tox_root}" coverage
python -m install_requirement --extra dev --project-root "{tox_root}" coverage coverage-conditional-plugin
commands =
-python -m coverage combine {env:COMBINE_FLAGS}
html: python -m coverage html --skip-covered --skip-empty
Expand Down

0 comments on commit 1c54499

Please sign in to comment.