Skip to content

Commit

Permalink
Replace distutils.version with packaging.version
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Jan 29, 2024
1 parent 44820cc commit 5b37b23
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
6 changes: 3 additions & 3 deletions reprounzip-vagrant/reprounzip_vagrant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"""

import argparse
from distutils.version import LooseVersion
import logging
import os
import packaging.version
import paramiko
from pathlib import Path, PurePosixPath
import re
Expand Down Expand Up @@ -802,7 +802,7 @@ def check_vagrant_version():
sys.exit(1)
out = out.decode('ascii').strip().lower().split()
if out[0] == 'vagrant':
if LooseVersion(out[1]) < LooseVersion('1.1'):
if packaging.version.parse(out[1]) < packaging.version.parse('1.1'):
logger.error("Vagrant >=1.1 is required; detected version: %s",
out[1])
sys.exit(1)
Expand All @@ -824,7 +824,7 @@ def test_has_vagrant(pack, **kwargs):
"work properly")
out = out.decode('ascii').strip().lower().split()
if out[0] == 'vagrant':
if LooseVersion(out[1]) >= LooseVersion('1.1'):
if packaging.version.parse(out[1]) >= packaging.version.parse('1.1'):
return COMPAT_OK
else:
return COMPAT_NO, ("Vagrant >=1.1 is required; detected version: "
Expand Down
1 change: 1 addition & 0 deletions reprounzip-vagrant/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
install_requires=[
'reprounzip>=2.0.0,<3.0.0',
'packaging',
'paramiko',
],
description="Allows the ReproZip unpacker to create virtual machines",
Expand Down
10 changes: 7 additions & 3 deletions reprounzip/reprounzip/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
images for various operating systems.
"""

from distutils.version import LooseVersion
import json
import logging
import os
import packaging.version.parse

from reprozip_core.common import get_reprozip_ca_certificate
from reprozip_core.utils import download_file
Expand Down Expand Up @@ -68,8 +68,12 @@ def update_parameters():
except OSError:
pass
else:
ver = LooseVersion(parameters.get('version', '1.0'))
if LooseVersion('1.1') <= ver < LooseVersion('3.0'):
ver = packaging.version.parse(parameters.get('version', '1.0'))
if (
packaging.version.parse('1.1')
<= ver
< packaging.version.parse('3.0')
):
return
else:
logger.info("parameters.json has incompatible version %s, "
Expand Down
8 changes: 5 additions & 3 deletions reprounzip/reprounzip/unpackers/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"""

import argparse
from distutils.version import LooseVersion
import heapq
import json
import logging
import packaging.version.parse
from pathlib import Path, PurePosixPath
import re
import sqlite3
Expand Down Expand Up @@ -479,8 +479,10 @@ def generate(target, configfile, database, all_forks=False, graph_format='dot',
inputs_outputs = config.inputs_outputs
inputs_outputs_map = dict((f.path, n)
for n, f in config.inputs_outputs.items())
has_thread_flag = config.format_version >= LooseVersion('0.7')
has_exit_timestamp = config.format_version >= LooseVersion('1.1')
has_thread_flag = config.format_version >= packaging.version.parse('0.7')
has_exit_timestamp = (
config.format_version >= packaging.version.parse('1.1')
)

runs, files, edges = read_events(database, all_forks,
has_thread_flag,
Expand Down
4 changes: 2 additions & 2 deletions reprounzip/reprounzip/unpackers/provviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import argparse
import logging
from distutils.version import LooseVersion
import packaging.version.parse
from pathlib import Path
import sqlite3
import sys
Expand Down Expand Up @@ -44,7 +44,7 @@ def generate(target, configfile, database):

config = load_config(configfile, canonical=False)

has_thread_flag = config.format_version >= LooseVersion('0.7')
has_thread_flag = config.format_version >= packaging.version.parse('0.7')

assert database.is_file()
conn = sqlite3.connect(str(database)) # connect() only accepts str
Expand Down
1 change: 1 addition & 0 deletions reprounzip/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
with io.open('README.rst', encoding='utf-8') as fp:
description = fp.read()
req = [
'packaging',
'PyYAML',
'usagestats>=1.0.1',
'requests',
Expand Down
10 changes: 7 additions & 3 deletions reprozip-core/reprozip_core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
import contextlib
import copy
from datetime import datetime
from distutils.version import LooseVersion
import functools
import gzip
import json
import logging
import logging.handlers
import os
import packaging.version
from pathlib import Path, PurePosixPath
import pkg_resources
import shutil
Expand Down Expand Up @@ -612,13 +612,17 @@ def load_config(filename, canonical):
# Turn bytes values into Python 3 str values
_bytes_to_surrogates(config)

ver = LooseVersion(config['version'])
ver = packaging.version.parse(config['version'])

keys_ = set(config)
if 'version' not in keys_:
raise InvalidConfig("Missing version")
# Accepts versions from 0.2 to 1.1 inclusive
elif not LooseVersion('0.2') <= ver < LooseVersion('1.2'):
elif not (
packaging.version.parse('0.2')
<= ver
< packaging.version.parse('1.2')
):
pkgname = (__package__ or __name__).split('.', 1)[0]
raise InvalidConfig("Loading configuration file in unknown format %s; "
"this probably means that you should upgrade "
Expand Down
1 change: 1 addition & 0 deletions reprozip-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
with io.open('README.rst', encoding='utf-8') as fp:
description = fp.read()
req = [
'packaging',
'PyYAML',
'usagestats>=1.0.1',
'requests',
Expand Down

0 comments on commit 5b37b23

Please sign in to comment.