Convert a link to a file on a github repo in a link to the raw github object.
(url_path: str)
| 109 | |
| 110 | |
| 111 | def convert_github_url(url_path: str) -> Tuple[str, Optional[str]]: |
| 112 | """Convert a link to a file on a github repo in a link to the raw github object.""" |
| 113 | parsed = urlparse(url_path) |
| 114 | sub_directory = None |
| 115 | if parsed.scheme in ("http", "https", "s3") and parsed.netloc == "github.com": |
| 116 | if "blob" in url_path: |
| 117 | if not url_path.endswith(".py"): |
| 118 | raise ValueError(f"External import from github at {url_path} should point to a file ending with '.py'") |
| 119 | url_path = url_path.replace("blob", "raw") # Point to the raw file |
| 120 | else: |
| 121 | # Parse github url to point to zip |
| 122 | github_path = parsed.path[1:] |
| 123 | repo_info, branch = github_path.split("/tree/") if "/tree/" in github_path else (github_path, "master") |
| 124 | repo_owner, repo_name = repo_info.split("/") |
| 125 | url_path = f"https://github.com/{repo_owner}/{repo_name}/archive/{branch}.zip" |
| 126 | sub_directory = f"{repo_name}-{branch}" |
| 127 | return url_path, sub_directory |
| 128 | |
| 129 | |
| 130 | def increase_load_count(name: str, resource_type: str): |
no outgoing calls
no test coverage detected
searching dependent graphs…