solara-enterprise 1.27.0__py2.py3-none-any.whl → 1.28.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  "Enterprise features for Solara"
2
- __version__ = "1.27.0"
2
+ __version__ = "1.28.0"
solara_enterprise/ssg.py CHANGED
@@ -3,6 +3,7 @@ import multiprocessing.pool
3
3
  import threading
4
4
  import time
5
5
  import typing
6
+ import urllib
6
7
  from pathlib import Path
7
8
  from typing import List, Optional
8
9
 
@@ -124,10 +125,18 @@ def ssg_crawl_route(base_url: str, route: solara.Route, build_path: Path, thread
124
125
  page.locator("#kernel-busy-indicator").wait_for(state="hidden")
125
126
  # page.wait_
126
127
  time.sleep(0.5)
127
- html = page.content()
128
+ raw_html = page.content()
128
129
  except Exception:
129
130
  logger.exception("Failure retrieving content for url: %s", url)
130
131
  raise
132
+ request_path = urllib.parse.urlparse(url).path
133
+
134
+ import solara.server.server
135
+
136
+ # the html from playwright is not what we want, pass it through the jinja template again
137
+ html = solara.server.server.read_root(request_path, ssg_data=_ssg_data(raw_html))
138
+ if html is None:
139
+ raise Exception(f"Failed to render {url}")
131
140
  path.write_text(html, encoding="utf-8")
132
141
  rprint(f"Wrote to {path}")
133
142
  page.goto("about:blank")
@@ -140,12 +149,8 @@ def ssg_crawl_route(base_url: str, route: solara.Route, build_path: Path, thread
140
149
  return results
141
150
 
142
151
 
143
- def ssg_data(path: str) -> Optional[SSGData]:
152
+ def ssg_content(path: str) -> Optional[str]:
144
153
  license.check("SSG")
145
- html = ""
146
- # pre_rendered_css = ""
147
- styles = []
148
- title = "Solara ☀️"
149
154
  # still not sure why we sometimes end with a double slash
150
155
  if path.endswith("//"):
151
156
  path = path[:-2]
@@ -164,38 +169,46 @@ def ssg_data(path: str) -> Optional[SSGData]:
164
169
  html_path = html_path.with_suffix(".html")
165
170
  if html_path.exists() and html_path.is_file():
166
171
  logger.info("Using pre-rendered html at %r", html_path)
167
-
168
- from bs4 import BeautifulSoup, Tag
169
-
170
- soup = BeautifulSoup(html_path.read_text("utf8"), "html.parser")
171
- node = soup.find(id="app")
172
- # TODO: add classes...
173
- if node and isinstance(node, Tag):
174
- # only render children
175
- html = "".join(str(x) for x in node.contents)
176
- title_tag = soup.find("title")
177
- if title_tag:
178
- title = title_tag.text
179
-
180
- # include all meta tags
181
- rendered_metas = soup.find_all("meta")
182
- metas = []
183
- for meta in rendered_metas:
184
- # but only the ones added by solara
185
- if meta.attrs.get("data-solara-head-key"):
186
- metas.append(str(meta))
187
-
188
- # include all styles
189
- rendered_styles = soup.find_all("style")
190
- for style in rendered_styles:
191
- style_html = str(style)
192
- # in case we want to skip the mathjax css
193
- # if "MJXZERO" in style_html:
194
- # continue
195
- # pre_rendered_css += style_html
196
- styles.append(style_html)
197
- logger.debug("Include style (size is %r mb):\n\t%r", len(style_html) / 1024**2, style_html[:200])
198
- return SSGData(title=title, html=html, styles=styles, metas=metas)
172
+ return html_path.read_text("utf8")
199
173
  else:
200
174
  logger.error("Count not find html at %r", html_path)
201
175
  return None
176
+
177
+
178
+ def _ssg_data(html: str) -> Optional[SSGData]:
179
+ license.check("SSG")
180
+ from bs4 import BeautifulSoup, Tag
181
+
182
+ # pre_rendered_css = ""
183
+ styles = []
184
+ title = "Solara ☀️"
185
+
186
+ soup = BeautifulSoup(html, "html.parser")
187
+ node = soup.find(id="app")
188
+ # TODO: add classes...
189
+ if node and isinstance(node, Tag):
190
+ # only render children
191
+ html = "".join(str(x) for x in node.contents)
192
+ title_tag = soup.find("title")
193
+ if title_tag:
194
+ title = title_tag.text
195
+
196
+ # include all meta tags
197
+ rendered_metas = soup.find_all("meta")
198
+ metas = []
199
+ for meta in rendered_metas:
200
+ # but only the ones added by solara
201
+ if meta.attrs.get("data-solara-head-key"):
202
+ metas.append(str(meta))
203
+
204
+ # include all styles
205
+ rendered_styles = soup.find_all("style")
206
+ for style in rendered_styles:
207
+ style_html = str(style)
208
+ # in case we want to skip the mathjax css
209
+ # if "MJXZERO" in style_html:
210
+ # continue
211
+ # pre_rendered_css += style_html
212
+ styles.append(style_html)
213
+ logger.debug("Include style (size is %r mb):\n\t%r", len(style_html) / 1024**2, style_html[:200])
214
+ return SSGData(title=title, html=html, styles=styles, metas=metas)
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: solara-enterprise
3
- Version: 1.27.0
3
+ Version: 1.28.0
4
4
  Project-URL: Home, https://www.github.com/widgetti/solara
5
5
  Author-email: "Maarten A. Breddels" <maartenbreddels@gmail.com>, Mario Buikhuizen <mariobuikhuizen@gmail.com>
6
6
  License: Not open source, contact contact@solara.dev for licencing.
7
7
  License-File: LICENSE
8
8
  Classifier: License :: Free for non-commercial use
9
- Requires-Dist: solara==1.27.0
9
+ Requires-Dist: solara==1.28.0
10
10
  Provides-Extra: all
11
11
  Requires-Dist: solara-enterprise[auth]; extra == 'all'
12
12
  Requires-Dist: solara-enterprise[cache]; extra == 'all'
@@ -1,6 +1,6 @@
1
- solara_enterprise/__init__.py,sha256=muiG2xZwijeJnK1ek8nzTBxHsIbf-7W4KwygyOb-ALA,56
1
+ solara_enterprise/__init__.py,sha256=NWlXg-v592B1ymG8jxiCxmHlyV0g3jyq2JiWCkdXH4Y,56
2
2
  solara_enterprise/license.py,sha256=GCGEs3x9rtKf0dYUcHkx-yteIQuRlgnS8hPbl9BDAXs,412
3
- solara_enterprise/ssg.py,sha256=CfLh-ME5_6r5nWns_-JYIq_4YiqsiQyzZd1LO-PhI7M,7176
3
+ solara_enterprise/ssg.py,sha256=eV18QON_bHgJKmVGENG74DcHh8pz0P4oq0DwQYNX9CI,7437
4
4
  solara_enterprise/auth/__init__.py,sha256=83RGLIkVJrb6R1iZxg5YS0R3kaCmqMHu4qs8S74LJXo,513
5
5
  solara_enterprise/auth/components.py,sha256=AnxtSkziYDdNssx8Cjr09QMtDdEqWpuI12w36Yv4JAk,4010
6
6
  solara_enterprise/auth/flask.py,sha256=Y__abnQPnP1cdQAkU8BBg9FuWMZ1rNnUmTLE_x19MlE,3539
@@ -17,7 +17,7 @@ solara_enterprise/search/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
17
17
  solara_enterprise/search/index.py,sha256=iBdvVyM_v7UGPlwBnPwWIBMLhy3ezFSTBvzmeb7SKW4,3307
18
18
  solara_enterprise/search/search.py,sha256=rnVHP81AwL0GR8s5vnNU6rpEIqCVnZSgwfFfCuoibCQ,467
19
19
  solara_enterprise/search/search.vue,sha256=Aoyp9XPK9dDlKCymJqAtT6eoTsEoAOIe6zXiJYup5f4,6127
20
- solara_enterprise-1.27.0.dist-info/METADATA,sha256=SFhVYCsUOoI5xqjfOTLs-HIPRXIb7kUexLiEHQBtKh8,932
21
- solara_enterprise-1.27.0.dist-info/WHEEL,sha256=ccEkY-EGGllEs7ySpwBlD8G4u70wR77CNej8Q6tzIqA,105
22
- solara_enterprise-1.27.0.dist-info/licenses/LICENSE,sha256=04_xbTWtvdcQomu6IXsIkniKk8EcD9P1GyJM2dYPoSU,59
23
- solara_enterprise-1.27.0.dist-info/RECORD,,
20
+ solara_enterprise-1.28.0.dist-info/METADATA,sha256=_pqvMngesg0KamQeyMP7mu4bd-7SBebRpFnzTOztBa0,932
21
+ solara_enterprise-1.28.0.dist-info/WHEEL,sha256=ccEkY-EGGllEs7ySpwBlD8G4u70wR77CNej8Q6tzIqA,105
22
+ solara_enterprise-1.28.0.dist-info/licenses/LICENSE,sha256=04_xbTWtvdcQomu6IXsIkniKk8EcD9P1GyJM2dYPoSU,59
23
+ solara_enterprise-1.28.0.dist-info/RECORD,,