-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60a5bc0
commit 1a6ec88
Showing
2 changed files
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import re | ||
import subprocess | ||
from typing import Optional | ||
|
||
|
||
def find_latest_version(library_name: str, major: Optional[int] = None) -> str: | ||
output = subprocess.check_output( | ||
[ | ||
"pip", | ||
"install", | ||
"--no-deps", | ||
"--ignore-installed", | ||
"--no-cache-dir", | ||
"--dry-run", | ||
f"{library_name}{f'=={major}.*' if major is not None else ''}", | ||
], | ||
stderr=subprocess.DEVNULL, | ||
) | ||
last_line = output.decode("utf-8").splitlines()[-1] | ||
regex_rule = f"{library_name.replace('_', '-')}-{major if major is not None else ''}.[^ ]+" | ||
match = re.search(regex_rule, last_line) | ||
assert match is not None | ||
return match[0][len(f"{library_name}-") :] |
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,15 @@ | ||
import pytest | ||
from dac._version_management import find_latest_version | ||
|
||
|
||
def test_if_find_latest_version_is_called_then_return_latest_version(): | ||
assert "0.5" == find_latest_version(library_name="rainbow-server") | ||
|
||
|
||
def test_if_find_latest_version_is_called_with_major_constraint_then_return_latest_major_version(): | ||
assert "0.25.3" == find_latest_version(library_name="pandas", major=0) | ||
|
||
|
||
def test_if_pkg_does_not_exist_then_find_package_return_none(): | ||
with pytest.raises(Exception): | ||
find_latest_version(library_name="non-existing-package") |