This repository has been archived by the owner on Dec 18, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from MousaZeidBaker/refactor/poetry
Refactor/poetry
- Loading branch information
Showing
9 changed files
with
117 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import logging | ||
from typing import List, Optional | ||
|
||
from packaging import version as version_ | ||
|
||
from poetryup.core.cmd import cmd_run | ||
|
||
|
||
class Poetry: | ||
"""A helper class to run poetry commands""" | ||
|
||
@property | ||
def version(self) -> str: | ||
"""Return the installed poetry version""" | ||
|
||
output = cmd_run(["poetry", "--version"], capture_output=True) | ||
# output is: 'Poetry (version x.y.z)' | ||
return output.rsplit(" ", 1).pop().strip().replace(")", "") | ||
|
||
def show(self) -> str: | ||
"""Run poetry show command | ||
Returns: | ||
The output from the poetry show command | ||
""" | ||
|
||
return cmd_run(["poetry", "show", "--tree"], capture_output=True) | ||
|
||
def update(self) -> None: | ||
"""Run poetry update command""" | ||
|
||
cmd_run(["poetry", "update"]) | ||
|
||
def add( | ||
self, | ||
packages: List[str], | ||
group: Optional[str], | ||
) -> None: | ||
"""Run poetry add command | ||
Args: | ||
package: The package(s) to add | ||
group: The group the package(s) should be added to | ||
""" | ||
|
||
if group is None or group == "default": | ||
cmd_run(["poetry", "add", *packages]) | ||
elif group == "dev" and self.version < version_.parse("1.2.0"): | ||
cmd_run(["poetry", "add", *packages, f"--{group}"]) | ||
elif self.version >= version_.parse("1.2.0"): | ||
cmd_run(["poetry", "add", *packages, "--group", group]) | ||
else: | ||
logging.warning(f"Couldn't add package(s) '{packages}'") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pytest_mock import MockerFixture | ||
|
||
from poetryup.core.poetry import Poetry | ||
|
||
|
||
def test_version_poetry_1_1_x( | ||
mocker: MockerFixture, | ||
) -> None: | ||
mocker.patch( | ||
"poetryup.core.poetry.cmd_run", | ||
return_value="Poetry version 1.2.3", | ||
) | ||
poetry = Poetry() | ||
assert poetry.version == "1.2.3" | ||
|
||
|
||
def test_version_poetry_1_2_x( | ||
mocker: MockerFixture, | ||
) -> None: | ||
mocker.patch( | ||
"poetryup.core.poetry.cmd_run", | ||
return_value="Poetry (version 1.2.3)", | ||
) | ||
poetry = Poetry() | ||
assert poetry.version == "1.2.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters