Skip to content

Commit 87a28ae

Browse files
committed
Merge branch 'main' into fastapi-docs
2 parents cf3c1d9 + 8fb541e commit 87a28ae

5 files changed

Lines changed: 217 additions & 20 deletions

File tree

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fetch-depth: 0
1919
- uses: actions/setup-python@v4
2020
with:
21-
python-version: 3.8
21+
python-version: 3.9
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip

docs/_extensions/machow/interlinks/_extension.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ version: 1.0.0
44
quarto-required: ">=1.2.0"
55
contributes:
66
filters:
7-
- interlinks.py
7+
- interlinks.lua
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
local function read_json(filename)
2+
local file = io.open(filename, "r")
3+
if file == nil then
4+
return nil
5+
end
6+
local str = file:read("a")
7+
file:close()
8+
return quarto.json.decode(str)
9+
end
10+
11+
local inventory = {}
12+
13+
function lookup(search_object)
14+
15+
local results = {}
16+
for ii, inventory in ipairs(inventory) do
17+
for jj, item in ipairs(inventory.items) do
18+
-- e.g. :external+<inv_name>:<domain>:<role>:`<name>`
19+
if item.inv_name and item.inv_name ~= search_object.inv_name then
20+
goto continue
21+
end
22+
23+
if item.name ~= search_object.name then
24+
goto continue
25+
end
26+
27+
if search_object.role and item.role ~= search_object.role then
28+
goto continue
29+
end
30+
31+
if search_object.domain and item.domain ~= search_object.domain then
32+
goto continue
33+
else
34+
table.insert(results, item)
35+
36+
goto continue
37+
end
38+
39+
::continue::
40+
end
41+
end
42+
43+
if #results == 1 then
44+
return results[1]
45+
end
46+
if #results > 1 then
47+
print("Found multiple matches for " .. search_object.name)
48+
quarto.utils.dump(results)
49+
return nil
50+
end
51+
if #results == 0 then
52+
print("Found no matches for object:")
53+
quarto.utils.dump(search_object)
54+
end
55+
56+
return nil
57+
end
58+
59+
function mysplit (inputstr, sep)
60+
if sep == nil then
61+
sep = "%s"
62+
end
63+
local t={}
64+
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
65+
table.insert(t, str)
66+
end
67+
return t
68+
end
69+
70+
local function normalize_role(role)
71+
if role == "func" then
72+
return "function"
73+
end
74+
return role
75+
end
76+
77+
local function build_search_object(str)
78+
local starts_with_colon = str:sub(1, 1) == ":"
79+
local search = {}
80+
if starts_with_colon then
81+
local t = mysplit(str, ":")
82+
if #t == 2 then
83+
-- e.g. :py:func:`my_func`
84+
search.role = normalize_role(t[1])
85+
search.name = t[2]:match("%%60(.*)%%60")
86+
elseif #t == 3 then
87+
-- e.g. :py:func:`my_func`
88+
search.domain = t[1]
89+
search.role = normalize_role(t[2])
90+
search.name = t[3]:match("%%60(.*)%%60")
91+
elseif #t == 4 then
92+
-- e.g. :ext+inv:py:func:`my_func`
93+
search.external = true
94+
95+
search.inv_name = t[1]:match("external%+(.*)")
96+
search.domain = t[2]
97+
search.role = normalize_role(t[3])
98+
search.name = t[4]:match("%%60(.*)%%60")
99+
else
100+
print("couldn't parse this link: " .. str)
101+
return {}
102+
end
103+
else
104+
search.name = str:match("%%60(.*)%%60")
105+
end
106+
107+
if search.name == nil then
108+
print("couldn't parse this link: " .. str)
109+
return {}
110+
end
111+
112+
if search.name:sub(1, 1) == "~" then
113+
search.shortened = true
114+
search.name = search.name:sub(2, -1)
115+
end
116+
return search
117+
end
118+
119+
function report_broken_link(link, search_object, replacement)
120+
-- TODO: how to unescape html elements like [?
121+
return pandoc.Code(pandoc.utils.stringify(link.content))
122+
end
123+
124+
function Link(link)
125+
-- do not process regular links ----
126+
if not link.target:match("%%60") then
127+
return link
128+
end
129+
130+
-- lookup item ----
131+
local search = build_search_object(link.target)
132+
local item = lookup(search)
133+
134+
-- determine replacement, used if no link text specified ----
135+
local original_text = pandoc.utils.stringify(link.content)
136+
local replacement = search.name
137+
if search.shortened then
138+
local t = mysplit(search.name, ".")
139+
replacement = t[#t]
140+
end
141+
142+
-- set link text ----
143+
if original_text == "" then
144+
link.content = replacement
145+
end
146+
147+
-- report broken links ----
148+
if item == nil then
149+
return report_broken_link(link, search)
150+
end
151+
link.target = item.uri:gsub("%$$", search.name)
152+
153+
154+
return link
155+
end
156+
157+
function fixup_json(json, prefix)
158+
for _, item in ipairs(json.items) do
159+
item.uri = prefix .. item.uri
160+
end
161+
table.insert(inventory, json)
162+
end
163+
164+
return {
165+
{
166+
Meta = function(meta)
167+
local json
168+
local prefix
169+
for k, v in pairs(meta.interlinks.sources) do
170+
json = read_json(quarto.project.offset .. "/_inv/" .. k .. "_objects.json")
171+
prefix = pandoc.utils.stringify(v.url)
172+
fixup_json(json, prefix)
173+
end
174+
json = read_json(quarto.project.offset .. "/objects.json")
175+
if json ~= nil then
176+
fixup_json(json, "/")
177+
end
178+
end
179+
},
180+
{
181+
Link = Link
182+
}
183+
}

docs/_quarto.yml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,17 @@ project:
44
output-dir: _site
55

66
website:
7-
title: "Vetiver (Python)"
7+
title: "vetiver for Python"
88
description: "Version, share, deploy, and monitor your Python models"
99
repo-url: https://github.com/rstudio/vetiver-python
10-
repo-actions: [edit, issue]
1110
page-navigation: true
1211
favicon: "figures/logo.svg"
1312
page-footer:
14-
left: |
13+
center: |
1514
Proudly supported by
1615
[![](https://www.rstudio.com/assets/img/posit-logo-fullcolor-TM.svg){fig-alt="Posit PBC" width=65px}](https://posit.co/)
17-
center:
18-
- text: "Main site"
19-
href: https://vetiver.rstudio.com
20-
right:
21-
- icon: github
22-
href: https://github.com/rstudio/vetiver-python
23-
aria-label: Vetiver python GitHub
2416
navbar:
25-
background: primary
17+
background: "#562910"
2618
pinned: true
2719
logo: "figures/logo.svg"
2820
logo-alt: "vetiver-home"
@@ -35,18 +27,27 @@ website:
3527
- custom_handler.md
3628
- text: "Changelog"
3729
file: changelog.md
38-
- text: "Vetiver main site"
39-
href: https://vetiver.rstudio.com
30+
- text: "Learn more"
31+
menu:
32+
- text: "vetiver.rstudio.com"
33+
href: https://vetiver.rstudio.com
34+
target: _blank
35+
- text: "R package documentation"
36+
href: https://rstudio.github.io/vetiver-r/reference/
37+
target: _blank
38+
right:
39+
- icon: github
40+
href: https://github.com/rstudio/vetiver-python
41+
aria-label: Vetiver python GitHub
4042

4143
sidebar:
4244
- id: reference
4345
contents: "_sidebar.yml"
4446

4547
quartodoc:
4648
style: pkgdown
47-
title: "Vetiver-{{< env VERSION >}}"
49+
title: "Vetiver:v{{< env VERSION >}}"
4850
package: vetiver
49-
display_name: relative
5051
renderer:
5152
style: markdown
5253
display_name: relative
@@ -63,7 +64,8 @@ quartodoc:
6364
- title: Deploy
6465
desc: ""
6566
contents:
66-
- VetiverAPI
67+
- name: VetiverAPI
68+
children: linked
6769
- VetiverAPI.run
6870
- VetiverAPI.vetiver_post
6971
- vetiver_endpoint
@@ -104,4 +106,5 @@ profile:
104106

105107
format:
106108
html:
107-
theme: sandstone
109+
theme:
110+
- flatly

vetiver/vetiver_model.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,18 @@ def __init__(
9393

9494
@classmethod
9595
def from_pin(cls, board, name: str, version: str = None):
96-
96+
"""
97+
Create VetiverModel from pinned model.
98+
99+
Parameters
100+
----------
101+
board :
102+
`pins` board where model is located
103+
name : str
104+
Model name inside pins board
105+
version : str
106+
What model version should be loaded
107+
"""
97108
model = board.pin_read(name, version)
98109
meta = board.pin_meta(name, version)
99110

0 commit comments

Comments
 (0)