Skip to content

Commit

Permalink
Merge branch 'master' into FIX_pytest_warns_None
Browse files Browse the repository at this point in the history
  • Loading branch information
ogrisel committed Feb 23, 2022
2 parents 3366d3c + 3d80506 commit 9121399
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 20 deletions.
24 changes: 12 additions & 12 deletions azure-pipelines.yml
Expand Up @@ -43,20 +43,20 @@ jobs:
PYTHON_VERSION: "3.9"
# SKIP_TESTS: "true"
SKLEARN_TESTS: "true"
linux_py38_distributed:
linux_py310_distributed:
# To be updated regularly to use the most recent versions of the
# dependencies.
imageName: 'ubuntu-latest'
PYTHON_VERSION: "3.8"
EXTRA_CONDA_PACKAGES: "numpy=1.18 distributed=2.17"
PYTHON_VERSION: "3.10"
EXTRA_CONDA_PACKAGES: "numpy=1.22 distributed=2022.2.0"
linux_py37_distributed:
imageName: 'ubuntu-latest'
PYTHON_VERSION: "3.7"
EXTRA_CONDA_PACKAGES: "numpy=1.15 distributed=2.13"
linux_py37_cython:
linux_py310_cython:
imageName: 'ubuntu-latest'
PYTHON_VERSION: "3.7"
EXTRA_CONDA_PACKAGES: "numpy=1.15"
PYTHON_VERSION: "3.10"
EXTRA_CONDA_PACKAGES: "numpy=1.22"
CYTHON: "true"
linux_py37_no_multiprocessing_no_lzma:
imageName: 'ubuntu-latest'
Expand All @@ -68,15 +68,15 @@ jobs:
imageName: 'ubuntu-latest'
PYTHON_VERSION: "3.7"

windows_py38:
windows_py310:
imageName: "windows-latest"
PYTHON_VERSION: "3.8"
EXTRA_CONDA_PACKAGES: "numpy=1.18"
PYTHON_VERSION: "3.10"
EXTRA_CONDA_PACKAGES: "numpy=1.22"

macos_py38:
macos_py310:
imageName: "macos-latest"
PYTHON_VERSION: "3.8"
EXTRA_CONDA_PACKAGES: "numpy=1.18"
PYTHON_VERSION: "3.10"
EXTRA_CONDA_PACKAGES: "numpy=1.22"
macos_py37_no_numpy:
imageName: "macos-latest"
PYTHON_VERSION: "3.7"
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
@@ -1,10 +1,10 @@
from distutils.version import LooseVersion

import pytest
from _pytest.doctest import DoctestItem

import logging
from joblib.parallel import mp
from joblib.backports import LooseVersion
try:
import lz4
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion continuous_integration/install.sh
Expand Up @@ -13,7 +13,7 @@ set -e
create_new_conda_env() {
conda update --yes conda
TO_INSTALL="python=$PYTHON_VERSION pip pytest $EXTRA_CONDA_PACKAGES"
conda create -n testenv --yes $TO_INSTALL
conda create -n testenv --yes -c conda-forge $TO_INSTALL
source activate testenv
}

Expand Down
101 changes: 100 additions & 1 deletion joblib/backports.py
Expand Up @@ -2,13 +2,112 @@
Backports of fixes for joblib dependencies
"""
import os
import re
import time

from distutils.version import LooseVersion
from os.path import basename
from multiprocessing import util


class Version:
"""Backport from deprecated distutils
We maintain this backport to avoid introducing a new dependency on
`packaging`.
We might rexplore this choice in the future if all major Python projects
introduce a dependency on packaging anyway.
"""

def __init__(self, vstring=None):
if vstring:
self.parse(vstring)

def __repr__(self):
return "%s ('%s')" % (self.__class__.__name__, str(self))

def __eq__(self, other):
c = self._cmp(other)
if c is NotImplemented:
return c
return c == 0

def __lt__(self, other):
c = self._cmp(other)
if c is NotImplemented:
return c
return c < 0

def __le__(self, other):
c = self._cmp(other)
if c is NotImplemented:
return c
return c <= 0

def __gt__(self, other):
c = self._cmp(other)
if c is NotImplemented:
return c
return c > 0

def __ge__(self, other):
c = self._cmp(other)
if c is NotImplemented:
return c
return c >= 0


class LooseVersion(Version):
"""Backport from deprecated distutils
We maintain this backport to avoid introducing a new dependency on
`packaging`.
We might rexplore this choice in the future if all major Python projects
introduce a dependency on packaging anyway.
"""

component_re = re.compile(r'(\d+ | [a-z]+ | \.)', re.VERBOSE)

def __init__(self, vstring=None):
if vstring:
self.parse(vstring)

def parse(self, vstring):
# I've given up on thinking I can reconstruct the version string
# from the parsed tuple -- so I just store the string here for
# use by __str__
self.vstring = vstring
components = [x for x in self.component_re.split(vstring)
if x and x != '.']
for i, obj in enumerate(components):
try:
components[i] = int(obj)
except ValueError:
pass

self.version = components

def __str__(self):
return self.vstring

def __repr__(self):
return "LooseVersion ('%s')" % str(self)

def _cmp(self, other):
if isinstance(other, str):
other = LooseVersion(other)
elif not isinstance(other, LooseVersion):
return NotImplemented

if self.version == other.version:
return 0
if self.version < other.version:
return -1
if self.version > other.version:
return 1


try:
import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion joblib/compressor.py
Expand Up @@ -2,7 +2,7 @@

import io
import zlib
from distutils.version import LooseVersion
from joblib.backports import LooseVersion

try:
from threading import RLock
Expand Down
10 changes: 6 additions & 4 deletions joblib/test/test_numpy_pickle.py
Expand Up @@ -282,11 +282,13 @@ def test_compress_mmap_mode_warning(tmpdir):
numpy_pickle.dump(a, this_filename, compress=1)
with warns(UserWarning) as warninfo:
numpy_pickle.load(this_filename, mmap_mode='r+')
warninfo = [w.message for w in warninfo]
assert len(warninfo) == 1
assert (str(warninfo[0].message) ==
'mmap_mode "%(mmap_mode)s" is not compatible with compressed '
'file %(filename)s. "%(mmap_mode)s" flag will be ignored.' %
{'filename': this_filename, 'mmap_mode': 'r+'})
assert (
str(warninfo[0]) ==
'mmap_mode "r+" is not compatible with compressed '
f'file {this_filename}. "r+" flag will be ignored.'
)


@with_numpy
Expand Down

0 comments on commit 9121399

Please sign in to comment.