FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
diffusers-workflow/scripts/dump_openapi.py at develop · dkackman/diffusers-workflow · GitHub
dkackman
diffusers-workflow
Repository navigation
Code
Issues
1
(1)
Pull requests
1
(1)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
diffusers-workflow
/
scripts
/
dump_openapi.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
102 lines (83 loc) · 3.36 KB
Breadcrumbs
diffusers-workflow
/
scripts
/
dump_openapi.py
Copy path
File metadata and controls
102 lines (83 loc) · 3.36 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""Write the server's OpenAPI document, strict and normalized, to
ui/src/lib/generated/openapi.json - what `npm run gen:api` turns into the UI's
response types. `--check` exits 1 when the committed copy is stale;
`--stdout` prints instead of writing.
Normalized so it is the same on every machine and release: `info.version`
is "0", and the app is built with fixed directories and no token. Written
only under the FastAPI and Pydantic that constraints-openapi.txt pins, since
either one's release changes the document by itself."""
import
json
import
os
from
importlib
.
metadata
import
version
import
sys
import
tempfile
from
pathlib
import
Path
os
.
environ
[
"DW_STRICT_RESPONSES"
]
=
"1"
# before dw is imported: no index signatures
REPO
=
Path
(
__file__
).
resolve
().
parent
.
parent
# This checkout's dw, not whichever one the venv's editable install points
# at - a worktree sharing the main checkout's venv would otherwise dump the
# main checkout's contract
sys
.
path
.
insert
(
0
,
str
(
REPO
))
OPENAPI_PATH
=
REPO
/
"ui"
/
"src"
/
"lib"
/
"generated"
/
"openapi.json"
CONSTRAINTS
=
REPO
/
"constraints-openapi.txt"
def
pins
()
->
dict
[
str
,
str
]:
lines
=
(
line
.
split
(
"#"
)[
0
].
strip
()
for
line
in
CONSTRAINTS
.
read_text
().
splitlines
()
)
return
dict
(
line
.
split
(
"=="
)
for
line
in
lines
if
line
)
def
installed
()
->
dict
[
str
,
str
]:
return
{
name
:
version
(
name
)
for
name
in
pins
()}
def
unpinned
()
->
list
[
str
]:
"""Each pinned package whose installed version differs, as "name x (pinned y)"."""
want
,
have
=
pins
(),
installed
()
return
[
f"
{
name
}
{
have
[
name
]
}
(pinned
{
want
[
name
]
}
)"
for
name
in
want
if
have
[
name
]
!=
want
[
name
]
]
def
openapi_document
()
->
dict
:
with
tempfile
.
TemporaryDirectory
()
as
tmp
:
# dw creates its settings root on import, and the app's JobManager
# opens the job history under it; point that at the scratch
# directory first, so reading the schema never touches the history
# a running dw.serve owns
os
.
environ
[
"DIFFUSERS_HELPER_ROOT"
]
=
os
.
path
.
join
(
tmp
,
"helper"
)
from
dw
.
server
.
app
import
create_app
app
=
create_app
(
workflow_dir
=
os
.
path
.
join
(
tmp
,
"workflows"
),
output_dir
=
os
.
path
.
join
(
tmp
,
"outputs"
),
prompt_dir
=
os
.
path
.
join
(
tmp
,
"prompts"
),
)
try
:
document
=
app
.
openapi
()
finally
:
app
.
state
.
job_manager
.
shutdown
()
document
[
"info"
][
"version"
]
=
"0"
return
document
def
render
()
->
str
:
return
json
.
dumps
(
openapi_document
(),
indent
=
2
,
sort_keys
=
True
)
+
"
\n
"
def
main
(
argv
:
list
[
str
])
->
int
:
if
"--stdout"
in
argv
:
sys
.
stdout
.
write
(
render
())
return
0
stray
=
unpinned
()
if
stray
:
print
(
f"not on the versions the document is pinned to:
{
', '
.
join
(
stray
)
}
- "
f"pip install -c
{
CONSTRAINTS
.
name
}
-r requirements.txt"
)
return
2
text
=
render
()
if
"--check"
in
argv
:
current
=
OPENAPI_PATH
.
read_text
()
if
OPENAPI_PATH
.
exists
()
else
""
if
current
!=
text
:
print
(
f"
{
OPENAPI_PATH
.
relative_to
(
REPO
)
}
is stale: run python scripts/dump_openapi.py"
)
return
1
return
0
OPENAPI_PATH
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
OPENAPI_PATH
.
write_text
(
text
)
return
0
if
__name__
==
"__main__"
:
sys
.
exit
(
main
(
sys
.
argv
[
1
:]))
Back
|
FazBrowse Home
|
New Git URL