Skip to content

Commit 591276b

Browse files
authored
Add package url pattern in const (#153)
Signed-off-by: Jiyeong Seok <[email protected]>
1 parent f3674cc commit 591276b

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

src/fosslight_util/_get_downloadable_url.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,11 @@
1515

1616

1717
def extract_name_version_from_link(link):
18-
# Github : https://github.com/(owner)/(repo)
19-
# npm : https://www.npmjs.com/package/(package)/v/(version)
20-
# npm2 : https://www.npmjs.com/package/@(group)/(package)/v/(version)
21-
# pypi : https://pypi.org/project/(oss_name)/(version)
22-
# pypi2 : https://files.pythonhosted.org/packages/source/(alphabet)/(oss_name)/(oss_name)-(version).tar.gz
23-
# Maven: https://mvnrepository.com/artifact/(group)/(artifact)/(version)
24-
# pub: https://pub.dev/packages/(package)/versions/(version)
25-
# Cocoapods: https://cocoapods.org/(package)
26-
pkg_pattern = {
27-
"pypi": r'https?:\/\/pypi\.org\/project\/([^\/]+)[\/]?([^\/]*)',
28-
"pypi2": r'https?:\/\/files\.pythonhosted\.org\/packages\/source\/[\w]\/([^\/]+)\/[\S]+-([^\-]+)\.tar\.gz',
29-
"maven": r'https?:\/\/mvnrepository\.com\/artifact\/([^\/]+)\/([^\/]+)\/?([^\/]*)',
30-
"npm": r'https?:\/\/www\.npmjs\.com\/package\/([^\/\@]+)(?:\/v\/)?([^\/]*)',
31-
"npm2": r'https?:\/\/www\.npmjs\.com\/package\/(\@[^\/]+\/[^\/]+)(?:\/v\/)?([^\/]*)',
32-
"pub": r'https?:\/\/pub\.dev\/packages\/([^\/]+)(?:\/versions\/)?([^\/]*)',
33-
"pods": r'https?:\/\/cocoapods\.org\/pods\/([^\/]+)'
34-
}
3518
oss_name = ""
3619
oss_version = ""
3720
if link.startswith("www."):
3821
link = link.replace("www.", "https://www.", 1)
39-
for key, value in pkg_pattern.items():
22+
for key, value in constant.PKG_PATTERN.items():
4023
p = re.compile(value)
4124
match = p.match(link)
4225
if match:
@@ -57,7 +40,7 @@ def extract_name_version_from_link(link):
5740
elif key == "pub":
5841
oss_name = f"pub:{origin_name}"
5942
oss_version = match.group(2)
60-
elif key == "pods":
43+
elif key == "cocoapods":
6144
oss_name = f"cocoapods:{origin_name}"
6245
except Exception as ex:
6346
logger.info(f"extract_name_version_from_link {key}:{ex}")

src/fosslight_util/constant.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,23 @@
1414
f'SRC_{FL_DEPENDENCY}': FL_DEPENDENCY,
1515
f'BIN_{FL_BINARY}': FL_BINARY,
1616
f'DEP_{FL_DEPENDENCY}': FL_DEPENDENCY}
17+
18+
# Github : https://github.com/(owner)/(repo)
19+
# npm : https://www.npmjs.com/package/(package)/v/(version)
20+
# npm2 : https://www.npmjs.com/package/@(group)/(package)/v/(version)
21+
# pypi : https://pypi.org/project/(oss_name)/(version)
22+
# pypi2 : https://files.pythonhosted.org/packages/source/(alphabet)/(oss_name)/(oss_name)-(version).tar.gz
23+
# Maven: https://mvnrepository.com/artifact/(group)/(artifact)/(version)
24+
# pub: https://pub.dev/packages/(package)/versions/(version)
25+
# Cocoapods : https://cocoapods.org/(package)
26+
# go : https://pkg.go.dev/(package_name_with_slash)@(version)
27+
PKG_PATTERN = {
28+
"pypi": r'https?:\/\/pypi\.org\/project\/([^\/]+)[\/]?([^\/]*)',
29+
"pypi2": r'https?:\/\/files\.pythonhosted\.org\/packages\/source\/[\w]\/([^\/]+)\/[\S]+-([^\-]+)\.tar\.gz',
30+
"maven": r'https?:\/\/mvnrepository\.com\/artifact\/([^\/]+)\/([^\/]+)\/?([^\/]*)',
31+
"npm": r'https?:\/\/www\.npmjs\.com\/package\/([^\/\@]+)(?:\/v\/)?([^\/]*)',
32+
"npm2": r'https?:\/\/www\.npmjs\.com\/package\/(\@[^\/]+\/[^\/]+)(?:\/v\/)?([^\/]*)',
33+
"pub": r'https?:\/\/pub\.dev\/packages\/([^\/]+)(?:\/versions\/)?([^\/]*)',
34+
"cocoapods": r'https?:\/\/cocoapods\.org\/pods\/([^\/]+)',
35+
"go": r'https?:\/\/pkg.go.dev\/([^\@]+)\@?v?([^\/]*)'
36+
}

0 commit comments

Comments
 (0)