Skip to content

Commit

Permalink
Add dev versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
MasloMaslane committed Apr 4, 2024
1 parent 4543c1b commit 9bc7c8f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ install_requires =
dictdiffer
importlib-resources
psutil
packaging

[options.packages.find]
where = src
Expand Down
15 changes: 12 additions & 3 deletions src/sinol_make/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def main_exn():
def main():
new_version = None
try:
if util.is_dev(__version__):
print(util.warning('You are using a development version of sinol-make. '
'It may be unstable and contain bugs.'))
new_version = util.check_for_updates(__version__)
main_exn()
except argparse.ArgumentError as err:
Expand All @@ -92,6 +95,12 @@ def main():
'https://github.com/sio2project/sinol-make/#reporting-bugs-and-contributing-code')
finally:
if new_version is not None:
print(util.warning(
f'New version of sinol-make is available (your version: {__version__}, available version: '
f'{new_version}).\nYou can update it by running `pip3 install sinol-make --upgrade`.'))
if not util.is_dev(new_version):
print(util.warning(
f'New version of sinol-make is available (your version: {__version__}, available version: '
f'{new_version}).\nYou can update it by running `pip3 install sinol-make --upgrade`.'))
elif util.is_dev(new_version):
print(util.warning(
f'New development version of sinol-make is available (your version: {__version__}, available '
f'version: {new_version}).\nYou can update it by running `pip3 install sinol-make --pre --upgrade`.'
))
40 changes: 16 additions & 24 deletions src/sinol_make/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import multiprocessing
import resource
from typing import Union
from packaging.version import parse as parse_version

from sinol_make.contest_types import get_contest_type
from sinol_make.helpers import paths, cache
Expand Down Expand Up @@ -150,10 +151,18 @@ def import_importlib_resources():
return importlib


def check_for_updates(current_version) -> Union[str, None]:
def is_dev(version):
"""
Function to check if the version is a development version.
"""
return parse_version(version).is_devrelease


def check_for_updates(current_version, check=True) -> Union[str, None]:
"""
Function to check if there is a new version of sinol-make.
:param current_version: current version of sinol-make
:param check: whether to check for new version
:return: returns new version if there is one, None otherwise
"""
importlib = import_importlib_resources()
Expand All @@ -164,8 +173,9 @@ def check_for_updates(current_version) -> Union[str, None]:

# We check for new version asynchronously, so that it doesn't slow down the program.
# If the main process exits, the check_version process will also exit.
process = multiprocessing.Process(target=check_version, daemon=True)
process.start()
if check:
process = multiprocessing.Process(target=check_version, daemon=True)
process.start()
version_file = data_dir.joinpath("version")

try:
Expand All @@ -178,7 +188,9 @@ def check_for_updates(current_version) -> Union[str, None]:
return None

try:
if compare_versions(current_version, version) == -1:
if not is_dev(version) and parse_version(version) > parse_version(current_version):
return version
if is_dev(current_version) and is_dev(version) and parse_version(version) > parse_version(current_version):
return version
else:
return None
Expand Down Expand Up @@ -217,26 +229,6 @@ def check_version():
pass


def compare_versions(version_a, version_b):
"""
Function to compare two versions.
Returns 1 if version_a > version_b, 0 if version_a == version_b, -1 if version_a < version_b.
"""

def convert(version):
return tuple(map(int, version.split(".")))

version_a = convert(version_a)
version_b = convert(version_b)

if version_a > version_b:
return 1
elif version_a == version_b:
return 0
else:
return -1


def lines_diff(lines1, lines2):
"""
Function to compare two lists of lines.
Expand Down

0 comments on commit 9bc7c8f

Please sign in to comment.