Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscripts.py
More file actions
Latest commit
170 lines (126 loc) · 4.33 KB
/
Copy pathscripts.py
File metadata and controls
170 lines (126 loc) · 4.33 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
importos
importre
importshutil
importsubprocess
importsys
frompathlibimportPath
defcheck_exit_code(command):
process=subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
ifnotprocess.stdout:
raiseRuntimeError("Process has no STDOUT")
whileTrue:
output=process.stdout.readline()
ifoutput==b""andprocess.poll() isnotNone:
break
ifoutput:
print(str(output.strip(), "utf-8"))
exit_code=process.poll()
ifexit_code!=0:
sys.exit(exit_code)
defrun_tests():
check_exit_code("uv run --env-file .env pytest")
defrun_formatter():
check_exit_code("ruff format .")
defrun_format_check():
check_exit_code("ruff format . --check")
defrun_linter():
check_exit_code("ruff check .")
defrun_linter_fix():
check_exit_code("ruff check . --fix")
defgenerate_docs():
here=Path(__file__).parent
input=here/"doc"
ifinput.exists():
shutil.rmtree(input)
check_exit_code(
"pdoc \
--include-undocumented \
--favicon https://logo.swmansion.com/membrane/\\?width\\=100\\&variant\\=signetDark\
--logo https://logo.swmansion.com/membrane/\\?width\\=70\\&variant\\=signetDark\
-t templates/doc \
-o doc \
fishjam"
)
input_images=here/"images"
out=here/"docs"/"api"
out_images=here/"docs"/"api"/"images"
ifout.exists():
shutil.rmtree(out)
shutil.copytree(input, out)
shutil.copytree(input_images, out_images)
# ...and rename the .html files to .md so that mkdocs picks them up!
forfinout.glob("**/*.html"):
f.rename(f.with_suffix(".md"))
defclean_mdx_content(content: str) ->str:
parts=re.split(r"((?:```[\s\S]*?```|`[^`\n]+`))", content)
# example: convert `fishjam._openapi_client.models.peer.Peer` into `Peer`
internal_path_pattern=r"fishjam\.(?:[\w.]+\.)?_[\w.]+\."
cleaned_parts= []
forpartinparts:
ifpart.startswith("`"):
text= (
part.replace("<", "<")
.replace(">", ">")
.replace("'", "'")
.replace("builtins.", "")
)
text=re.sub(internal_path_pattern, "", text)
cleaned_parts.append(text)
else:
text=part.replace("{", "\\{").replace("}", "\\}").replace("<", "<")
cleaned_parts.append(text)
return"".join(cleaned_parts)
defgenerate_docusaurus():
here=Path(__file__).parent
input=here/"doc"
out=here/"docusaurus"
ifinput.exists():
shutil.rmtree(input)
ifout.exists():
shutil.rmtree(out)
check_exit_code(
"pdoc \
--include-undocumented \
-t templates/docusaurus \
-o doc \
fishjam"
)
try:
os.remove(input/"index.html")
exceptFileNotFoundError:
pass
out.mkdir(parents=True, exist_ok=True)
forfininput.glob("**/*.html"):
content=f.read_text(encoding="utf-8")
safe_content=clean_mdx_content(content)
rel_path=f.relative_to(input)
dest_path=out/rel_path.parent/rel_path.stem/"index.md"
dest_path.parent.mkdir(parents=True, exist_ok=True)
dest_path.write_text(safe_content, encoding="utf-8")
defupdate_client():
iflen(sys.argv) <2:
raiseRuntimeError("Missing fishjam openapi.yaml raw url positional argument")
url_or_path=sys.argv[1]
is_url=url_or_path.startswith("http://") orurl_or_path.startswith("https://")
file_arg=f"--url {url_or_path}"ifis_urlelsef"--path {url_or_path}"
check_exit_code(
f"openapi-python-client generate \
{file_arg}\
--config openapi-python-client-config.yaml \
--meta=none \
--overwrite \
--output-path=fishjam/_openapi_client/ \
--custom-template-path=templates/openapi"
)
defstart_room_manager():
current_path=os.getcwd()
current_folder=os.path.basename(current_path)
ifcurrent_folder!="python-server-sdk":
raiseRuntimeError(
"Room Manager has to be started from the `python-server-sdk` directory."
)
subprocess.run(
["python", "-m", "examples.room_manager.main"] +sys.argv[1:], check=False
)