Skip to content

Commit 9ec705a

Browse files
committed
Factored out supported URI schemes to a variable
Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com>
1 parent 952f6a5 commit 9ec705a

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

cfbs/cfbs_config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
load_bundlenames,
1414
)
1515
from cfbs.internal_file_management import (
16+
SUPPORTED_URI_SCHEMES,
1617
clone_url_repo,
1718
fetch_archive,
1819
SUPPORTED_ARCHIVES,
@@ -132,7 +133,7 @@ def _add_using_url(
132133
if url.endswith(SUPPORTED_ARCHIVES):
133134
config_path, url_commit = fetch_archive(url, checksum)
134135
else:
135-
assert url.startswith(("https://", "git://", "ssh://"))
136+
assert url.startswith(SUPPORTED_URI_SCHEMES)
136137
config_path, url_commit = clone_url_repo(url)
137138

138139
if "@" in url and (url.rindex("@") > url.rindex(".")):
@@ -386,7 +387,7 @@ def add_command(
386387
before = {m["name"] for m in self.get("build", [])}
387388

388389
if to_add[0].endswith(SUPPORTED_ARCHIVES) or to_add[0].startswith(
389-
("https://", "git://", "ssh://")
390+
SUPPORTED_URI_SCHEMES
390391
):
391392
self._add_using_url(
392393
url=to_add[0],

cfbs/commands.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from cfbs.cfbs_config import CFBSConfig, CFBSReturnWithoutCommit
4545
from cfbs.validate import validate_config
4646
from cfbs.internal_file_management import (
47+
SUPPORTED_URI_SCHEMES,
4748
fetch_archive,
4849
get_download_path,
4950
local_module_copy,
@@ -455,7 +456,7 @@ def _get_modules_by_url(name) -> list:
455456
msg = ""
456457
files = []
457458
for name in to_remove:
458-
if name.startswith(("https://", "ssh://", "git://")):
459+
if name.startswith(SUPPORTED_URI_SCHEMES):
459460
matches = _get_modules_by_url(name)
460461
if not matches:
461462
user_error("Could not find module with URL '%s'" % name)

cfbs/internal_file_management.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
_SUPPORTED_TAR_TYPES = (".tar.gz", ".tgz")
3030
SUPPORTED_ARCHIVES = (".zip",) + _SUPPORTED_TAR_TYPES
31+
SUPPORTED_URI_SCHEMES = ("https://", "ssh://", "git://")
3132

3233

3334
def local_module_name(module_path):
@@ -113,7 +114,7 @@ def local_module_copy(module, counter, max_length):
113114

114115

115116
def _get_path_from_url(url):
116-
if not url.startswith(("https://", "ssh://", "git://")):
117+
if not url.startswith(SUPPORTED_URI_SCHEMES):
117118
if "://" in url:
118119
return user_error("Unsupported URL protocol in '%s'" % url)
119120
else:
@@ -153,7 +154,7 @@ def _clone_and_checkout(url, path, commit):
153154

154155

155156
def clone_url_repo(repo_url):
156-
assert repo_url.startswith(("https://", "ssh://", "git://"))
157+
assert repo_url.startswith(SUPPORTED_URI_SCHEMES)
157158

158159
commit = None
159160
if "@" in repo_url and (repo_url.rindex("@") > repo_url.rindex(".")):

0 commit comments

Comments
 (0)