Skip to content

Commit 75973dc

Browse files
committed
removed duplicate function definition
1 parent 8dd7ca7 commit 75973dc

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

src/compas_invocations2/grasshopper.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ def _get_version_from_toml(toml_file: str) -> str:
7070
return version
7171

7272

73+
def _get_package_name(toml_file: str) -> str:
74+
with open(toml_file, "r") as f:
75+
pyproject_data = tomlkit.load(f)
76+
if not pyproject_data:
77+
raise invoke.Exit("Failed to load pyproject.toml.")
78+
79+
name = pyproject_data.get("project", {}).get("name", None)
80+
if not name:
81+
raise invoke.Exit("Failed to get package name from pyproject.toml.")
82+
return name
83+
84+
7385
def _get_user_object_path(context):
7486
if hasattr(context, "ghuser_cpython"):
7587
print("checking ghuser_cpython")
@@ -199,35 +211,13 @@ def publish_yak(ctx, yak_file: str, test_server: bool = False):
199211
ctx.run(f"{yak_exe_path} push {yak_file}")
200212

201213

202-
def _get_version_from_toml() -> str:
203-
with open("pyproject.toml", "r") as f:
204-
pyproject_data = tomlkit.load(f)
205-
if not pyproject_data:
206-
raise invoke.Exit("Failed to load pyproject.toml.")
207-
208-
version = pyproject_data.get("tool", {}).get("bumpversion", {}).get("current_version", None)
209-
if not version:
210-
raise invoke.Exit("Failed to get version from pyproject.toml. Please provide a version number.")
211-
return version
212-
213-
214-
def _get_package_name() -> str:
215-
with open("pyproject.toml", "r") as f:
216-
pyproject_data = tomlkit.load(f)
217-
if not pyproject_data:
218-
raise invoke.Exit("Failed to load pyproject.toml.")
219-
220-
name = pyproject_data.get("project", {}).get("name", None)
221-
if not name:
222-
raise invoke.Exit("Failed to get package name from pyproject.toml.")
223-
return name
224-
225-
226214
@invoke.task(help={"version": "New minimum version to set in the header. If not provided, current version is used."})
227215
def update_gh_header(ctx, version=None):
228216
"""Update the minimum version header of all CPython Grasshopper components."""
229-
version = version or _get_version_from_toml()
230-
package_name = _get_package_name()
217+
toml_filepath = os.path.join(ctx.base_folder, "pyproject.toml")
218+
version = version or _get_version_from_toml(toml_filepath)
219+
package_name = _get_package_name(toml_filepath)
220+
231221
new_header = f"# r: {package_name}>={version}"
232222

233223
for file in Path(ctx.ghuser_cpython.source_dir).glob("**/code.py"):

0 commit comments

Comments
 (0)