-
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
Showing
2 changed files
with
67 additions
and
29 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,59 @@ | ||
import shutil | ||
|
||
from pathlib import Path | ||
from apps_exceptions import ValidationErrors | ||
|
||
|
||
def is_valid_bump_type(bump: str) -> bool: | ||
if bump in ('patch', 'minor', 'major'): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def is_valid_version(version: str) -> bool: | ||
if not version: | ||
return False | ||
|
||
return version.count('.') == 2 | ||
|
||
|
||
def bump_version(version: str, bump: str) -> str: | ||
parts = version.split('.') | ||
if len(parts) != 3: | ||
raise ValueError(f'Invalid version {version!r}') | ||
if bump == 'patch': | ||
parts[2] = str(int(parts[2]) + 1) | ||
elif bump == 'minor': | ||
parts[1] = str(int(parts[1]) + 1) | ||
parts[2] = '0' | ||
elif bump == 'major': | ||
parts[0] = str(int(parts[0]) + 1) | ||
parts[1] = '0' | ||
parts[2] = '0' | ||
|
||
return '.'.join(parts) | ||
|
||
|
||
def rename_versioned_dir(version: str, new_version: str, train_name: str, app_dir: Path) -> None: | ||
verrors = ValidationErrors() | ||
|
||
if not is_valid_version(version) or not is_valid_version(new_version): | ||
verrors.add('version_bump', f'Invalid version {version!r} or {new_version!r}') | ||
|
||
if not app_dir.is_dir(): | ||
verrors.add('version_bump', f'{app_dir.name!r} is not a directory') | ||
|
||
verrors.check() | ||
|
||
dir_base = app_dir / 'templates/library' / train_name / app_dir.name | ||
curr_versioned_dir = dir_base / f'v{version}' | ||
new_versioned_dir = dir_base / f'v{new_version}' | ||
if not curr_versioned_dir.is_dir(): | ||
return | ||
|
||
if new_versioned_dir.is_dir(): | ||
verrors.add('version_bump', f'App {app_dir.name!r} library with version {new_version!r} already exists') | ||
shutil.move(curr_versioned_dir, new_versioned_dir) | ||
|
||
print(f'[\033[92mOK\x1B[0m]\tUpdated app {app_dir.name!r} library from {version!r} to {new_version!r}') |