def __get_version(self, pkg_name): if self.loc_version.is_up_to_date: update_statement = "You are up to date!" else: if pkg_ver.parse(str(self.VERSION)) < pkg_ver.parse( str(get_version_pypi(pkg_name))): update_statement = f"You are running an older version of {pkg_name} than what is available. Consider upgrading." else: if self.VERSION in get_versions_pypi(pkg_name): avail_ver = ( ", a developmental version available via the PyPi repository" ) else: avail_ver = ( ", a version that is NOT available via any online package manager" ) update_statement = f"You are running a version of {pkg_name} that is newer than the latest version{avail_ver}" update_statement += f"\nThe versions available from PyPi are: {', '.join(get_versions_pypi(pkg_name))}" ver = str(f"{pretty_name} ({self.VERSION}) using Python {PY_VER}\n" + f"{update_statement}") print(ver) return ver
def check_and_compare_version(external_version: Optional[str] = str() ) -> Tuple[bool, str]: """Checks what the currently installed version of sheetwork is and compares it to the one on PyPI. This requires an internet connection. In the case where this doesn't happen a URLError will probably be thrown and in that case we just return False not to cause annoying user experience. Args: external_version (Optional[str], optional): Mainly for testing purposes. Defaults to str(). Returns: bool: True when sheetwork needs an update. False when good. """ try: pypi_version: str = luddite.get_version_pypi("sheetwork") if external_version: installed_version = external_version else: installed_version = __version__ needs_update = semver_parse(pypi_version) > semver_parse( installed_version) if needs_update: logger.warning( yellow( f"Looks like you're a bit behind. A newer version of Sheetwork v{pypi_version} is available." )) return needs_update, pypi_version except URLError: return False, str()
def test_get_version_pypi(mocker): mock_response = mocker.MagicMock() mock_response.code = 200 mock_response.read.return_value = b'{"info": {"version": "0.3"}}' mocker.patch("luddite.urlopen", return_value=mock_response) mocker.patch("luddite.get_charset", return_value="utf-8") v = luddite.get_version_pypi("dist", "http://myindex/+simple/") assert v == "0.3"
def check_update_available(): try: latest_version = luddite.get_version_pypi("faraday-cli") update_available = version.parse(latest_version) > version.parse( __version__) return update_available, latest_version except: # noqa: E722 return False, __version__
def show_version(skip_version_check: bool): local_version = pkg_resources.get_distribution("gitlabform").version tower_crane = Symbol("🏗", "") tokens_to_show = [ reset, tower_crane, " GitLabForm version:", blue, local_version, reset, ] message(*tokens_to_show, end="") if skip_version_check: # just print end of the line print() else: try: latest_version = luddite.get_version_pypi("gitlabform") except URLError as e: # end the line with current version print() error(f"Checking latest version failed:\n{e}") return if local_version == latest_version: happy = Symbol("😊", "") tokens_to_show = [ "= the latest stable ", happy, ] elif packaging_version.parse(local_version) < packaging_version.parse( latest_version): sad = Symbol("😔", "") tokens_to_show = [ "= outdated ", sad, f", please update! (the latest stable is ", blue, latest_version, reset, ")", ] else: excited = Symbol("🤩", "") tokens_to_show = [ "= pre-release ", excited, f" (the latest stable is ", blue, latest_version, reset, ")", ] message(*tokens_to_show, sep="")
def get_version(self, skip_version_check): local_version = pkg_resources.get_distribution("gitlabform").version version = f"GitLabForm version: {local_version}" if not skip_version_check: latest_version = luddite.get_version_pypi("gitlabform") if local_version == latest_version: version += " (the latest)" else: version += f" (the latest is {latest_version} - please update!)" return version
def _sanity_check(): # Check for any new versions of the package try: assert __version__ == luddite.get_version_pypi("DiffPriv") except AssertionError: # pragma: no cover # We ignore code coverage for this because there is no way to test this through pytest, but it has been tested manually warnings.warn( '\u001b[33m \n' 'You have DiffPriv '+__version__+', however, newer versions are avaliable. Use \n' ' pip install --upgrade DiffPriv \n' 'to upgrade your package. \u001b[0m' )
def show_version(self, skip_version_check): local_version = pkg_resources.get_distribution("gitlabform").version tower_crane = cli_ui.Symbol("🏗", "") tokens_to_show = [ cli_ui.reset, tower_crane, " GitLabForm version:", cli_ui.blue, local_version, cli_ui.reset, ] cli_ui.message(*tokens_to_show, end="") if skip_version_check: # just print end of the line print() else: latest_version = luddite.get_version_pypi("gitlabform") if local_version == latest_version: happy = cli_ui.Symbol("😊", "") tokens_to_show = [ "= the latest stable ", happy, ] elif packaging_version.parse( local_version) < packaging_version.parse(latest_version): sad = cli_ui.Symbol("😔", "") tokens_to_show = [ "= outdated ", sad, f", please update! (the latest stable is ", cli_ui.blue, latest_version, cli_ui.reset, ")", ] else: excited = cli_ui.Symbol("🤩", "") tokens_to_show = [ "= pre-release ", excited, f" (the latest stable is ", cli_ui.blue, latest_version, cli_ui.reset, ")", ] cli_ui.message(*tokens_to_show, sep="")
def _upgrade(): latest_version = luddite.get_version_pypi("workoutizer") from workoutizer import __version__ as current_version if latest_version == current_version: click.echo(f"No update available. You are running the latest version: {latest_version}") else: click.echo(f"found newer version: {latest_version}, you have {current_version} installed") _pip_install("workoutizer", upgrade=True) execute_from_command_line(["manage.py", "collectstatic", "--noinput"]) execute_from_command_line(["manage.py", "migrate"]) execute_from_command_line(["manage.py", "check"]) click.echo(f"Successfully upgraded from {current_version} to {latest_version}")
def get_latest(self): try: return get_version_pypi(self.package_name) except URLError: statement = "Unable to connect to the internet, therefore I can't get remote version data" print(statement) ver = "Unknown" is_latest = False self.offline = True return None except DistributionNotFound as e: print(e) ver = "Unknown" is_latest = False return (ver, is_latest)
__version__ = "0.1.13" __author__ = "Adam Tyson, Charly Rousseau, Christian Niedworok" __license__ = "GPL-3.0" __name__ = "amap" from . import * import luddite from packaging import version most_recent_version = luddite.get_version_pypi(__name__) if version.parse(__version__) < version.parse(most_recent_version): print(f"This version of {__name__} ({__version__}) is not the most recent " f"version. Please update to v{most_recent_version} by running: " f"'pip install {__name__} --upgrade'")
import PySimpleGUI as sg import pkgutil, json, ast, webbrowser, pkg_resources, os, sys, luddite from boldigger import login, boldblast_coi, boldblast_its, boldblast_rbcl, additional_data from boldigger import first_hit, jamp_hit, digger_sort from contextlib import contextmanager ## get image data for the GUI logo = pkgutil.get_data(__name__, 'data/logo.png') github = pkgutil.get_data(__name__, 'data/github.png') userdata = ast.literal_eval( pkgutil.get_data(__name__, 'data/userdata').decode()) certs = pkg_resources.resource_filename(__name__, 'data/certs.pem') version = pkg_resources.get_distribution('boldigger').version most_recent_version = luddite.get_version_pypi('boldigger') ## main function to handle the flow of boldigger def main(): ## defines a layout for the GUI layout = [ [sg.Image(data=logo, pad=(25, 0))], [ sg.Frame(layout=[[sg.Text('Your results will be saved here')], [ sg.Text('Output folder'), sg.InputText(size=(40, 1), do_not_clear=True, key='output_folder'), sg.FolderBrowse() ]], title='Select an output folder')
def single_run(preset_filename, robots, bind_addr, seed, batch_file=None, override_settings={}): if batch_file: ScreenObjectManager.BATCH_FILE = batch_file ScreenObjectManager.PRESET_FILE = preset_filename import ev3sim try: latest_version = get_version_pypi("ev3sim") ScreenObjectManager.NEW_VERSION = latest_version != ev3sim.__version__ if ScreenObjectManager.NEW_VERSION: update_message = f"""\ ========================================================================================== There is a new version of ev3sim available ({latest_version}). Keeping an up to date version of ev3sim ensures you have the latest bugfixes and features. Please update ev3sim by running the following command: python -m pip install -U ev3sim ========================================================================================== """ print(update_message) except: ScreenObjectManager.NEW_VERSION = False Randomiser.createGlobalRandomiserWithSeed(seed) preset_file = find_abs(preset_filename, allowed_areas=[ "local", "local/presets/", "package", "package/presets/" ]) with open(preset_file, "r") as f: config = yaml.safe_load(f) config["robots"] = config.get("robots", []) + robots shared_data = { "tick": 0, # Current tick. "write_stack": deque(), # All write actions are processed through this. "data_queue": {}, # Simulation data for each bot. "active_count": {}, # Keeps track of which code connection each bot has. "bot_locks": {}, # Threading Locks and Conditions for each bot to wait for connection actions. "bot_communications_data": {}, # Buffers and information for all bot communications. "tick_updates": {}, # Simply a dictionary where the simulation tick will push static data, so the other methods are aware of when the simulation has exited. "events": {}, # Any events that should be sent to robots. } result_bucket = Queue(maxsize=1) from threading import Thread from ev3sim.simulation.communication import start_server_with_shared_data def run(shared_data, result): try: runFromConfig(config, shared_data) except Exception as e: result.put(("Simulation", e)) return result.put(True) # Handle any other settings modified by the preset. settings = config.get("settings", {}) settings.update(override_settings) for keyword, value in settings.items(): run = mock.patch(keyword, value)(run) comm_thread = Thread(target=start_server_with_shared_data, args=(shared_data, result_bucket, bind_addr), daemon=True) sim_thread = Thread(target=run, args=(shared_data, result_bucket), daemon=True) comm_thread.start() sim_thread.start() try: with result_bucket.not_empty: while not result_bucket._qsize(): result_bucket.not_empty.wait(0.1) r = result_bucket.get() # Chuck it back on the queue so that other threads know we are quitting. result_bucket.put(r) if r is not True: print( f"An error occurred in the {r[0]} thread. Raising an error now..." ) time.sleep(1) raise r[1] except KeyboardInterrupt: pass