-
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.
* add find_latest_version * add cli * update changelog * fix increase minor in the case when patch contains characters * fix typo in test file name
- Loading branch information
1 parent
60a5bc0
commit d546d5d
Showing
7 changed files
with
113 additions
and
2 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
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 @@ | ||
import re | ||
import subprocess | ||
from typing import Optional | ||
|
||
|
||
def find_latest_version(pkg_name: str, major: Optional[int] = None) -> str: | ||
output = subprocess.check_output( | ||
[ | ||
"pip", | ||
"install", | ||
"--no-deps", | ||
"--ignore-installed", | ||
"--no-cache-dir", | ||
"--dry-run", | ||
f"{pkg_name}{f'=={major}.*' if major is not None else ''}", | ||
], | ||
stderr=subprocess.DEVNULL, | ||
) | ||
last_line = output.decode("utf-8").splitlines()[-1] | ||
regex_rule = f"{pkg_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"{pkg_name}-") :] | ||
|
||
|
||
def increase_minor(version: str) -> str: | ||
major, minor, patch = version.split(".") | ||
assert major.isdigit() and minor.isdigit() | ||
return f"{major}.{int(minor) + 1}.0" |
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,27 @@ | ||
from test.cli_utilities import invoke_dac_next_version | ||
|
||
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(pkg_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(pkg_name="pandas", major=0) | ||
|
||
|
||
def test_if_pkg_does_not_exist_then_find_package_raises_exception(): | ||
with pytest.raises(Exception): | ||
find_latest_version(pkg_name="non-existing-package") | ||
|
||
|
||
def test_if_next_version_without_major_spec_then_return_latest_version_with_minor_upgrade(): | ||
result = invoke_dac_next_version(pkg_name="rainbow-saddle") | ||
assert result.stdout == "0.5.0\n" | ||
|
||
|
||
def test_if_next_version_with_major_spec_then_return_minor_upgrade_for_that_major(): | ||
result = invoke_dac_next_version(pkg_name="pandas", major=0) | ||
assert result.stdout == "0.26.0\n" |
Empty file.
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,13 @@ | ||
import pytest | ||
from dac._version_management import increase_minor | ||
|
||
|
||
def test_increase_minor_then_return_version_with_increased_minor(): | ||
assert "0.6.0" == increase_minor(version="0.5.0") | ||
assert "0.6.0" == increase_minor(version="0.5.1rc0") | ||
|
||
|
||
@pytest.mark.parametrize("version", ["0", "0.5", "guess.what.now", "guess.0.now"]) | ||
def test_if_invalid_version_then_increase_minor_raises_exception(version): | ||
with pytest.raises(Exception): | ||
increase_minor(version=version) |