Skip to content

Commit

Permalink
fix: migration timezones (#683)
Browse files Browse the repository at this point in the history
* Removes pytz dependency and fixes Project date converter code

* Changes travis build to runi unit tests and test docs separately

* Cleans up run-tests.sh and add release configs for travis

* Updates git actions for new run-tests.sh
  • Loading branch information
Panaetius authored and jsam committed Sep 18, 2019
1 parent 3fbde5e commit 58c2de4
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 27 deletions.
28 changes: 24 additions & 4 deletions .github/workflows/test.yml
Expand Up @@ -3,7 +3,7 @@ name: CI
on: [push]

jobs:
test-linux:
docs-linux:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
Expand All @@ -17,12 +17,32 @@ jobs:
version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pip
python -m pip install .[all]
git config --global --add user.name "Renku @ SDSC"
git config --global --add user.email "renku@datascience.ch"
- name: Test docs
run: ./run-tests.sh -d
test-linux:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7]
steps:
- uses: actions/checkout@master
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[nodocs]
git config --global --add user.name "Renku @ SDSC"
git config --global --add user.email "renku@datascience.ch"
- name: Test with pytest
run: ./run-tests.sh
run: ./run-tests.sh -s -t

test-macos:
runs-on: macos-latest
Expand All @@ -40,7 +60,7 @@ jobs:
run: |
brew update
brew install git-lfs shellcheck node || brew link --overwrite node
python -m pip install --upgrade pip
python -m pip install --upgrade pip
python -m pip install .[all]
git config --global --add user.name "Renku @ SDSC"
git config --global --add user.email "renku@datascience.ch"
Expand Down
23 changes: 19 additions & 4 deletions .travis.yml
Expand Up @@ -43,6 +43,7 @@ python:

stages:
- name: test
- name: docs
- name: integration
if: branch = master AND (type != pull_request)
- name: test OSX
Expand All @@ -64,6 +65,9 @@ before_install:
requirements-builder -e all --level=min setup.py > .travis-lowest-requirements.txt;
requirements-builder -e all --level=pypi setup.py > .travis-release-requirements.txt;
requirements-builder -e all --level=dev --req requirements-devel.txt setup.py > .travis-devel-requirements.txt;
requirements-builder -e nodocs --level=min setup.py > .travis-lowest-requirements-nodocs.txt;
requirements-builder -e nodocs --level=pypi setup.py > .travis-release-requirements-nodocs.txt;
requirements-builder -e nodocs --level=dev --req requirements-devel.txt setup.py > .travis-devel-requirements-nodocs.txt;
elif [[ $TRAVIS_OS_NAME == 'osx' ]]; then
brew update;
brew upgrade python;
Expand All @@ -75,22 +79,33 @@ before_install:

install:
- if [[ $TRAVIS_OS_NAME == 'linux' ]]; then
travis_retry python -m pip install -r .travis-${REQUIREMENTS}-requirements.txt;
travis_retry python -m pip install -e .[all];
travis_retry python -m pip install -r .travis-${REQUIREMENTS}-requirements-nodocs.txt;
travis_retry python -m pip install -e .[nodocs];
elif [[ $TRAVIS_OS_NAME == 'osx' ]]; then
travis_retry pipenv install --deploy;
source "$(pipenv --venv)/bin/activate";
travis_retry pip install -e .[all];
travis_retry pip install -e .[nodocs];
fi

script:
- "./run-tests.sh"
- "./run-tests.sh -t -s"

after_success:
- coveralls

jobs:
include:
- stage: docs
os: linux
dist: xenial
language: python
env:
- REQUIREMENTS=lowest
- REQUIREMENTS=release
install:
- travis_retry python -m pip install -r .travis-${REQUIREMENTS}-requirements-all.txt;
travis_retry python -m pip install -e .[all];
script: ./run-tests.sh -d
- stage: integration
os: linux
dist: xenial
Expand Down
10 changes: 0 additions & 10 deletions renku/models/projects.py
Expand Up @@ -19,8 +19,6 @@

import datetime

import pytz

from renku.utils.datetime8601 import parse_date

from . import _jsonld as jsonld
Expand Down Expand Up @@ -62,14 +60,6 @@ def _now(self):
"""Define default value for datetime fields."""
return datetime.datetime.now(datetime.timezone.utc)

def __attrs_post_init__(self):
"""Initialize computed attributes."""
if self.created and self.created.tzinfo is None:
self.created = pytz.utc.localize(self.created)

if self.updated and self.updated.tzinfo is None:
self.updated = pytz.utc.localize(self.updated)


class ProjectCollection(Collection):
"""Represent projects on the server.
Expand Down
5 changes: 3 additions & 2 deletions renku/utils/datetime8601.py
Expand Up @@ -42,8 +42,9 @@ def validate_iso8601(str_val):
def parse_date(value):
"""Convert date to datetime."""
if isinstance(value, datetime.datetime):
return value
date = dateutil_parse_date(value)
date = value
else:
date = dateutil_parse_date(value)
if not date.tzinfo:
# set timezone to local timezone
tz = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
Expand Down
83 changes: 76 additions & 7 deletions run-tests.sh
Expand Up @@ -23,10 +23,79 @@ set -o errexit
# quit on unbound symbols:
set -o nounset

pydocstyle renku tests conftest.py docs
isort -rc -c -df
unify -c -r renku tests conftest.py docs
check-manifest --ignore ".travis-*,renku/version.py"
find . -iname \*.sh -print0 | xargs -0 shellcheck
sphinx-build -qnNW docs docs/_build/html
pytest -v -m "not integration"
USAGE=$(cat <<-END
Usage:
run-tests.sh [-s | --styles] [-d | --docs] [-t | --tests]
run-tests.sh -h | --help
Options:
-h, --help Show this screen.
-s, --styles check styles
-d, --docs build and test docs
-t, --tests run unit tests
END
)

check_styles(){
pydocstyle renku tests conftest.py docs
isort -rc -c -df
unify -c -r renku tests conftest.py docs
check-manifest --ignore ".travis-*,renku/version.py"
find . -iname \*.sh -print0 | xargs -0 shellcheck
}

build_docs(){
sphinx-build -qnNW docs docs/_build/html
pytest -v -m "not integration" -o testpaths="docs conftest.py"
}

run_tests(){
pytest -v -m "not integration" -o testpaths="tests renku conftest.py"
}

usage(){
echo "$USAGE"
}

all=1
tests=
docs=
styles=

while [ "${1-}" != "" ]; do
case $1 in
-t | --tests )
tests=1
all=0
;;
-d | --docs )
docs=1
all=0
;;

-s | --styles )
styles=1
all=0
;;
-h | --help )
usage
exit
;;
esac
shift
done

docs=$((docs||all))
tests=$((tests||all))
styles=$((styles||all))

if [ "$docs" = "1" ]; then
build_docs
fi

if [ "$styles" = "1" ]; then
check_styles
fi

if [ "$tests" = "1" ]; then
run_tests
fi
6 changes: 6 additions & 0 deletions setup.py
Expand Up @@ -65,6 +65,12 @@
continue
extras_require['all'].extend(reqs)

extras_require['nodocs'] = list(setup_requires)
for name, reqs in extras_require.items():
if name.startswith(':') or name == 'docs':
continue
extras_require['nodocs'].extend(reqs)

install_requires = [
'appdirs>=1.4.3',
'attrs>=18.2.0',
Expand Down

0 comments on commit 58c2de4

Please sign in to comment.