Skip to content

Commit

Permalink
Merge pull request #26 from consideRatio/setup-travis-pypi-cd
Browse files Browse the repository at this point in the history
CI/CD update + a bug found by pytest-flakes?
  • Loading branch information
yuvipanda authored Dec 9, 2019
2 parents 1f94f42 + 6317dc8 commit 489c4b2
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 12 deletions.
21 changes: 21 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[bumpversion]
current_version = 0.4.0.dev
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<release>[a-z0-9]+))?
tag_name = {new_version}
allow_dirty = True
commit = True
tag = False
serialize =
{major}.{minor}.{patch}.{release}
{major}.{minor}.{patch}

[bumpversion:file:ltiauthenticator/__init__.py]

[bumpversion:file:setup.py]

[bumpversion:part:release]
optional_value = stable
values =
dev
stable

30 changes: 22 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
dist: bionic
language: python
sudo: false
python:
- 3.8
- 3.7
- 3.6
- 3.5

# install dependencies
# initial step - install dependencies
install:
- pip install --no-cache-dir -e .
- pip install --no-cache-dir -r dev-requirements.txt
- pip install --upgrade pip
- pip install -r dev-requirements.txt
- pip install .
- pip freeze

# command to run tests
# middle step - run tests
script:
- py.test tests/
- pytest --verbose --flakes

matrix:
fast_finish: true
# final step - optionally deploy
deploy:
provider: pypi
user: "__token__"
# password: set by TravisCI's environment variable PYPI_PASSWORD
# ref: https://travis-ci.org/jupyterhub/ltiauthenticator/settings
distributions: sdist bdist_wheel
on:
# Only deploy on tagged commits instead of the default of only doing it to
# the master branch. A tag does not belong specifically to a branch, so
# without this it would fail to deploy for tags.
tags: true
71 changes: 71 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# How to make a release

`jupyterhub-ltiauthenticator` is a package [available on
PyPI](https://pypi.org/project/jupyterhub-ltiauthenticator/). These are
instructions on how to make a release on PyPI. The PyPI release is packaged and
published automatically by TravisCI when a git tag is pushed.

For you to follow along according to these instructions, you need:
- To have push rights to the [ltiauthenticator GitHub
repository](https://github.com/jupyterhub/ltiauthenticator).

## Steps to make a release

1. Update [CHANGELOG.md](CHANGELOG.md) if it is not up to date, and verify
[README.md](README.md) has an updated output of running `--help`. Make a PR
to review the CHANGELOG notes.

To get the foundation of the changelog written, you can install
[github-activity](https://github.com/choldgraf/github-activity) and run
`github-activity --kind pr jupyterhub/ltiauthenticator` after setting up
credentials as described in the project's README.md file.

1. Once the changelog is up to date, checkout master and make sure it is up to date and clean.

```bash
ORIGIN=${ORIGIN:-origin} # set to the canonical remote, e.g. 'upstream' if 'origin' is not the official repo
git checkout master
git fetch $ORIGIN master
git reset --hard $ORIGIN/master
# WARNING! This next command deletes any untracked files in the repo
git clean -xfd
```

1. Update the version with `bump2version` (can be installed with `pip install -r
dev-requirements.txt`)

```bash
VERSION=... # e.g. 1.2.3
bump2version --tag --new-version $VERSION -
```

1. Reset the version to the next development version with `bump2version`

```bash
bump2version --no-tag patch
```

1. Push your two commits to master along with the annotated tags referencing
commits on master.

```
git push --follow-tags $ORIGIN master
```

## Manually uploading to PyPI

We are using CD with Travis to automatically update PyPI, but if you want to do
it manually when you are on a tagged commit in a otherwise cleaned repository,
you can do this.

1. Package the release

```bash
python3 setup.py sdist bdist_wheel
```

1. Upload it to PyPI

```bash
twine upload dist/*
```
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
bump2version
pytest
pytest-flakes
33 changes: 30 additions & 3 deletions ltiauthenticator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import time

from traitlets import Bool, Dict
from traitlets import Dict
from tornado import gen, web

from jupyterhub.auth import Authenticator
Expand All @@ -10,6 +10,8 @@
from oauthlib.oauth1.rfc5849 import signature
from collections import OrderedDict

__version__ = '0.4.0.dev'

class LTILaunchValidator:
# Record time when process starts, so we can reject requests made
# before this
Expand Down Expand Up @@ -184,5 +186,30 @@ class LTIAuthenticateHandler(BaseHandler):

@gen.coroutine
def post(self):
user = yield self.login_user()
self.redirect(self.get_body_argument('custom_next', self.get_next_url()))
"""
Technical reference of relevance to understand this function
------------------------------------------------------------
1. Class dependencies
- jupyterhub.handlers.BaseHandler: https://github.com/jupyterhub/jupyterhub/blob/abb93ad799865a4b27f677e126ab917241e1af72/jupyterhub/handlers/base.py#L69
- tornado.web.RequestHandler: https://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler
2. Function dependencies
- login_user: https://github.com/jupyterhub/jupyterhub/blob/abb93ad799865a4b27f677e126ab917241e1af72/jupyterhub/handlers/base.py#L696-L715
login_user is defined in the JupyterHub wide BaseHandler class,
mainly wraps a call to the authenticate function and follow up.
a successful authentication with a call to auth_to_user that
persists a JupyterHub user and returns it.
- get_next_url: https://github.com/jupyterhub/jupyterhub/blob/abb93ad799865a4b27f677e126ab917241e1af72/jupyterhub/handlers/base.py#L587
- get_body_argument: https://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.get_body_argument
"""
# FIXME: Figure out if we want to pass the user returned from
# self.login_user() to self.get_next_url(). It is named
# _ for now as pyflakes is fine about having an unused
# variable named _.
_ = yield self.login_user()
next_url = self.get_next_url()
body_argument = self.get_body_argument(
name='custom_next',
default=next_url,
)

self.redirect(body_argument)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='jupyterhub-ltiauthenticator',
version='0.3',
version='0.4.0.dev',
description='JupyterHub authenticator implementing LTI v1',
url='https://github.com/yuvipanda/jupyterhub-ltiauthenticator',
author='Yuvi Panda',
Expand Down

0 comments on commit 489c4b2

Please sign in to comment.