Skip to content

Commit

Permalink
Better interface for remove cmd (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomas Perez <[email protected]>
  • Loading branch information
Tomperez98 and coactive-tomas authored Jan 30, 2024
1 parent 0d1d1e0 commit f998585
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ dependencies = [
[project.optional-dependencies]
dev = ["pytest-cov < 5", "types-toml"]


[project.scripts]
pyrgo = "pyrgo.cli.__main__:cli"

Expand Down
17 changes: 13 additions & 4 deletions pyrgo/cli/cmds/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import click
import tomlkit
from packaging.requirements import Requirement
from tomlkit.items import Item, Table

from pyrgo.cli.utils import ensure_env_exist
Expand Down Expand Up @@ -42,16 +43,24 @@ def remove(env: str, dependency: str) -> None:
msg = "`project` section should be a container"
raise TypeError(msg)

project_optional_deps[env] = _remove_from_pyproject_list(
new_deps = _remove_from_pyproject_list(
pyproject_item=project_optional_deps[env], value_to_remove=dependency
)
if len(new_deps) > 0:
project_optional_deps[env] = new_deps
else:
project_optional_deps.pop(env)

conf.pyproject_path.write_text(tomlkit.dumps(pyproject_doc, sort_keys=False))


def _remove_from_pyproject_list(
pyproject_item: Item, value_to_remove: str
) -> list[str]:
pyproject_list: list[str] = pyproject_item.unwrap()
pyproject_list.remove(value_to_remove)
return pyproject_list
pyproject_dependencies: dict[str, str] = {
Requirement(x).name: x for x in pyproject_item.unwrap()
}
if value_to_remove in pyproject_dependencies:
pyproject_dependencies.pop(value_to_remove)

return list(pyproject_dependencies.values())
6 changes: 3 additions & 3 deletions requirements/core.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ click==8.1.7
# via
# pip-tools
# pyrgo (pyproject.toml)
cyclonedx-python-lib==6.4.0
cyclonedx-python-lib==6.4.1
# via pip-audit
defusedxml==0.7.1
# via py-serializable
Expand Down Expand Up @@ -96,7 +96,7 @@ result==0.16.0
# via pyrgo (pyproject.toml)
rich==13.7.0
# via pip-audit
ruff==0.1.14
ruff==0.1.15
# via pyrgo (pyproject.toml)
six==1.16.0
# via html5lib
Expand All @@ -119,7 +119,7 @@ typing-extensions==4.9.0
# via
# mypy
# result
urllib3==2.1.0
urllib3==2.2.0
# via requests
vulture==2.11
# via pyrgo (pyproject.toml)
Expand Down
6 changes: 3 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ coverage[toml]==7.4.1
# via
# coverage
# pytest-cov
cyclonedx-python-lib==6.4.0
cyclonedx-python-lib==6.4.1
# via pip-audit
defusedxml==0.7.1
# via py-serializable
Expand Down Expand Up @@ -104,7 +104,7 @@ result==0.16.0
# via pyrgo (pyproject.toml)
rich==13.7.0
# via pip-audit
ruff==0.1.14
ruff==0.1.15
# via pyrgo (pyproject.toml)
six==1.16.0
# via html5lib
Expand All @@ -130,7 +130,7 @@ typing-extensions==4.9.0
# via
# mypy
# result
urllib3==2.1.0
urllib3==2.2.0
# via requests
vulture==2.11
# via pyrgo (pyproject.toml)
Expand Down

0 comments on commit f998585

Please sign in to comment.