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

Update requirements.txt and setup.py according to GHSA-977j-xj7q-2jr9 #101

Merged
merged 2 commits into from
Apr 6, 2020
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
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ notifications:
email: false
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Fixed an issue with builds failing due to numerical issues (#103)

### Changed
- Increase minimum version of `tensorflow` to v1.15.2 to fix the security vulnerability reported in https://github.com/tensorflow/tensorflow/security/advisories/GHSA-977j-xj7q-2jr9 (#101).
- Dropped support for Python 2.7 and 3.4 (#101).

## [2.3.0] - 2019-11-22

### Changed
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ models implemented in `TensorFlow <https://www.tensorflow.org/>`__
Installation
============

This package currently supports Python 3.5, 3.6, and 3.7.

Installation with ``pip`` is recommended:

.. code:: bash
Expand Down
2 changes: 0 additions & 2 deletions muffnn/autoencoder/autoencoder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Autoencoder in scikit-learn style with TensorFlow
"""
from __future__ import print_function
from __future__ import division

import logging
import re
Expand Down
15 changes: 2 additions & 13 deletions muffnn/autoencoder/tests/test_autoencoder.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
"""
Tests for the Autoencoder.
"""
from __future__ import print_function
from __future__ import division

import logging
import pprint
from io import BytesIO
import pickle
import sys
try:
from unittest import mock
except ImportError:
mock = None
from unittest import mock

import pytest
import numpy as np
import scipy.sparse as sp
import six
import tensorflow as tf
from sklearn.preprocessing import MinMaxScaler, OneHotEncoder
from sklearn.datasets import load_iris
Expand All @@ -27,11 +21,6 @@

from muffnn import Autoencoder

if six.PY2:
from mock import patch
else:
from unittest.mock import patch


_LOGGER = logging.getLogger(__name__)
iris = load_iris()
Expand Down Expand Up @@ -112,7 +101,7 @@ def __init__(self, hidden_units=(256,), batch_size=128, n_epochs=300,
# replicate outside of travis, but I was able to get the test to fail locally
# by changing atol in sklearn.utils.check_methods_subset_invariance from 1e-7
# to 1e-10. This simply skips that part of check_estimator.
@patch('sklearn.utils.estimator_checks.check_methods_subset_invariance')
@mock.patch('sklearn.utils.estimator_checks.check_methods_subset_invariance')
def test_check_estimator(mock_check_methods_subset_invariance):
"""Check adherence to Estimator API."""
if sys.version_info.major == 3 and sys.version_info.minor == 7:
Expand Down
81 changes: 5 additions & 76 deletions muffnn/core.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,10 @@
from __future__ import print_function
from __future__ import division

import os
from abc import ABCMeta, abstractmethod
import glob
import os
import tarfile
from abc import ABCMeta, abstractmethod
import six
import tensorflow as tf

from tempfile import TemporaryDirectory

if six.PY3:
from tempfile import TemporaryDirectory
else:
# Backport TemporaryDirectory; this was introduced in Python 3.2
from tempfile import mkdtemp
import shutil as _shutil
import sys as _sys
import warnings as _warnings

class ResourceWarning(Warning):
pass

# from civis-python (civis.compat)
# copied here to avoid the dependency
class TemporaryDirectory(object):
"""Create and return a temporary directory. This has the same
behavior as mkdtemp but can be used as a context manager. For
example:

with TemporaryDirectory() as tmpdir:
...

Upon exiting the context, the directory and everything contained
in it are removed.

This is a port of the Python 3.2+ TemporaryDirectory object,
modified slightly to work with Python 2.7. Python 3 docs are at
https://docs.python.org/3/library/tempfile.html#tempfile.TemporaryDirectory
"""

def __init__(self, suffix='', prefix='tmp', dir=None):
self._closed = False
self.name = None # Handle mkdtemp raising an exception
self.name = mkdtemp(suffix, prefix, dir)

def __repr__(self):
return "<{} {!r}>".format(self.__class__.__name__, self.name)

def __enter__(self):
return self.name

def __exit__(self, exc, value, tb):
self.cleanup()

def __del__(self):
# Issue a ResourceWarning if implicit cleanup needed
self.cleanup(_warn=True)

def cleanup(self, _warn=False):
if self.name and not self._closed:
try:
_shutil.rmtree(self.name)
except (TypeError, AttributeError) as ex:
# Issue #10188: Emit a warning on stderr
# if the directory could not be cleaned
# up due to missing globals
if "None" not in str(ex):
raise
print("ERROR: {!r} while cleaning up "
"{!r}".format(ex, self,),
file=_sys.stderr)
return
self._closed = True
if _warn:
_warnings.warn("Implicitly cleaning up {!r}".format(self),
ResourceWarning)
import tensorflow as tf


def affine(input_tensor, output_size, bias=True, bias_start=0.0,
Expand Down Expand Up @@ -131,8 +61,7 @@ def affine(input_tensor, output_size, bias=True, bias_start=0.0,
return t


@six.add_metaclass(ABCMeta)
class TFPicklingBase(object):
class TFPicklingBase(object, metaclass=ABCMeta):
"""Base class for pickling TensorFlow-based scikit-learn estimators.

This base class defines a few standard attributes to enable fairly
Expand Down
3 changes: 0 additions & 3 deletions muffnn/fm/fm_classifier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import print_function
from __future__ import division

import logging
import re

Expand Down
3 changes: 0 additions & 3 deletions muffnn/fm/fm_regressor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import print_function
from __future__ import division

import logging
from warnings import warn
import re
Expand Down
8 changes: 1 addition & 7 deletions muffnn/fm/tests/test_fm_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
based in part on sklearn's logistic tests:
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/tests/test_logistic.py
"""
from __future__ import print_function
from __future__ import division

from io import BytesIO
import pickle
import sys
try:
from unittest import mock
except ImportError:
mock = None
from unittest import mock

import numpy as np
import pytest
Expand Down
7 changes: 1 addition & 6 deletions muffnn/fm/tests/test_fm_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
based in part on sklearn's logistic tests:
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/tests/test_logistic.py
"""
from __future__ import print_function
from __future__ import division

from io import BytesIO
import pickle
import sys
try:
from unittest import mock
except ImportError:
mock = None
from unittest import mock

import numpy as np
import pytest
Expand Down
6 changes: 1 addition & 5 deletions muffnn/mlp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

Similar to sklearn.neural_network.MLPClassifier, but using TensorFlow.
"""
from __future__ import print_function
from __future__ import division

from abc import ABCMeta, abstractmethod
import six
import logging
import re
from warnings import warn
Expand All @@ -32,8 +29,7 @@
_LOGGER = logging.getLogger(__name__)


@six.add_metaclass(ABCMeta)
class MLPBaseEstimator(TFPicklingBase, BaseEstimator):
class MLPBaseEstimator(TFPicklingBase, BaseEstimator, metaclass=ABCMeta):
"""Base class for multilayer perceptron models

Notes
Expand Down
2 changes: 0 additions & 2 deletions muffnn/mlp/mlp_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

Similar to sklearn.neural_network.MLPClassifier, but using TensorFlow.
"""
from __future__ import print_function
from __future__ import division

import logging

Expand Down
2 changes: 0 additions & 2 deletions muffnn/mlp/mlp_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

Similar to sklearn.neural_network.MLPRegressor, but using TensorFlow.
"""
from __future__ import print_function
from __future__ import division

import logging
from warnings import warn
Expand Down
9 changes: 1 addition & 8 deletions muffnn/mlp/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
from __future__ import print_function
from __future__ import division

from io import BytesIO
import pickle

import pytest
import six
import numpy as np
import scipy.sparse
import tensorflow as tf
from tensorflow.python.ops import nn

import muffnn.mlp.base as base

if six.PY2:
import mock
else:
from unittest import mock
from unittest import mock


class SimpleTestEstimator(base.MLPBaseEstimator):
Expand Down
16 changes: 3 additions & 13 deletions muffnn/mlp/tests/test_mlp_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
based in part on sklearn's logistic tests:
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/linear_model/tests/test_logistic.py
"""
from __future__ import print_function
from __future__ import division

from io import BytesIO
import pickle
import sys
try:
from unittest import mock
except ImportError:
mock = None
from unittest import mock
from unittest.mock import MagicMock

import six
import numpy as np
import pytest
import scipy.sparse as sp
Expand All @@ -34,11 +29,6 @@
from muffnn import MLPClassifier
from muffnn.mlp.tests.util import assert_sample_weights_work

if six.PY2:
from mock import MagicMock, patch
else:
from unittest.mock import MagicMock, patch


iris = load_iris()
X = [[-1, 0], [0, 1], [1, 1]]
Expand Down Expand Up @@ -84,7 +74,7 @@ def predict_proba(self, *args, **kwargs):
# replicate outside of travis, but I was able to get the test to fail locally
# by changing atol in sklearn.utils.check_methods_subset_invariance from 1e-7
# to 1e-10. This simply skips that part of check_estimator.
@patch('sklearn.utils.estimator_checks.check_methods_subset_invariance')
@mock.patch('sklearn.utils.estimator_checks.check_methods_subset_invariance')
def test_check_estimator(mock_check_methods_subset_invariance):
"""Check adherence to Estimator API."""
if sys.version_info.major == 3 and sys.version_info.minor == 7:
Expand Down
7 changes: 1 addition & 6 deletions muffnn/mlp/tests/test_mlp_regressor.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
"""
Tests for MLP Regressor
"""
from __future__ import print_function
from __future__ import division

import sys
try:
from unittest import mock
except ImportError:
mock = None
from unittest import mock

import numpy as np
import pytest
Expand Down
2 changes: 0 additions & 2 deletions muffnn/tests/test_tfbase.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Tests for TFPicklingBase
"""
from __future__ import print_function
from __future__ import division

import io
import pickle
Expand Down
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
numpy~=1.14
scipy~=1.0
scikit-learn>=0.19
six~=1.10
tensorflow>=1.12.1,<2
mock==2.0.0 ; python_version < '3.0'
tensorflow>=1.15.2,<2
12 changes: 11 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@

_VERSION = '2.3.0'

CLASSIFIERS = [
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3 :: Only',
]

setup(
name='muffnn',
version=_VERSION,
Expand All @@ -20,5 +29,6 @@
install_requires=['numpy',
'scipy',
'scikit-learn>=0.19',
'tensorflow>=1.12.1,<2']
'tensorflow>=1.15.2,<2'],
classifiers=CLASSIFIERS
)