-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from marcelotrevisani/fb-improvements-package…
…-availability Fb improvements package availability
- Loading branch information
Showing
14 changed files
with
196 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import re | ||
from functools import lru_cache | ||
from typing import List, Optional, Tuple | ||
|
||
import requests | ||
|
||
|
||
@lru_cache(maxsize=35) | ||
def is_pkg_available(pkg_name: str, channel: str = "conda-forge") -> bool: | ||
"""Verify if the package is available on Anaconda for a specific channel. | ||
:param pkg_name: Package name | ||
:param channel: Anaconda channel | ||
:return: Return True if the package is present on the given channel | ||
""" | ||
response = requests.get( | ||
url=f"https://anaconda.org/{channel}/{pkg_name}/files", allow_redirects=False | ||
) | ||
return response.status_code == 200 | ||
|
||
|
||
def check_pkgs_availability( | ||
list_pkgs: List[str], channel: Optional[str] = None | ||
) -> List[Tuple[str, bool]]: | ||
"""Check if the list is | ||
:param list_pkgs: List with packages name | ||
:return: | ||
""" | ||
list_pkgs.sort() | ||
re_search = re.compile(r"^\s*[a-z0-9\.\-\_]+", re.IGNORECASE) | ||
|
||
result_list = [] | ||
all_pkg = set() | ||
for pkg in list_pkgs: | ||
if not pkg: | ||
continue | ||
search_result = re_search.search(pkg) | ||
if not search_result: | ||
continue | ||
|
||
pkg_name = search_result.group() | ||
if pkg_name in all_pkg: | ||
continue | ||
|
||
all_pkg.add(pkg_name) | ||
if channel: | ||
result_list.append((pkg, is_pkg_available(pkg_name, channel))) | ||
else: | ||
result_list.append((pkg, is_pkg_available(pkg_name))) | ||
return result_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from grayskull.base.pkg_info import check_pkgs_availability, is_pkg_available | ||
|
||
|
||
def test_pkg_available(): | ||
assert is_pkg_available("pytest") | ||
|
||
|
||
def test_pkg_not_available(): | ||
assert not is_pkg_available("NOT_PACKAGE_654987321") | ||
|
||
|
||
def test_check_pkgs_availability(capsys): | ||
all_pkgs = check_pkgs_availability( | ||
[ | ||
"pytest >=4.0.0,<5.0.0 # [win]", | ||
"requests", | ||
"pandas[test]", | ||
"NOT_PACKAGE_13248743", | ||
] | ||
) | ||
|
||
assert sorted(all_pkgs) == sorted( | ||
[ | ||
("pytest >=4.0.0,<5.0.0 # [win]", True), | ||
("requests", True), | ||
("pandas[test]", True), | ||
("NOT_PACKAGE_13248743", False), | ||
] | ||
) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters