Skip to content

Commit 30473d7

Browse files
Deduplicate some logic
1 parent 8f72751 commit 30473d7

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/rapids_pre_commit_hooks/pyproject_license.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,12 @@ def find_value_location(document, key, append):
5757
def check_pyproject_license(linter, args):
5858
document = tomlkit.loads(linter.content)
5959
try:
60+
add_project_table = True
6061
project_table = document["project"]
61-
except tomlkit.exceptions.NonExistentKey:
62-
loc = (len(linter.content), len(linter.content))
63-
linter.add_warning(
64-
loc, f'add project.license with value {{ text = "{RAPIDS_LICENSE}" }}'
65-
).add_replacement(
66-
loc,
67-
"[project]\nlicense = "
68-
f"{{ text = {tomlkit.string(RAPIDS_LICENSE).as_string()} }}\n",
69-
)
70-
return
71-
72-
try:
62+
add_project_table = project_table.is_super_table()
7363
license_value = project_table["license"]["text"]
7464
except tomlkit.exceptions.NonExistentKey:
75-
if project_table.is_super_table():
65+
if add_project_table:
7666
loc = (len(linter.content), len(linter.content))
7767
linter.add_warning(
7868
loc, f'add project.license with value {{ text = "{RAPIDS_LICENSE}" }}'

0 commit comments

Comments
 (0)