Skip to content

Commit

Permalink
Updating version parser because the prior one (distutils.version) is …
Browse files Browse the repository at this point in the history
…obsolete, violates current python version guides (PEP 440), and undocumented. The new parser is part of setuptools, which is required to install switch (it's an import in setup.py).

Changing version number from alpha to dev which seems a better name for this staging branch.
  • Loading branch information
josiahjohnston committed Aug 16, 2019
1 parent 766e377 commit b5b1a28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 6 additions & 6 deletions switch_model/upgrade/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import argparse
import os
import shutil
from distutils.version import StrictVersion
from pkg_resources import parse_version

import switch_model

Expand Down Expand Up @@ -35,7 +35,7 @@
# Not every code revision requires an update; this is the last revision that did.
last_required_update = upgrade_plugins[-1][-1]

code_version = StrictVersion(switch_model.__version__)
code_version = parse_version(switch_model.__version__)
version_file = 'switch_inputs_version.txt'
#verbose = False
verbose = True
Expand Down Expand Up @@ -93,7 +93,7 @@ def do_inputs_need_upgrade(inputs_dir):
# Not every code revision requires an update, so just hard-code the last
# revision that required an update.
inputs_version = get_input_version(inputs_dir)
return StrictVersion(inputs_version) < StrictVersion(last_required_update)
return parse_version(inputs_version) < parse_version(last_required_update)


def _backup(inputs_dir):
Expand Down Expand Up @@ -122,15 +122,15 @@ def upgrade_inputs(inputs_dir, backup=True, assign_current_version=False):
_backup(inputs_dir)
# Successively apply the upgrade scripts as needed.
for (upgrader, v_from, v_to) in upgrade_plugins:
inputs_v = StrictVersion(get_input_version(inputs_dir))
inputs_v = parse_version(get_input_version(inputs_dir))
# note: the next line catches datasets created by/for versions of Switch that
# didn't require input directory upgrades
if StrictVersion(v_from) <= inputs_v < StrictVersion(v_to):
if parse_version(v_from) <= inputs_v < parse_version(v_to):
print_verbose('\tUpgrading from ' + v_from + ' to ' + v_to)
upgrader.upgrade_input_dir(inputs_dir)
upgraded = True

if (StrictVersion(last_required_update) < StrictVersion(switch_model.__version__)
if (parse_version(last_required_update) < parse_version(switch_model.__version__)
and assign_current_version):
# user requested writing of current version number, even if no upgrade is needed
# (useful for updating examples to track with new release of Switch)
Expand Down
9 changes: 4 additions & 5 deletions switch_model/version.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Copyright (c) 2015-2019 The Switch Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0, which is in the LICENSE file.
"""
This file should only include the version. Do not import any packages or
modules here because this file needs to be executed before Switch is
installed and executed in environments that don't have any dependencies
installed.
This file should not contain anything that is not part of a minimal python
distribution because it needs to be executed before Switch (and its
dependencies) are installed.
"""
__version__='2.0.6-alpha'
__version__='2.0.6-dev'

0 comments on commit b5b1a28

Please sign in to comment.