Skip to content

Commit

Permalink
Merge pull request #52 from civisanalytics/drop-python-2-support
Browse files Browse the repository at this point in the history
Drop support for Python 2 and allow Pandas 1.x
  • Loading branch information
mikesaelim authored Sep 8, 2020
2 parents 68a803d + 749193f commit 16e3fb8
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 89 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ services:
dist: xenial
language: python
python:
- "2.7"
- "3.5"
- "3.6"
- "3.7"
Expand All @@ -21,10 +20,5 @@ script:
- |
if [ ${TRAVIS_PYTHON_VERSION} = 3.7 ]
then
./tests/run_docker_tests.sh tests/python3/Dockerfile
fi
- |
if [ ${TRAVIS_PYTHON_VERSION} = 2.7 ]
then
./tests/run_docker_tests.sh tests/python2/Dockerfile
./tests/run_docker_tests.sh tests/Dockerfile
fi
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

## [2.0.0] - 2020-09-08

### Added
- Compatibility with Pandas 1.x (#52)

### Removed
- File logging. All logs will now be written to stdout/stderr streams. (#47)
- Support for Python 2.7 (#52)

## [1.0.2] - 2020-01-30

### Removed
- Remove Notebook XSRF check (#51)

Expand All @@ -21,6 +28,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Fix issue with notebook ip address in config (#50)

### Removed
- File logging. All logs will now be written to stdout/stderr streams. (#47)

## [1.0.0] - 2019-05-10

### Removed
Expand Down
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Usage

In your ``Dockerfile``, put the following code at the end::

ENV DEFAULT_KERNEL <your kernel> # set to python3 or ir

RUN pip install civis-jupyter-notebook && \
civis-jupyter-notebooks-install

Expand All @@ -19,14 +21,13 @@ In your ``Dockerfile``, put the following code at the end::
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

ENV DEFAULT_KERNEL <your kernel> # set to one of python3, python2 or ir
EXPOSE 8888
WORKDIR /root/work
ENTRYPOINT ["/tini", "--"]
CMD ["civis-jupyter-notebooks-start"]

Here you need to replace ``<your kernel>`` with the name of your kernel (e.g.,
one of ``python2``, ``python3``, or ``ir``). Note that your Dockerfile must use
``python3`` or ``ir``). Note that your Dockerfile must use
``root`` as the default user.

See the `example`_ Docker image for more details.
Expand Down
2 changes: 1 addition & 1 deletion civis_jupyter_notebooks/assets/civis_client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

if 'CIVIS_API_KEY' in os.environ:
LOGGER.info('creating civis api client')
client = civis.APIClient(resources='all')
client = civis.APIClient()
LOGGER.info('civis api client created')

# clean out the namespace for users
Expand Down
4 changes: 1 addition & 3 deletions civis_jupyter_notebooks/platform_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ def generate_and_save_preview(url, os_path):

def get_client():
""" This gets a client that knows about our notebook endpoints """

# TODO: Simplify this once the notebooks endpoints are in the client
return civis.APIClient(resources='all')
return civis.APIClient()


class NotebookManagementError(Exception):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import unittest
import six
import pkg_resources
import platform
from unittest.mock import patch, MagicMock

from civis_jupyter_notebooks.extensions.git.uncommitted_changes import UncommittedChangesHandler
from civis_jupyter_notebooks.git_utils import CivisGitError

if (six.PY2 or pkg_resources.parse_version('.'.join(platform.python_version_tuple()[0:2]))
== pkg_resources.parse_version('3.4')):
from mock import patch, MagicMock
else:
from unittest.mock import patch, MagicMock


class UncommittedChangesHandlerTest(unittest.TestCase):

Expand Down
12 changes: 1 addition & 11 deletions civis_jupyter_notebooks/tests/test_git_utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import unittest
from unittest.mock import patch, MagicMock
import os
import logging
import six
import pkg_resources
import platform

from git.exc import GitCommandError
from git import Repo
from civis_jupyter_notebooks.git_utils import CivisGit, CivisGitError

if (six.PY2 or pkg_resources.parse_version('.'.join(platform.python_version_tuple()[0:2]))
== pkg_resources.parse_version('3.4')):
from mock import patch
from mock import MagicMock
else:
from unittest.mock import patch
from unittest.mock import MagicMock

REPO_URL = 'http://www.github.com/civisanalytics.foo.git'
REPO_MOUNT_PATH = '/root/work'
GIT_REPO_REF = 'master'
Expand Down
10 changes: 1 addition & 9 deletions civis_jupyter_notebooks/tests/test_notebook_config.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import unittest
import six
from unittest.mock import patch, ANY
import os
import pkg_resources
import platform
from traitlets.config.loader import Config

from civis_jupyter_notebooks import notebook_config, platform_persistence

if (six.PY2 or pkg_resources.parse_version('.'.join(platform.python_version_tuple()[0:2]))
== pkg_resources.parse_version('3.4')):
from mock import patch, ANY
else:
from unittest.mock import patch, ANY


class NotebookConfigTest(unittest.TestCase):
@patch.dict(os.environ, {'DEFAULT_KERNEL': 'kern'})
Expand Down
14 changes: 3 additions & 11 deletions civis_jupyter_notebooks/tests/test_platform_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@
import nbformat
import requests
import unittest
from unittest.mock import ANY, MagicMock, patch
import logging
import six
import pkg_resources
import platform

from civis_jupyter_notebooks import platform_persistence
from civis_jupyter_notebooks.platform_persistence import NotebookManagementError

if (six.PY2 or pkg_resources.parse_version('.'.join(platform.python_version_tuple()[0:2]))
== pkg_resources.parse_version('3.4')):
from mock import ANY, MagicMock, patch
else:
from unittest.mock import ANY, MagicMock, patch

TEST_NOTEBOOK_PATH = '/path/to/notebook.ipynb'
TEST_PLATFORM_OBJECT_ID = '1914'
SAMPLE_NOTEBOOK = open(os.path.join(os.path.dirname(__file__), 'fixtures/sample_notebook.ipynb')).read()
Expand Down Expand Up @@ -193,7 +185,7 @@ def test_generate_preview_throws_error_on_convert(self, _rput, _client, check_ca
@patch('civis.APIClient')
def test_will_regenerate_api_client(self, mock_client):
platform_persistence.get_client()
mock_client.assert_called_with(resources='all')
mock_client.assert_called_with()

@patch('os.path.isfile')
@patch('os.path.isdir')
Expand Down Expand Up @@ -235,7 +227,7 @@ def test_pip_install_calls_subprocess(self, executable, check_output):
@patch('sys.executable')
def test_pip_install_failure_raises_notebookmanagementerror(self, executable, check_output):
check_output.side_effect = subprocess.CalledProcessError(returncode=1, cmd='cmd', output=b'installation error')
with self.assertRaisesRegexp(NotebookManagementError, 'installation error'):
with self.assertRaisesRegex(NotebookManagementError, 'installation error'):
platform_persistence.pip_install('/path/requirements.txt')


Expand Down
2 changes: 1 addition & 1 deletion civis_jupyter_notebooks/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.2'
__version__ = '2.0.0'
1 change: 0 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pytest~=3.2
flake8~=3.0
mock~=2.0 ; python_version >= '2.7' and python_version < '3.0'
5 changes: 3 additions & 2 deletions example/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM python:3.6
FROM python:3.7

ENV DEFAULT_KERNEL python3

RUN pip install civis-jupyter-notebook && \
civis-jupyter-notebooks-install
Expand All @@ -8,7 +10,6 @@ ENV TINI_VERSION v0.16.1
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

ENV DEFAULT_KERNEL python3
EXPOSE 8888
WORKDIR /root/work
ENTRYPOINT ["/tini", "--"]
Expand Down
10 changes: 3 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
civis~=1.6
civis~=1.9
requests~=2.18
click~=6.7
jupyter-core~=4.6.0
notebook==6.0.0 ; python_version >= '3.5'
notebook==5.7.8 ; python_version < '3.0'
# Python 2 notebooks require notebook v5.7.8
# because v6.0.0 drops support for Python 2
notebook==6.0.0
tornado<6
six~=1.10
civis-jupyter-extensions~=0.1
civis-jupyter-extensions~=1.0
GitPython~=2.1
2 changes: 1 addition & 1 deletion tests/python3/Dockerfile → tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.6
FROM python:3.7

COPY ./requirements.txt /root/requirements.txt
RUN pip install -r /root/requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion tests/build_dev_image.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

cp tests/python3/Dockerfile .
cp tests/Dockerfile .
docker build -t py3 .
rm Dockerfile
22 changes: 0 additions & 22 deletions tests/python2/Dockerfile

This file was deleted.

0 comments on commit 16e3fb8

Please sign in to comment.