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 #35 from MousaZeidBaker/feat/constraint-property
Browse files Browse the repository at this point in the history
Feat/constraint property
  • Loading branch information
MousaZeidBaker authored Mar 23, 2022
2 parents f398517 + 60f3031 commit 54ce0ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 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.5.5"
version = "0.5.6"
description = "Update dependencies and bump their version in the pyproject.toml file"
authors = ["Mousa Zeid Baker"]
packages = [
Expand Down
29 changes: 18 additions & 11 deletions src/poetryup/pyproject.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import re
import subprocess
from dataclasses import dataclass, field
from dataclasses import dataclass
from typing import List, Optional, Union

import tomlkit
Expand All @@ -14,13 +14,23 @@ class Dependency:
"""A class to represent a dependency"""

name: str
normalized_name: str = field(init=False)
version: Union[items.String, items.InlineTable, items.Array]
group: str

def __post_init__(self):
@property
def normalized_name(self) -> str:
# https://www.python.org/dev/peps/pep-0503/#normalized-names
self.normalized_name = self.name.replace("_", "-").lower()
return self.name.replace("_", "-").lower()

@property
def constraint(self) -> str:
if type(self.version) is items.String:
if self.version[0].startswith(("^", "~")):
return self.version[0]
elif type(self.version) is items.InlineTable:
if self.version.get("version", "").startswith(("^", "~")):
return self.version["version"][0]
return ""


class Pyproject:
Expand Down Expand Up @@ -116,18 +126,15 @@ def list_lock_dependencies(self) -> List[Dependency]:
)
continue

constraint = ""
if type(dependency.version) is items.String:
if dependency.version[0].startswith(("^", "~")):
constraint = dependency.version[0]
dependency.version = constraint + lock_dep.version
dependency.version = dependency.constraint + lock_dep.version
elif (
type(dependency.version) is items.InlineTable
and dependency.version.get("version") is not None
):
if dependency.version["version"].startswith(("^", "~")):
constraint = dependency.version["version"][0]
dependency.version["version"] = constraint + lock_dep.version
dependency.version["version"] = (
dependency.constraint + lock_dep.version
)

return dependencies

Expand Down

0 comments on commit 54ce0ea

Please sign in to comment.