Skip to content

Commit acb2164

Browse files
authored
Merge branch 'main' into dev-sd-handler
2 parents 3e68319 + ce9b5b8 commit acb2164

16 files changed

Lines changed: 312 additions & 38 deletions

.github/workflows/tests.yml

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ on:
1111
jobs:
1212
tests:
1313
name: "Tests"
14-
runs-on: ubuntu-latest
14+
runs-on: ${{ matrix.os }}
1515
strategy:
1616
matrix:
17-
python-version: ['3.7', '3.8', '3.9', '3.10']
17+
include:
18+
- os: 'ubuntu-latest'
19+
python-version: '3.7'
20+
- os: 'macos-latest'
21+
python-version: '3.8'
22+
- os: 'windows-latest'
23+
python-version: '3.9'
24+
- os: 'ubuntu-latest'
25+
python-version: '3.10'
26+
1827
steps:
1928
- uses: actions/checkout@v2
2029
- uses: actions/setup-python@v2
@@ -26,6 +35,32 @@ jobs:
2635
python -m pip install -e .[dev,torch]
2736
- name: Run Tests
2837
run: |
29-
pytest --cov --cov-report xml .
38+
pytest -m 'not rsc_test' --cov --cov-report xml
3039
- name: Upload coverage
3140
uses: codecov/codecov-action@v2
41+
42+
test-rsconnect:
43+
name: "Test RSConnect"
44+
runs-on: ubuntu-latest
45+
if: ${{ !github.event.pull_request.head.repo.fork }}
46+
steps:
47+
- uses: actions/checkout@v2
48+
- uses: actions/setup-python@v2
49+
with:
50+
python-version: 3.8
51+
- name: Install dependencies
52+
run: |
53+
python -m pip install --upgrade pip
54+
python -m pip install -e .[dev,torch]
55+
- name: run RStudio Connect
56+
run: |
57+
docker-compose up --build -d
58+
make dev
59+
env:
60+
RSC_LICENSE: ${{ secrets.RSC_LICENSE }}
61+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
62+
63+
# NOTE: edited to run checks for python package
64+
- name: Run tests
65+
run: |
66+
pytest vetiver -m 'rsc_test'

