Skip to content

Commit

Permalink
Merge pull request #263 from rstudio/mbh-modernization-hammer
Browse files Browse the repository at this point in the history
Use setuptools_scm for version
  • Loading branch information
meatballhat authored Jun 22, 2020
2 parents ae3181b + be1672f commit 58dec25
Show file tree
Hide file tree
Showing 12 changed files with 1,133 additions and 81 deletions.
127 changes: 127 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: main
on:
push:
branches: [master]
tags: ['*']
pull_request:
branches: [master]
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['2.7', '3.5', '3.6', '3.7', '3.8']
include:
- os: macos-latest
python-version: '3.8'
runs-on: ${{ matrix.os }}
name: test (py${{ matrix.python-version }} ${{ matrix.os }})
steps:
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- if: ${{ matrix.os != 'macos-latest' }}
uses: actions/cache@v1
with:
path: ~/.cache/pip
key: pip-${{ matrix.os }}-py${{ matrix.python-version }}-${{ hashFiles('Pipfile.lock') }}
restore-keys: |
pip-${{ matrix.os }}-py${{ matrix.python-version }}-${{ hashFiles('Pipfile.lock') }}
pip-${{ matrix.os }}-py${{ matrix.python-version }}-
- if: ${{ matrix.os == 'macos-latest' }}
uses: actions/cache@v1
with:
path: ~/Library/Caches/pip
key: pip-${{ matrix.os }}-py${{ matrix.python-version }}-${{ hashFiles('Pipfile.lock') }}
restore-keys: |
pip-${{ matrix.os }}-py${{ matrix.python-version }}-${{ hashFiles('Pipfile.lock') }}
pip-${{ matrix.os }}-py${{ matrix.python-version }}-
- uses: actions/cache@v1
with:
path: ~/.local/share/virtualenvs
key: virtualenvs-${{ matrix.os }}-py${{ matrix.python-version }}-${{ hashFiles('Pipfile.lock') }}
restore-keys: |
virtualenvs-${{ matrix.os }}-py${{ matrix.python-version }}-${{ hashFiles('Pipfile.lock') }}
virtualenvs-${{ matrix.os }}-py${{ matrix.python-version }}-
- run: pip install -U -I pip pipenv
- run: pipenv install --dev
- run: pipenv run pip freeze
- run: pipenv run python setup.py --version
- run: pipenv run python -Wi setup.py test
distributions:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: git fetch --prune --unshallow
- uses: actions/setup-python@v2
with:
python-version: 3.8.x
- uses: actions/cache@v1
with:
path: ~/.cache/pip
key: pip-ubuntu-latest-py3.8-${{ hashFiles('Pipfile.lock') }}
restore-keys: |
pip-ubuntu-latest-py3.8-${{ hashFiles('Pipfile.lock') }}
pip-ubuntu-latest-py3.8-
- uses: actions/cache@v1
with:
path: ~/.local/share/virtualenvs
key: virtualenvs-ubuntu-latest-py3.8-${{ hashFiles('Pipfile.lock') }}
restore-keys: |
virtualenvs-ubuntu-latest-py3.8-${{ hashFiles('Pipfile.lock') }}
virtualenvs-ubuntu-latest-py3.8-
- run: pip install -U -I pip pipenv
- run: pipenv install --dev
- run: pipenv run pip install -U 'SecretStorage>=3'
- run: make dist
id: create_dist
- uses: actions/upload-artifact@v2
with:
name: distributions
path: dist/
- run: pipenv run pip install -vvv ${{ steps.create_dist.outputs.whl }}
- run: pipenv run python -c 'import rsconnect_jupyter;print(rsconnect_jupyter.__version__)'
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.create_dist.outputs.whl }}
asset_name: ${{ steps.create_dist.outputs.whl_basename }}
asset_content_type: application/x-wheel+zip
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET }}
aws-region: us-east-1
- if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: make sync-latest-to-s3
- if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
# docs:
# needs: test
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - run: make docs-build
# - uses: actions/upload-artifact@v2
# with:
# name: docs
# path: docs/site/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
/*.eggs
.DS_Store
.vagrant
/rsconnect_jupyter/static/version.json
/rsconnect_jupyter/static/version.json
/rsconnect_jupyter/version.py
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ RUN conda update conda

USER ${NB_UID}:${NB_GID}
RUN bash -c 'cd /home/builder \
&& conda create --yes --channel conda-forge --name py${PY_VERSION/./} python=${PY_VERSION} jupyter numpy matplotlib setuptools pip'
&& conda create --yes --channel conda-forge --name py${PY_VERSION/./} python=${PY_VERSION} jupyter numpy matplotlib setuptools pip pipenv'
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ include rsconnect_jupyter/static/*.js
include rsconnect_jupyter/static/*.json
include rsconnect_jupyter/static/main.css
include rsconnect_jupyter/static/images/*.png
include rsconnect_jupyter/version.txt
75 changes: 45 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ NB_UID=$(shell id -u)
NB_GID=$(shell id -g)

IMAGE=rstudio/rsconnect-jupyter-py
VERSION=$(shell cat rsconnect_jupyter/version.txt)
VERSION_BUILD=${VERSION}.$(shell printenv BUILD_NUMBER || echo 9999)
VERSION := $(shell pipenv run python setup.py --version)
BDIST_WHEEL := dist/rsconnect_jupyter-$(VERSION)-py2.py3-none-any.whl
S3_PREFIX := s3://rstudio-connect-downloads/connect/rsconnect-jupyter
PORT = $(shell printenv PORT || echo 9999)

# NOTE: See the `dist` target for why this exists.
SOURCE_DATE_EPOCH := $(shell date +%s)
export SOURCE_DATE_EPOCH

clean:
rm -rf build/ dist/ rsconnect_jupyter.egg-info/

Expand All @@ -30,7 +35,6 @@ launch:
-e NB_UID=$(NB_UID) \
-e NB_GID=$(NB_GID) \
-e PY_VERSION=$(PY_VERSION) \
-e BUILD_NUMBER=$(BUILD_NUMBER) \
-p :$(PORT):9999 \
$(DOCKER_IMAGE) \
/rsconnect_jupyter/run.sh $(TARGET)
Expand All @@ -55,25 +59,30 @@ test-selenium:
$(MAKE) -C selenium test-env-down || true ; \
exit $$EXITCODE

# NOTE: Wheels won't get built if _any_ file it tries to touch has a timestamp
# before 1980 (system files) so the $(SOURCE_DATE_EPOCH) current timestamp is
# exported as a point of reference instead.
dist: version-frontend
# wheels don't get built if _any_ file it tries to touch has a timestamp < 1980
# (system files) so use the current timestamp as a point of reference instead
SOURCE_DATE_EPOCH="$(shell date +%s)"; python setup.py sdist bdist_wheel
pipenv run python setup.py bdist_wheel
pipenv run twine check $(BDIST_WHEEL)
rm -vf dist/*.egg
@echo "::set-output name=whl::$(BDIST_WHEEL)"
@echo "::set-output name=whl_basename::$(notdir $(BDIST_WHEEL))"

package:
make DOCKER_IMAGE=$(IMAGE)3 PY_VERSION=3 TARGET=dist launch

run:
# link python package
python setup.py develop
pipenv install --dev
# install rsconnect_jupyter as a jupyter extension
jupyter-nbextension install --symlink --user --py rsconnect_jupyter
pipenv run jupyter-nbextension install --symlink --user --py rsconnect_jupyter
# enable js extension
jupyter-nbextension enable --py rsconnect_jupyter
pipenv run jupyter-nbextension enable --py rsconnect_jupyter
# enable python extension
jupyter-serverextension enable --py rsconnect_jupyter
pipenv run jupyter-serverextension enable --py rsconnect_jupyter
# start notebook
jupyter-notebook -y --notebook-dir=/notebooks --ip='0.0.0.0' --port=9999 --no-browser --NotebookApp.token=''
pipenv run jupyter-notebook -y --notebook-dir=/notebooks --ip='0.0.0.0' --port=9999 --no-browser --NotebookApp.token=''

shell:
bash
Expand All @@ -85,31 +94,31 @@ dist-run%:
make DOCKER_IMAGE=$(IMAGE)$* PY_VERSION=$* TARGET=dist-run launch

dist-run: dist
pip install dist/rsconnect_jupyter-$(VERSION_BUILD)-py2.py3-none-any.whl
jupyter-nbextension install --symlink --user --py rsconnect_jupyter
jupyter-nbextension enable --py rsconnect_jupyter
jupyter-serverextension enable --py rsconnect_jupyter
jupyter-notebook -y --notebook-dir=/notebooks --ip='0.0.0.0' --port=9999 --no-browser --NotebookApp.token=''
pipenv run pip install dist/rsconnect_jupyter-$(VERSION)-py2.py3-none-any.whl
pipenv run jupyter-nbextension install --symlink --user --py rsconnect_jupyter
pipenv run jupyter-nbextension enable --py rsconnect_jupyter
pipenv run jupyter-serverextension enable --py rsconnect_jupyter
pipenv run jupyter-notebook -y --notebook-dir=/notebooks --ip='0.0.0.0' --port=9999 --no-browser --NotebookApp.token=''

pypi-run%:
make DOCKER_IMAGE=$(IMAGE)$* PY_VERSION=$* TARGET=pypi-run launch

pypi-run:
pip install rsconnect_jupyter==$(VERSION_BUILD)
jupyter-nbextension install --symlink --user --py rsconnect_jupyter
jupyter-nbextension enable --py rsconnect_jupyter
jupyter-serverextension enable --py rsconnect_jupyter
jupyter-notebook -y --notebook-dir=/notebooks --ip='0.0.0.0' --port=9999 --no-browser --NotebookApp.token=''
pipenv run pip install rsconnect_jupyter==$(VERSION)
pipenv run jupyter-nbextension install --symlink --user --py rsconnect_jupyter
pipenv run jupyter-nbextension enable --py rsconnect_jupyter
pipenv run jupyter-serverextension enable --py rsconnect_jupyter
pipenv run jupyter-notebook -y --notebook-dir=/notebooks --ip='0.0.0.0' --port=9999 --no-browser --NotebookApp.token=''

pypi-test-run%:
make DOCKER_IMAGE=$(IMAGE)$* PY_VERSION=$* TARGET=pypi-test-run launch

pypi-test-run:
pip install --index-url https://test.pypi.org/simple/ rsconnect_jupyter==$(VERSION_BUILD)
jupyter-nbextension install --symlink --user --py rsconnect_jupyter
jupyter-nbextension enable --py rsconnect_jupyter
jupyter-serverextension enable --py rsconnect_jupyter
jupyter-notebook -y --notebook-dir=/notebooks --ip='0.0.0.0' --port=9999 --no-browser --NotebookApp.token=''
pipenv run pip install --index-url https://test.pypi.org/simple/ rsconnect_jupyter==$(VERSION)
pipenv run jupyter-nbextension install --symlink --user --py rsconnect_jupyter
pipenv run jupyter-nbextension enable --py rsconnect_jupyter
pipenv run jupyter-serverextension enable --py rsconnect_jupyter
pipenv run jupyter-notebook -y --notebook-dir=/notebooks --ip='0.0.0.0' --port=9999 --no-browser --NotebookApp.token=''

build/mock-connect/bin/flask:
bash -c '\
Expand Down Expand Up @@ -143,10 +152,10 @@ endif
## Inside Jenkins (when JOB_NAME is defined), we are in the right type of
## Docker container. Otherwise, launch pandoc inside a
## rstudio/connect:docs container.
BUILD_DOC=env VERSION=${VERSION_BUILD} ./docs/build-doc.sh
BUILD_DOC=env VERSION=${VERSION} ./docs/build-doc.sh
ifeq (${JOB_NAME},)
BUILD_DOC=docker run --rm=true ${DOCKER_RUN_AS} \
-e VERSION=${VERSION_BUILD} \
-e VERSION=${VERSION} \
${DOCKER_ARGS} \
-v $(CURDIR):/rsconnect_jupyter \
-w /rsconnect_jupyter \
Expand All @@ -160,8 +169,14 @@ docs-build:
${BUILD_DOC}


dist/rsconnect-jupyter-${VERSION_BUILD}.pdf: docs/README.md docs/*.gif
dist/rsconnect-jupyter-${VERSION}.pdf: docs/README.md docs/*.gif
${BUILD_DOC}

version-frontend:
echo '{ "version": "${VERSION}"}' > rsconnect_jupyter/static/version.json
printf '{"version":"%s"}\n' $(VERSION) >rsconnect_jupyter/static/version.json

.PHONY: sync-latest-to-s3
sync-latest-to-s3:
aws s3 cp --acl bucket-owner-full-control \
$(BDIST_WHEEL) \
$(S3_PREFIX)/latest/rsconnect_jupyter-latest-py2.py3-none-any.whl
27 changes: 27 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
black = "*"
coverage = "*"
flake8 = "*"
importlib-metadata = "*"
ipython = "*"
pytest = "*"
pytest-cov = "*"
setuptools_scm = "*"
toml = "*"
twine = "*"
wheel = "*"

[packages]
nbconvert = ">=5.0"
nbformat = "*"
notebook = "*"
rsconnect-python = "1.5.0b1"
six = "*"

[pipenv]
allow_prereleases = true
Loading

0 comments on commit 58dec25

Please sign in to comment.