Skip to content

Commit

Permalink
Print stable version in the right place using --list option (#44)
Browse files Browse the repository at this point in the history
* Print the stable version in the right place using `--list` option

* Update black

* Format
  • Loading branch information
mondeja authored Apr 26, 2022
1 parent f489a00 commit 6c4c034
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.18
current_version = 0.0.19

[bumpversion:file:blender_downloader/__init__.py]

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
hooks:
- id: setup-cfg-fmt
- repo: https:/psf/black
rev: 21.12b0
rev: 22.3.0
hooks:
- id: black
language_version: python3
Expand Down
19 changes: 14 additions & 5 deletions blender_downloader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
__author__ = "mondeja"
__description__ = "Multiplatform Blender portable release downloader script."
__title__ = "blender-downloader"
__version__ = "0.0.18"
__version__ = "0.0.19"

QUIET = False

Expand Down Expand Up @@ -139,7 +139,7 @@ def build_parser():
parser.add_argument(
"--bits",
dest="bits",
default=64 if sys.maxsize > 2 ** 32 else 32,
default=64 if sys.maxsize > 2**32 else 32,
type=int,
help="Operative system bits. Keep in mind that Blender v2.80 was the"
" latest release with support operative systems with 32 bits.",
Expand Down Expand Up @@ -879,11 +879,12 @@ def list_available_blender_versions(
"stable",
use_cache=use_cache,
)
sys.stdout.write(f"{stable_version}\n")
versions_found.append(stable_version)
n_versions += 1
if maximum_versions < 3:
sys.stdout.write(f"{stable_version}\n")
return 0
stable_Version = Version(stable_version)
_stable_version_printed = False

url = "https://download.blender.org/release/"
response_lines = GET(url, use_cache=use_cache).splitlines()
Expand Down Expand Up @@ -945,9 +946,17 @@ def list_available_blender_versions(
continue

# print version
# print stable version in their correct place
if Version(version) < stable_Version and not _stable_version_printed:
n_versions += 1
sys.stdout.write(f"{stable_version}\n")
_stable_version_printed = True
if n_versions >= maximum_versions:
break

versions_found.append(version)
n_versions += 1
sys.stdout.write(f"{version}\n")
n_versions += 1

if n_versions >= maximum_versions:
break
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = blender_downloader
version = 0.0.18
version = 0.0.19
description = Multiplatorm Blender downloader.
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
12 changes: 7 additions & 5 deletions tests/test_list_available_blender_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def __repr__(self):
@pytest.mark.parametrize("bits", (64, 32))
@pytest.mark.parametrize("arch", (None, "arm64"))
def test_list_available_blender_versions(
maximum_versions, operative_system, bits, arch
maximum_versions,
operative_system,
bits,
arch,
):
mocked_stdout = io.StringIO()
with contextlib.redirect_stdout(mocked_stdout):
Expand All @@ -58,11 +61,10 @@ def test_list_available_blender_versions(

min_version_supported = BlenderVersion(MINIMUM_VERSION_SUPPPORTED)

for i, raw_version in enumerate(stdout_lines):
for raw_version in stdout_lines:
version = BlenderVersion(raw_version)
assert min_version_supported < version

if i > 2: # first version is the stable one
if prev_version is not None:
assert version < prev_version
if prev_version is not None:
assert version < prev_version
prev_version = version

0 comments on commit 6c4c034

Please sign in to comment.