Makefile

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
.PHONY: clean-pyc clean-build clean docs
2+
UNAME := $(shell uname)
3+
4+
SPHINX_BUILDARGS=
5+
# Note that these are keys generated by the docker rsconnect service, so are
6+
# not really secrets. They are saved to json to make it easy to use rsconnect
7+
# as multiple users from the tests
8+
RSC_API_KEYS=vetiver/tests/rsconnect_api_keys.json
9+
10+
ifeq ($(UNAME), Darwin)
11+
BROWSER := open
12+
else
13+
BROWSER := python -mwebbrowser
14+
endif
15+
16+
help:
17+
@echo "clean - remove all build, test, coverage and Python artifacts"
18+
@echo "clean-build - remove build artifacts"
19+
@echo "clean-pyc - remove Python file artifacts"
20+
@echo "clean-test - remove test and coverage artifacts"
21+
@echo "lint - check style with flake8"
22+
@echo "test - run tests quickly with the default Python"
23+
@echo "coverage - check code coverage quickly with the default Python"
24+
@echo "docs - generate Sphinx HTML documentation, including API docs"
25+
@echo "cdocs - cleanout previous build & generate Sphinx HTML documentation, including API docs"
26+
@echo "release - package and upload a release"
27+
@echo "dist - package"
28+
@echo "install - install the package to the active Python's site-packages"
29+
@echo "dev - generate RStudio Connect API keys"
30+
@echo "dev-start - start up development RStudio Connect in Docker"
31+
@echo "dev-stop - stop RStudio Connect dev container"
32+
33+
clean: clean-build clean-pyc clean-test docs-clean
34+
35+
clean-build:
36+
rm -fr build/
37+
rm -fr dist/
38+
rm -fr .eggs/
39+
find . -name '*.egg-info' -exec rm -fr {} +
40+
find . -name '*.egg' -exec rm -f {} +
41+
42+
clean-pyc:
43+
find . -name '*.pyc' -exec rm -f {} +
44+
find . -name '*.pyo' -exec rm -f {} +
45+
find . -name '*~' -exec rm -f {} +
46+
find . -name '__pycache__' -exec rm -fr {} +
47+
48+
clean-test:
49+
rm -f .coverage
50+
rm -f coverage.xml
51+
rm -fr htmlcov/
52+
53+
lint:
54+
flake8 vetiver
55+
56+
test: clean-test
57+
pytest
58+
59+
coverage:
60+
coverage report -m
61+
coverage html
62+
$(BROWSER) htmlcov/index.html
63+
64+
cdocs cdoc cdocumentation: docs-clean docs
65+
66+
docs-clean:
67+
$(MAKE) -C docs clean
68+
69+
docs doc documentation:
70+
$(MAKE) -C docs html
71+
$(BROWSER) docs/_build/html/index.html
72+
73+
release: dist
74+
twine upload dist/*
75+
76+
dist: clean
77+
python setup.py sdist
78+
79+
install: clean
80+
python setup.py install
81+
82+
develop: clean-pyc
83+
python setup.py develop
84+
85+
dev: vetiver/tests/rsconnect_api_keys.json
86+
87+
dev-start:
88+
docker-compose up -d
89+
docker-compose exec -T rsconnect bash < script/setup-rsconnect/add-users.sh
90+
# curl fails with error 52 without a short sleep....
91+
sleep 5
92+
curl -s --retry 10 --retry-connrefused http://localhost:3939
93+
94+
dev-stop:
95+
docker-compose down
96+
rm -f $(RSC_API_KEYS)
97+
98+
$(RSC_API_KEYS): dev-start
99+
python script/setup-rsconnect/dump_api_keys.py $@

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](h
99

1010
_Vetiver, the oil of tranquility, is used as a stabilizing ingredient in perfumery to preserve more volatile fragrances._
1111

12-
The goal of vetiver is to provide fluent tooling to version, share, deploy, and monitor a trained model. Functions handle both recording and checking the model's input data prototype, and predicting from a remote API endpoint. The vetiver package is extensible, with generics that can support many kinds of models, and available for both Python and R. To learn more about vetiver, see the documentation at <https://vetiver.rstudio.com/>
12+
The goal of vetiver is to provide fluent tooling to version, share, deploy, and monitor a trained model. Functions handle both recording and checking the model's input data prototype, and predicting from a remote API endpoint. The vetiver package is extensible, with generics that can support many kinds of models, and available for both Python and R. To learn more about vetiver, see:
13+
14+
- the documentation at <https://vetiver.rstudio.com/>
15+
- the R package at <https://rstudio.github.io/vetiver-r/>
1316

1417
You can use vetiver with:
1518

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: '3.1'
2+
3+
services:
4+
5+
rsconnect:
6+
image: rstudio/rstudio-connect:2021.12.1
7+
restart: always
8+
ports:
9+
- 3939:3939
10+
volumes:
11+
- $PWD/script/setup-rsconnect/users.txt:/etc/users.txt
12+
- $PWD/script/setup-rsconnect/rstudio-connect.gcfg:/etc/rstudio-connect/rstudio-connect.gcfg
13+
# by default, mysql rounds to 4 decimals, but tests require more precision
14+
privileged: true
15+
environment:
16+
RSTUDIO_CONNECT_HASTE: "enabled"
17+
RSC_LICENSE: ${RSC_LICENSE}

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
[build-system]
22
requires = ["setuptools>=45", "wheel"]
33
build-backend = "setuptools.build_meta"
4+
5+
[tool.pytest.ini_options]
6+
testpaths = ["vetiver"]
7+
addopts = "--doctest-modules"
8+
doctest_optionflags = "NORMALIZE_WHITESPACE"
9+
markers = [
10+
"rsc_test: tests for rstudio connect",
11+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
awk ' { system("useradd -m -s /bin/bash "$1); system("echo \""$1":"$2"\" | chpasswd"); system("id "$1) } ' /etc/users.txt
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import json
2+
import sys
3+
4+
from pins.rsconnect.api import _HackyConnect
5+
6+
OUT_FILE = sys.argv[1]
7+
8+
9+
def get_api_key(user, password, email):
10+
rsc = _HackyConnect("http://localhost:3939")
11+
12+
return rsc.create_first_admin(user, password, email).api_key
13+
14+
15+
api_keys = {
16+
"admin": get_api_key("admin", "admin0", "admin@example.com"),
17+
"susan": get_api_key("susan", "susan", "susan@example.com"),
18+
"derek": get_api_key("derek", "derek", "derek@example.com"),
19+
}
20+
21+
json.dump(api_keys, open(OUT_FILE, "w"))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[Server]
2+
DataDir = /data
3+
Address = http://localhost:3939
4+
5+
[HTTP]
6+
Listen = :3939
7+
8+
[Authentication]
9+
Provider = pam
10+
11+
[Authorization]
12+
DefaultUserRole = publisher
13+
14+
[Python]
15+
Enabled = false
16+
17+
[RPackageRepository "CRAN"]
18+
URL = https://packagemanager.rstudio.com/cran/__linux__/bionic/latest
19+
20+
[RPackageRepository "RSPM"]
21+
URL = https://packagemanager.rstudio.com/cran/__linux__/bionic/latest

script/setup-rsconnect/users.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
admin admin0
2+
test test
3+
susan susan
4+
derek derek
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"admin": "iv6yzMB4GwhQIXjI3lOWG2T21N02C9SU", "susan": "llQqii6bHqV5R9eMN7qpTvJqr3xtnRmy", "derek": "FkakZvdVk2ApxDVkbEn6u2g0eSul4tE6"}

0 commit comments

Comments
 (0)