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 #23 from MousaZeidBaker/restricted-dependencies
Browse files Browse the repository at this point in the history
Restricted dependencies
  • Loading branch information
MousaZeidBaker authored Jan 8, 2022
2 parents 17209ee + 4c09fb2 commit 5808fa9
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 164 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
runs-on: ubuntu-latest
environment: testpypi
strategy:
fail-fast: false
matrix:
python-version: [ '3.6', '3.7', '3.8', '3.9' ]
steps:
Expand Down Expand Up @@ -47,7 +48,7 @@ jobs:
run: |
source $(poetry env info --path)/bin/activate # activate virtual environment
NEW_VERSION=$(poetry version --short)
git fetch --no-tags && git checkout master
git fetch --no-tags && git checkout --force master
OLD_VERSION=$(poetry version --short)
echo "NEW_VERSION ${NEW_VERSION} OLD_VERSION ${OLD_VERSION}"
if [[ "$NEW_VERSION" == "$OLD_VERSION" ]]; then
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ Sort imports
```shell
isort .
```

Install current project from branch
```shell
poetry add git+https://github.com/MousaZeidBaker/poetryup.git#branch-name
```
297 changes: 160 additions & 137 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poetryup"
version = "0.3.15"
version = "0.4.0"
description = "Update dependencies and bump their version in the pyproject.toml file"
authors = ["Mousa Zeid Baker"]
packages = [
Expand Down Expand Up @@ -31,12 +31,15 @@ tomlkit = "^0.7.2"
[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
pytest-mock = "^3.6.1"
black = "^20.8b1"
black = [
{version = "^20.8b1", python = "<=3.6.2"},
{version = "^21.12b0", python = ">3.6.2"},
]
flake8 = "^4.0.1"
flake8-black = "^0.2.3"
flake8-isort = "^4.1.1"
isort = { version = "^5.9.3", python = "^3.6.1" }
pre-commit = { version = "^2.15.0", python = "^3.6.1" }
isort = { version = "^5.10.1", python = "^3.6.1" }
pre-commit = { version = "^2.16.0", python = "^3.6.1" }

[tool.poetry.scripts]
poetryup = "poetryup.main:main"
Expand Down
37 changes: 22 additions & 15 deletions src/poetryup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import List

import tomlkit
from tomlkit.items import String
from tomlkit import items
from tomlkit.toml_document import TOMLDocument

from poetryup import utils
Expand Down Expand Up @@ -81,22 +81,29 @@ def _bump_versions_in_pyproject(

for dependency in dependencies:
value = utils.lookup_tomlkit_table(
table=pyproject["tool"]["poetry"], key=dependency.name
table=pyproject["tool"]["poetry"],
key=dependency.name,
)

if type(value) is not String:
logging.info(
f"Bumping skipped for dependency named: {dependency.name}"
)
continue # skip if dependency is complex or if not found

if value.startswith(("^", "~")):
new_version = value[0] + dependency.version
utils.update_tomlkit_table(
table=pyproject["tool"]["poetry"],
key=dependency.name,
new_value=new_version,
)
if type(value) is items.String and value.startswith(("^", "~")):
new_value = value[0] + dependency.version
elif (
type(value) is items.InlineTable
and "version" in value
and value["version"].startswith(("^", "~"))
):
new_value = value
new_value["version"] = value["version"][0] + dependency.version
else:
# skip if exact version or not found or complex dependency
logging.info(f"Bumping skipped for dependency: {dependency.name}")
continue

utils.update_tomlkit_table(
table=pyproject["tool"]["poetry"],
key=dependency.name,
new_value=new_value,
)

return pyproject

Expand Down
14 changes: 7 additions & 7 deletions src/poetryup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from typing import Any

from tomlkit.items import String, Table
from tomlkit import items


def lookup_tomlkit_table(table: Table, key: str) -> Any:
def lookup_tomlkit_table(table: items.Table, key: str) -> Any:
"""Lookup value recursively in a tomlkit Table
Args:
Expand All @@ -17,19 +17,19 @@ def lookup_tomlkit_table(table: Table, key: str) -> Any:
"""

for item_key, item_value in table.items():
if item_key.lower() == key and type(item_value) == String:
if item_key.lower() == key:
return item_value

for value in table.values():
if type(value) is Table:
if type(value) is items.Table:
lookup = lookup_tomlkit_table(table=value, key=key)
if lookup is not None:
return lookup

return None


def update_tomlkit_table(table: Table, key: str, new_value: Any) -> bool:
def update_tomlkit_table(table: items.Table, key: str, new_value: Any) -> bool:
"""Update value in a tomlkit Table
Args:
Expand All @@ -42,12 +42,12 @@ def update_tomlkit_table(table: Table, key: str, new_value: Any) -> bool:
"""

for item_key, item_value in table.items():
if item_key.lower() == key and type(item_value) == String:
if item_key.lower() == key:
table[item_key] = new_value
return True

for item_value in table.values():
if type(item_value) is Table:
if type(item_value) is items.Table:
updated = update_tomlkit_table(
table=item_value, key=key, new_value=new_value
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[tool.poetry]
name = "test-poetryup"
version = "0.1.0"
description = "Test PoetryUp"
authors = ["Mousa Zeid Baker"]
packages = [
{ include = "test_poetryup", from = "src" }
]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/MousaZeidBaker/poetryup"
repository = "https://github.com/MousaZeidBaker/poetryup"
keywords=[
"packaging",
"dependency",
"poetry",
"poetryup",
]
include = ["LICENSE"]

[tool.poetry.dependencies]
python = "^3.6"
poetryup = {version = "^0.2.0", python = "<3.7"}

[tool.poetry.dev-dependencies]

[tool.poetry.scripts]
poetryup = "src.test_poetryup.test_poetryup:main"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[tool.poetry]
name = "test-poetryup"
version = "0.1.0"
description = "Test PoetryUp"
authors = ["Mousa Zeid Baker"]
packages = [
{ include = "test_poetryup", from = "src" }
]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/MousaZeidBaker/poetryup"
repository = "https://github.com/MousaZeidBaker/poetryup"
keywords=[
"packaging",
"dependency",
"poetry",
"poetryup",
]
include = ["LICENSE"]

[tool.poetry.dependencies]
python = "^3.6"
poetryup = {version = "^0.1.0", python = "<3.7"}

[tool.poetry.dev-dependencies]

[tool.poetry.scripts]
poetryup = "src.test_poetryup.test_poetryup:main"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 5808fa9

Please sign in to comment.