Skip to content

Commit fcd4885

Browse files
Fixed a bug that only allowed harvesting if not using poetry.
1 parent 4f937d7 commit fcd4885

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/hermes_toml/harvest.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TomlHarvestPlugin(HermesHarvestPlugin):
2323
("runtimePlatform", "requires-python"), ("author", "authors"),
2424
("maintainer", "maintainers"), ("keywords", "keywords")
2525
],
26-
"tool.poetry": [
26+
"poetry": [
2727
("name", "name"), ("version", "version"), ("description", "description"),
2828
("author", "authors"), ("maintainer", "maintainers"), ("url", "homepage"),
2929
("codeRepository", "repository"), ("keywords", "keywords")
@@ -64,8 +64,18 @@ def read_from_toml(cls, file):
6464
#if more than one table existis raise an error as
6565
#the information could be overlapping and there should only be one table
6666
for table, mapping in cls.table_with_mapping.items():
67-
table = data.get(table)
67+
#choose correct dictionary representing the table
68+
if table == "project":
69+
table = data.get(table)
70+
else:
71+
temp = data.get("tool")
72+
if temp is None:
73+
continue
74+
table = temp.get(table)
75+
76+
#check if the table exists
6877
if not table is None:
78+
#if the table exists
6979
if len(ret_data.keys()) != 0:
7080
raise ValueError("Both project and tool.poetry table exist.")
7181
#read the data from the table

test/hermes_toml_test/test_harvest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def toml_file(tmp_path_factory):
3434

3535
@pytest.mark.parametrize("in_data, out_data", [
3636
({}, {}), ({"project": {"name":"a"}}, {"name": "a"}),
37-
({"tool.poetry": {"name":"a"}}, {"name": "a"}),
37+
({"tool": {"poetry": {"name":"a"}}}, {"name": "a"}),
3838
({"project":{"name":"a"}, "a":{"b":"c"}}, {"name":"a"}),
3939
({"project":{"name":"a", "requires-python":">3.7"}}, {"name":"a", "runtimePlatform":"Python >3.7"}),
4040
({"project":{"authors":{"givenName":"a"}}}, {"author":{"givenName":"a", "@type":"Person"}}),
@@ -49,9 +49,9 @@ def test_read_from_toml(in_data, out_data, toml_file):
4949
assert TomlHarvestPlugin.read_from_toml(str(toml_file)) == out_data
5050

5151
@pytest.mark.parametrize("in_data", [
52-
({"project": {"authors":"a"}}), ({"tool.poetry": {"authors":"a"}}),
53-
({"project": {"authors":["a"]}}), ({"tool.poetry": {"authors":["a"]}}),
54-
({"project": {"name":"a"}, "tool.poetry": {"name":"a"}})
52+
({"project": {"authors":"a"}}), ({"tool": {"poetry": {"authors":"a"}}}),
53+
({"project": {"authors":["a"]}}), ({"tool": {"poetry": {"authors":["a"]}}}),
54+
({"project": {"name":"a"}, "tool": {"poetry": {"name":"a"}}})
5555
])
5656
def test_read_from_toml_with_error(in_data, toml_file):
5757
toml.dump(in_data, open(toml_file, "w", encoding="utf8"))

0 commit comments

Comments
 (0)