Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] install: Check installed version against latest published version on PyPI #173

Merged
merged 7 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import unittest
import platform
import os
import pkg_resources

# import custom python packages
from wahoomc.setup_functions import is_program_installed, is_map_writer_plugin_installed, read_version_last_run
from wahoomc.setup_functions import is_program_installed, is_map_writer_plugin_installed, \
read_version_last_run
from wahoomc.constants_functions import get_tooling_win_path
from wahoomc.constants import USER_WAHOO_MC
from wahoomc.constants import USER_WAHOO_MC, VERSION
from wahoomc.file_directory_functions import write_json_file_generic
from wahoomc.downloader import get_latest_pypi_version


class TestSetup(unittest.TestCase):
Expand Down Expand Up @@ -90,6 +93,16 @@ def test_version_if_written_neq(self):

self.assertNotEqual('2.0.2', read_version_last_run())

def test_version_constants_against_pypi(self):
"""
tests, if the version of constants.py is equal to the latest available version on PyPI
"""
latest_version = pkg_resources.parse_version(
get_latest_pypi_version()).public

self.assertEqual(
VERSION, latest_version)


if __name__ == '__main__':
unittest.main()
13 changes: 13 additions & 0 deletions wahoomc/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import time
import logging
import platform
import requests

# import custom python packages
from wahoomc.file_directory_functions import download_url_to_file, unzip
Expand Down Expand Up @@ -118,6 +119,18 @@ def download_tooling_win():
'http://m.m.i24.cc/osmfilter.exe')


def get_latest_pypi_version():
"""
get latest wahoomc version available on PyPI
"""
try:
response = requests.get(
'https://pypi.org/pypi/wahoomc/json', timeout=1)
return response.json()['info']['version']
except (requests.ConnectionError, requests.Timeout):
return None


class Downloader:
"""
This is the class to check and download maps / artifacts"
Expand Down
4 changes: 3 additions & 1 deletion wahoomc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from wahoomc.input import process_call_of_the_tool, cli_init
from wahoomc.setup_functions import initialize_work_directories, \
check_installation_of_required_programs, write_config_file, \
adjustments_due_to_breaking_changes, copy_jsons_from_repo_to_user
adjustments_due_to_breaking_changes, copy_jsons_from_repo_to_user, \
check_installed_version_against_latest_pypi
from wahoomc.downloader import download_tooling_win

from wahoomc.osm_maps_functions import OsmMaps
Expand All @@ -32,6 +33,7 @@ def run(run_level):

# initializing work directories needs to be the first call,
# because other setup stuff relies on that (breaking changes)
check_installed_version_against_latest_pypi()
initialize_work_directories()
adjustments_due_to_breaking_changes()
download_tooling_win()
Expand Down
23 changes: 21 additions & 2 deletions wahoomc/setup_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from wahoomc.file_directory_functions import move_content, write_json_file_generic, \
read_json_file_generic, delete_o5m_pbf_files_in_folder, copy_or_move_files_and_folder
from wahoomc.constants_functions import get_tooling_win_path, get_absolute_dir_user_or_repo
from wahoomc.downloader import get_latest_pypi_version

from wahoomc.constants import USER_WAHOO_MC
from wahoomc.constants import USER_DL_DIR
Expand Down Expand Up @@ -191,9 +192,27 @@ def copy_jsons_from_repo_to_user(folder, file=''):
log.debug('# Copy "%s" files from repo to directory if not existing: %s',
folder, absolute_paths[0])

# copy files of gitcommon package directory to user directory
# copy files of wahoomc package directory to user directory
copy_or_move_files_and_folder(
absolute_paths[1], absolute_paths[0], delete_from_dir=False)

log.info('# Copy "%s" files from repo or gitcommon to directory if not existing: %s : OK',
log.info('# Copy "%s" files from wahoomc installation to directory if not existing: %s : OK',
folder, absolute_paths[0])


def check_installed_version_against_latest_pypi():
"""
get latest wahoomc version available on PyPI and compare with locally installed version
"""
# get latest wahoomc version available on PyPI
latest_version = get_latest_pypi_version()

# compare installed version against latest and issue a info if a new version is available
if latest_version \
and pkg_resources.parse_version(VERSION) < pkg_resources.parse_version(latest_version):
log.info('\n\nUpdate available! \
\nA new version of wahoomc is available: "%s". You have installed version "%s". \
\nUpgrade wahoomc with "pip install wahoomc --upgrade". \
\nRelease notes are here: https://github.com/treee111/wahooMapsCreator/releases/latest. \
\n',
latest_version, VERSION)