Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
yangky11 committed Dec 3, 2024
1 parent b832856 commit fe8ee85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lean_dojo/data_extraction/lean.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

_URL_REGEX = re.compile(r"(?P<url>.*?)/*")

_SSH_TO_HTTPS_REGEX = re.compile(r"^git@github\.com:(.+)/(.+)(?:\.git)?$")
_SSH_TO_HTTPS_REGEX = re.compile(r"git@github\.com:(?P<user>.+)/(?P<repo>.+)\.git")

REPO_CACHE_PREFIX = "repos"

Expand All @@ -70,7 +70,13 @@ def normalize_url(url: str, repo_type: RepoType = RepoType.GITHUB) -> str:
if repo_type == RepoType.LOCAL: # Convert to absolute path if local.
return os.path.abspath(url)
# Remove trailing `/`.
return _URL_REGEX.fullmatch(url)["url"] # type: ignore
url = _URL_REGEX.fullmatch(url)["url"] # type: ignore
return ssh_to_https(url)


def ssh_to_https(url: str) -> str:
m = _SSH_TO_HTTPS_REGEX.fullmatch(url)
return f"https://github.com/{m.group('user')}/{m.group('repo')}" if m else url


def get_repo_type(url: str) -> Optional[RepoType]:
Expand All @@ -81,8 +87,7 @@ def get_repo_type(url: str) -> Optional[RepoType]:
Returns:
Optional[str]: The type of the repository (None if the repo cannot be found).
"""
m = _SSH_TO_HTTPS_REGEX.match(url)
url = f"https://github.com/{m.group(1)}/{m.group(2)}" if m else url
url = ssh_to_https(url)
parsed_url = urllib.parse.urlparse(url) # type: ignore
if parsed_url.scheme in ["http", "https"]:
# Case 1 - GitHub URL.
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from lean_dojo import *


MINIF2F_URL = "git@github.com:yangky11/miniF2F-lean4.git"
BATTERIES_URL = "https://github.com/leanprover-community/batteries"
AESOP_URL = "https://github.com/leanprover-community/aesop"
MATHLIB4_URL = "https://github.com/leanprover-community/mathlib4"
LEAN4_EXAMPLE_URL = "https://github.com/yangky11/lean4-example"
EXAMPLE_COMMIT_HASH = "3f8c5eb303a225cdef609498b8d87262e5ef344b"
REMOTE_EXAMPLE_URL = "https://gitee.com/rexzong/lean4-example"
URLS = [
MINIF2F_URL,
BATTERIES_URL,
AESOP_URL,
MATHLIB4_URL,
Expand Down

0 comments on commit fe8ee85

Please sign in to comment.