Skip to content

Commit

Permalink
Merge pull request #66 from sdn4z/feature/support_poetry_1_5_and_above
Browse files Browse the repository at this point in the history
Support poetry.lock version >= 1.5
  • Loading branch information
yeisonvargasf authored Oct 17, 2023
2 parents 0838117 + ae37324 commit 7db0452
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dparse/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def parse(self):
name = dep['name']
spec = "=={version}".format(
version=Version(dep['version']))
section = dep['category']
section = dep.get('category')
except KeyError:
raise KeyError("Malformed poetry lock file")
except InvalidVersion:
Expand Down
51 changes: 50 additions & 1 deletion tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def test_pipfile_lock_with_invalid_json():
assert isinstance(throw, MalformedDependencyFileError)


def test_poetry_lock():
def test_poetry_lock_version_lower_than_1_5():
content = """
[[package]]
name = "certifi"
Expand Down Expand Up @@ -407,6 +407,55 @@ def test_poetry_lock_with_invalid_toml():
assert isinstance(throw, MalformedDependencyFileError)


def test_poetry_lock_version_greater_than_1_5():
"""In poetry's version 1.5, the `category` field was removed. We need then to be able to handle such scenario."""

content = """
[[package]]
name = "certifi"
version = "2022.6.15"
description = "Python package for providing Mozilla's CA Bundle."
optional = false
python-versions = ">=3.6"
[[package]]
name = "attrs"
version = "22.1.0"
description = "Classes Without Boilerplate"
optional = false
python-versions = ">=3.5"
[package.extras]
dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"]
docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"]
tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "cloudpickle"]
tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "cloudpickle"]
[metadata]
lock-version = "1.1"
python-versions = "^3.9"
content-hash = "96e49f07dcfd53e21489b9a7f3451d3b76515f33496173d989395e1898ae9a26"
[metadata.files]
certifi = []
attrs = []
"""

dep_file = parse(content, file_type=filetypes.poetry_lock)

assert dep_file.dependencies[0].name == 'certifi'
assert dep_file.dependencies[0].specs == SpecifierSet('==2022.6.15')
assert dep_file.dependencies[0].dependency_type == 'poetry.lock'
assert dep_file.dependencies[0].section is None
assert dep_file.dependencies[0].hashes == ()

assert dep_file.dependencies[1].name == 'attrs'
assert dep_file.dependencies[1].specs == SpecifierSet('==22.1.0')
assert dep_file.dependencies[1].dependency_type == 'poetry.lock'
assert dep_file.dependencies[1].section is None
assert dep_file.dependencies[1].hashes == ()


def test_pyproject_toml() -> None:
content = """
[project]
Expand Down

0 comments on commit 7db0452

Please sign in to comment.