Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 31, 2024
1 parent 7bb153b commit 1d2e892
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/ogdc_runner/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from __future__ import annotations

import os
import tempfile
import subprocess
import tempfile
import time
from pathlib import Path
from urllib.parse import urlparse

import click
Expand All @@ -16,30 +14,31 @@
# handling github by
# checking if path is a URL
def is_url(recipe_path):
""" Check if the path is a valid URL."""
"""Check if the path is a valid URL."""
parsed = urlparse(recipe_path)
return parsed.scheme in ('http', 'https') and parsed.netloc != ''
return parsed.scheme in ("http", "https") and parsed.netloc != ""


def convert_url_to_ssh(recipe_path):
""" Convert https github url to ssh format."""
"""Convert https github url to ssh format."""
parsed = urlparse(recipe_path)
if parsed.scheme != "https" or "github.com" not in parsed.netloc:
raise ValueError("Invalid GitHub HTTPS URL")
# extract just the repo path
repo_path = parsed.path.lstrip("/")
repo_path = parsed.path.lstrip("/")
return f"[email protected]:{repo_path}.git"


def clone_repo(ssh_url):
"""Clone the repository into a temporary directory."""
temp_dir = tempfile.mkdtemp()
try:
subprocess.run(['git', 'clone', ssh_url, temp_dir], check=True)
subprocess.run(["git", "clone", ssh_url, temp_dir], check=True)
return temp_dir
except subprocess.CalledProcessError as e:
print(f"Error cloning repository: {e}")


# use that as a local path for submission
# need to figure out how to best do this for if its a url - this is a temporary solution
recipe_path = click.argument(
Expand All @@ -55,11 +54,7 @@ def clone_repo(ssh_url):
# path_type=Path,
# ),
)
recipe_name = click.argument(
"recipe_name",
required=False,
type = str
)
recipe_name = click.argument("recipe_name", required=False, type=str)


@click.group
Expand All @@ -72,7 +67,7 @@ def _submit_workflow(recipe_path) -> str:
print(f"Detected URL: {recipe_path}. Cloning repository...")
ssh_url = convert_url_to_ssh(recipe_path)
clone_repo(ssh_url)
else:
else:
workflow = make_simple_workflow(
recipe_dir=recipe_path,
)
Expand Down

0 comments on commit 1d2e892

Please sign in to comment.