Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #57 from MousaZeidBaker/feat/verbosity
Browse files Browse the repository at this point in the history
feat: add verbosity option
  • Loading branch information
MousaZeidBaker authored Jun 27, 2022
2 parents fbcc3cf + 1ca4907 commit dec9ae7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poetryup"
version = "0.8.2"
version = "0.9.0"
description = "Update dependencies and bump their version in the pyproject.toml file"
authors = ["Mousa Zeid Baker"]
packages = [
Expand Down
10 changes: 8 additions & 2 deletions src/poetryup/core/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def update_dependencies(
dependency.name
] = dependency.version
else:
logging.info(f"Couldn't bump dependency '{dependency.name}'")
logging.warning(f"Couldn't bump dependency '{dependency.name}'")

@staticmethod
def __get_poetry_version() -> str:
Expand All @@ -316,6 +316,7 @@ def __get_poetry_version() -> str:
Returns:
The poetry version installed
"""
logging.debug("Execute: 'poetry --version'")

if sys.version_info < (3, 7):
return subprocess.check_output(
Expand All @@ -341,6 +342,7 @@ def __run_poetry_show() -> str:
Returns:
The output from the poetry show command
"""
logging.debug("Execute: 'poetry show --tree'")

if sys.version_info < (3, 7):
return subprocess.check_output(
Expand All @@ -357,6 +359,7 @@ def __run_poetry_show() -> str:
def __run_poetry_update() -> None:
"""Run poetry update command"""

logging.debug("Execute: 'poetry update'")
subprocess.run(["poetry", "update"])

def __run_poetry_add(
Expand All @@ -372,10 +375,13 @@ def __run_poetry_add(
"""

if group is None or group == "default":
logging.debug(f"Execute: 'poetry add {packages}'")
subprocess.run(["poetry", "add", *packages])
elif group == "dev" and self.poetry_version < version_.parse("1.2.0"):
logging.debug(f"Execute: 'poetry add {packages} --{group}'")
subprocess.run(["poetry", "add", *packages, f"--{group}"])
elif self.poetry_version >= version_.parse("1.2.0"):
logging.debug(f"Execute: 'poetry add {packages} --group {group}'")
subprocess.run(["poetry", "add", *packages, f"--group {group}"])
else:
logging.info(f"Couldn't add package(s) '{packages}'")
logging.warning(f"Couldn't add package(s) '{packages}'")
21 changes: 18 additions & 3 deletions src/poetryup/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import logging
import os
import subprocess
from pathlib import Path
from typing import List
Expand All @@ -11,11 +10,18 @@
from poetryup.core.pyproject import Pyproject
from poetryup.models.dependency import Constraint

logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO").upper())

app = typer.Typer(add_completion=False)


def setup_logging(verbosity):
level = logging.WARNING
if verbosity == 1:
level = logging.INFO
elif verbosity > 1:
level = logging.DEBUG
logging.basicConfig(level=level)


@app.command()
def poetryup(
latest: bool = typer.Option(
Expand All @@ -34,8 +40,16 @@ def poetryup(
default=[],
help="The dependency groups to include.",
),
verbose: int = typer.Option(
0,
"--verbose",
"-v",
count=True,
help='Increase verbosity of messages: "-v" for info, "-vv" for debug.',
),
):
"""Update dependencies and bump their version in pyproject.toml file"""
setup_logging(verbose)

try:
pyproject_str = Path("pyproject.toml").read_text()
Expand All @@ -49,6 +63,7 @@ def poetryup(
pyproject.update_dependencies(latest, without_constraint, name, group)
Path("pyproject.toml").write_text(pyproject.dumps())
# refresh the lock file after changes in pyproject.toml
logging.debug("Execute: 'poetry lock --no-update'")
subprocess.run(["poetry", "lock", "--no-update"])


Expand Down

0 comments on commit dec9ae7

Please sign in to comment.