Skip to content

Commit 5d30dd3

Browse files
authored
Merge branch 'main' into spacy
2 parents bab0b2a + a12326a commit 5d30dd3

File tree

14 files changed

+256
-59
lines changed

14 files changed

+256
-59
lines changed

.github/workflows/docs.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ jobs:
7676
ALIAS: ${{ steps.deployment.outputs.env }}
7777

7878
- name: Update Github Deployment
79-
uses: bobheadxi/deployments@v0.4.3
80-
if: ${{ always() }}
79+
uses: bobheadxi/deployments@v1
80+
if: always()
8181
with:
8282
step: finish
8383
token: ${{ secrets.GITHUB_TOKEN }}
8484
status: ${{ job.status }}
85+
env: ${{ steps.deployment.outputs.env }}j
8586
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
8687
env_url: 'https://${{ steps.deployment.outputs.env }}--relaxed-mooncake-704252.netlify.app'
8788
logs: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'

.github/workflows/tests.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Install dependencies
3333
run: |
3434
python -m pip install --upgrade pip
35-
python -m pip install -e .[all]
35+
python -m pip install -e ".[dev,all_models]"
3636
- name: Run Tests
3737
run: |
3838
pytest -m 'not rsc_test and not docker' --cov --cov-report xml
@@ -109,3 +109,32 @@ jobs:
109109
- name: Run tests
110110
run: |
111111
pytest vetiver/tests/test_sklearn.py
112+
113+
typecheck:
114+
runs-on: ubuntu-latest
115+
116+
# We want to run on external PRs, but not on our own internal PRs as they'll be run
117+
# by the push to the branch.
118+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
119+
120+
strategy:
121+
matrix:
122+
python-version: [3.11]
123+
124+
steps:
125+
- name: Checkout Code
126+
uses: actions/checkout@v3
127+
128+
- name: Setup Python
129+
uses: actions/setup-python@v4
130+
with:
131+
python-version: ${{ matrix.python-version }}
132+
133+
- name: Install Packages
134+
shell: bash
135+
run: |
136+
pip install ".[dev,all_models]"
137+
138+
- name: Run Tests
139+
shell: bash
140+
run: make typecheck

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,8 @@ dev-stop:
9191
docker-compose down
9292
rm -f $(RSC_API_KEYS)
9393

94+
typecheck:
95+
pyright
96+
9497
$(RSC_API_KEYS): dev-start
9598
python script/setup-rsconnect/dump_api_keys.py $@

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
# Catch-all target:
66
%: Makefile
77
python version_config.py
8-
python -m quartodoc build
8+
python -m quartodoc build --verbose
99
python -m quartodoc interlinks
1010
quarto render

