Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide --update option as comma separated list #33

Merged
merged 1 commit into from
Aug 1, 2020
Merged
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
13 changes: 6 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ To update one or more dependencies to the latest allowed version, run:

.. code:: console

pip-df sync --update DEPENDENCY1 --update DEPENDENCY2 ...
pip-df sync --update DEPENDENCY1,DEPENDENCY2 ...

If you need to add some dependencies from VCS references (e.g. when a library
with a patch you need is not available as a release on a package index), add
Expand Down Expand Up @@ -138,7 +138,7 @@ How to
``setup.py`` and add the git reference in ``requirements.txt.in``)
- Remove a dependency (remove it from ``setup.py``)
- Update a dependency to the most recent version
(``pip-df sync --update DEPENDENCY1 --update DEPENDENCY2``)
(``pip-df sync --update DEPENDENCY1,DEPENDENCY2``)
- Update all dependencies to the latest version
(``pip-df sync --update-all`` or remove ``requirements.txt`` and run
``pip-df sync``)
Expand Down Expand Up @@ -199,12 +199,11 @@ pip-df sync
dependencies.

Options:
-u, --update DEPENDENCY Make sure DEPENDENCY is upgraded (or
downgraded) to the latest allowed version.
If DEPENDENCY is not part of your
-u, --update DEP1,DEP2,... Make sure selected dependencies are upgraded
(or downgraded) to the latest allowed
version. If DEP is not part of your
application dependencies anymore, this
option has no effect. This option can be
repeated.
option has no effect.

--update-all Upgrade (or downgrade) all dependencies of
your application to the latest allowed
Expand Down
1 change: 1 addition & 0 deletions news/33.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``--update`` is changed to accept a comma-separated list of distribution names.
17 changes: 8 additions & 9 deletions src/pip_deepfreeze/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import shutil
from pathlib import Path
from typing import List, Optional
from typing import Optional

import typer

from .detect import supports_editable
from .sync import sync as sync_operation
from .tree import tree as tree_operation
from .utils import increase_verbosity, log_debug, log_error
from .utils import comma_split, increase_verbosity, log_debug, log_error

app = typer.Typer()

Expand All @@ -20,16 +20,15 @@ class MainOptions:
@app.command()
def sync(
ctx: typer.Context,
to_upgrade: List[str] = typer.Option(
to_upgrade: str = typer.Option(
None,
"--update",
"-u",
metavar="DEPENDENCY",
metavar="DEP1,DEP2,...",
help=(
"Make sure DEPENDENCY is upgraded (or downgraded) to the latest "
"allowed version. If DEPENDENCY is not part of your application "
"dependencies anymore, this option has no effect. "
"This option can be repeated."
"Make sure selected dependencies are upgraded (or downgraded) to "
"the latest allowed version. If DEP is not part of your application "
"dependencies anymore, this option has no effect."
),
),
upgrade_all: bool = typer.Option(
Expand Down Expand Up @@ -80,7 +79,7 @@ def sync(
sync_operation(
ctx.obj.python,
upgrade_all,
to_upgrade,
comma_split(to_upgrade),
editable,
extras=[],
uninstall_unneeded=uninstall_unneeded,
Expand Down
12 changes: 11 additions & 1 deletion src/pip_deepfreeze/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import subprocess
from pathlib import Path
from subprocess import CalledProcessError
from typing import IO, Any, Dict, Iterator, Optional, Sequence, Union
from typing import IO, Any, Dict, Iterator, List, Optional, Sequence, Union

import typer

Expand Down Expand Up @@ -82,3 +82,13 @@ def check_output(
cmd_str = shlex_join(str(item) for item in cmd)
log_error(f"Error running: {cmd_str}.")
raise typer.Exit(1)


def comma_split(s: str) -> List[str]:
if not s:
return []
s = s.strip()
if not s:
return []
items = [item.strip() for item in s.split(",")]
return [item for item in items if item]
16 changes: 16 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pip_deepfreeze.utils import (
check_call,
check_output,
comma_split,
decrease_verbosity,
increase_verbosity,
log_debug,
Expand Down Expand Up @@ -82,3 +83,18 @@ def test_check_output(capsys):
check_output([sys.executable, "-c", "import sys; sys.exit(1)"])
assert e.value.exit_code == 1
assert "Error running: " in capsys.readouterr().err


@pytest.mark.parametrize(
"s, expected",
[
(None, []),
("", []),
(" ", []),
(" a", ["a"]),
("a, b", ["a", "b"]),
("a,,b, c ", ["a", "b", "c"]),
],
)
def test_comma_split(s, expected):
assert comma_split(s) == expected