pyproject.toml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,65 @@ markers = [
1818
[tool.setuptools_scm]
1919
fallback_version = "999"
2020
version_scheme = 'post-release'
21+
22+
########## Tool - Pyright ##########
23+
[tool.pyright]
24+
# Paths of directories or files that should be included. If no paths
25+
# are specified, pyright defaults to the directory that contains the
26+
# config file. Paths may contain wildcard characters ** (a directory or
27+
# multiple levels of directories), * (a sequence of zero or more
28+
# characters), or ? (a single character). If no include paths are
29+
# specified, the root path for the workspace is assumed.
30+
include = [
31+
"vetiver/"
32+
]
33+
34+
# Paths of directories or files whose diagnostic output (errors and
35+
# warnings) should be suppressed even if they are an included file or
36+
# within the transitive closure of an included file. Paths may contain
37+
# wildcard characters ** (a directory or multiple levels of
38+
# directories), * (a sequence of zero or more characters), or ? (a
39+
# single character).
40+
ignore = [
41+
#"vetiver/__init__.py",
42+
#"vetiver/attach_pkgs.py",
43+
"vetiver/helpers.py",
44+
"vetiver/meta.py",
45+
"vetiver/mock.py",
46+
"vetiver/model_card.py",
47+
"vetiver/monitor.py",
48+
"vetiver/pin_read_write.py",
49+
"vetiver/prototype.py",
50+
"vetiver/rsconnect.py",
51+
"vetiver/server.py",
52+
"vetiver/types.py",
53+
"vetiver/utils.py",
54+
"vetiver/vetiver_model.py",
55+
"vetiver/write_docker.py",
56+
"vetiver/write_fastapi.py",
57+
"vetiver/handlers/",
58+
"vetiver/data/",
59+
"vetiver/tests"
60+
]
61+
62+
# Set of identifiers that should be assumed to contain a constant
63+
# value wherever used within this program. For example, { "DEBUG": true
64+
# } indicates that pyright should assume that the identifier DEBUG will
65+
# always be equal to True. If this identifier is used within a
66+
# conditional expression (such as if not DEBUG:) pyright will use the
67+
# indicated value to determine whether the guarded block is reachable
68+
# or not. Member expressions that reference one of these constants
69+
# (e.g. my_module.DEBUG) are also supported.
70+
defineConstant = { DEBUG = true }
71+
72+
# typeCheckingMode = "strict"
73+
useLibraryCodeForTypes = true
74+
reportUnnecessaryTypeIgnoreComment = true
75+
76+
# Specifies a list of execution environments (see below). Execution
77+
# environments are searched from start to finish by comparing the path
78+
# of a source file with the root path specified in the execution
79+
# environment.
80+
executionEnvironments = []
81+
82+
stubPath = ""

setup.cfg

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ install_requires =
4141
[options.extras_require]
4242
all =
4343
vetiver[dev]
44+
vetiver[all_models]
45+
vetiver[docs]
46+
47+
all_models =
4448
vetiver[torch]
4549
vetiver[statsmodels]
4650
vetiver[xgboost]
@@ -50,18 +54,23 @@ dev =
5054
pytest
5155
pytest-cov
5256
pytest-snapshot
57+
vetiver[typecheck]
5358

5459
docs =
5560
quartodoc
5661

57-
torch =
58-
torch
59-
6062
statsmodels =
6163
statsmodels
6264

65+
torch =
66+
torch
67+
6368
xgboost =
6469
xgboost
6570

6671
spacy =
6772
spacy
73+
74+
typecheck =
75+
pyright
76+
pandas-stubs

vetiver/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .server import VetiverAPI, vetiver_endpoint, predict # noqa
88
from .mock import get_mock_data, get_mock_model # noqa
99
from .pin_read_write import vetiver_pin_write # noqa
10-
from .attach_pkgs import load_pkgs # noqa
10+
from .attach_pkgs import load_pkgs, get_board_pkgs # noqa
1111
from .meta import VetiverMeta # noqa
1212
from .write_docker import write_docker, prepare_docker # noqa
1313
from .write_fastapi import write_app, vetiver_write_app # noqa

vetiver/attach_pkgs.py

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
1+
from __future__ import annotations
2+
import typing
3+
14
import tempfile
25
import os
6+
import warnings
37
from .vetiver_model import VetiverModel
48
from .meta import VetiverMeta
59

10+
if typing.TYPE_CHECKING:
11+
from typing import Optional
12+
from pathlib import Path
13+
614

7-
def load_pkgs(model: VetiverModel = None, packages: list = None, path=""):
15+
def load_pkgs(
16+
model: VetiverModel, packages: Optional[list] = None, path: str | Path = ""
17+
):
818
"""Load packages necessary for predictions
919
10-
Args
11-
----
12-
model: VetiverModel
13-
VetiverModel to extract packages from
14-
packages: list
15-
List of extra packages to include
16-
path: str
17-
Where to save output file
20+
Parameters
21+
----------
22+
model: VetiverModel
23+
VetiverModel to extract packages from
24+
packages: list
25+
List of extra packages to include
26+
path: str
27+
Where to save output file
1828
"""
1929

2030
required_pkgs = ["vetiver"]
2131
if packages:
22-
required_pkgs = list(set(required_pkgs + packages))
32+
required_pkgs += packages
2333

2434
if isinstance(model.metadata, dict):
2535
model.metadata = VetiverMeta.from_dict(model.metadata)
2636

2737
if model.metadata.required_pkgs:
28-
required_pkgs = list(set(required_pkgs + model.metadata.required_pkgs))
38+
required_pkgs += model.metadata.required_pkgs
2939

3040
tmp = tempfile.NamedTemporaryFile(suffix=".in", delete=False)
3141
tmp.close()
@@ -36,3 +46,37 @@ def load_pkgs(model: VetiverModel = None, packages: list = None, path=""):
3646

3747
os.system(f"pip-compile {tmp.name} --output-file={path}requirements.txt")
3848
os.remove(tmp.name)
49+
50+
51+
def get_board_pkgs(board) -> list[str]:
52+
"""
53+
Extract packages required for pin board authorization
54+
55+
Parameters
56+
----------
57+
board:
58+
A pin board, created by `pins.board_folder()` or another `board_` function.
59+
60+
Returns
61+
--------
62+
list[str]
63+
"""
64+
prot = board.fs.protocol
65+
66+
if prot == "rsc":
67+
return ["rsconnect-python"]
68+
elif prot == "file":
69+
return []
70+
elif prot == ["s3", "s3a"]:
71+
return ["s3fs"]
72+
elif prot == "abfs":
73+
return ["adlfs"]
74+
elif prot == ("gcs", "gs"):
75+
return ["gcsfs"]
76+
else:
77+
warnings.warn(
78+
f"required packages unknown for board protocol: {prot}, "
79+
"add to model's metadata to export",
80+
UserWarning,
81+
)
82+
return []

vetiver/pin_read_write.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def vetiver_pin_write(board, model: VetiverModel, versioned: bool = True):
4343
>>> vetiver.vetiver_pin_write(model_board, v)
4444
"""
4545
if not board.allow_pickle_read:
46-
raise NotImplementedError # must be pickle-able
46+
raise ValueError(
47+
"board does not allow pickled models. Set "
48+
"allow_pickle_read to True on board creation."
49+
)
4750

4851
inform(
4952
_log,

vetiver/tests/test_pin_write.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_board_pin_write_error():
1616
model=model, prototype_data=X_df, model_name="model", versioned=None
1717
)
1818
board = pins.board_temp()
19-
with pytest.raises(NotImplementedError):
19+
with pytest.raises(ValueError):
2020
vetiver_pin_write(board=board, model=v)
2121

2222

0 commit comments

Comments
 (0)