Skip to content

Commit b49ddfc

Browse files
authored
Merge branch 'master' into mypy-fastapi
2 parents df87cbd + 6d86d37 commit b49ddfc

File tree

26 files changed

+252
-399
lines changed

26 files changed

+252
-399
lines changed

.vscode/launch.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "Python: Attach",
8+
"name": "OL: Attach to Web Container",
99
"type": "debugpy",
1010
"request": "attach",
1111
"connect": {
@@ -18,6 +18,21 @@
1818
"remoteRoot": "/openlibrary/"
1919
}
2020
]
21+
},
22+
{
23+
"name": "OL: Attach to FastAPI Container",
24+
"type": "debugpy",
25+
"request": "attach",
26+
"connect": {
27+
"host": "localhost",
28+
"port": 3001
29+
},
30+
"pathMappings": [
31+
{
32+
"localRoot": "${workspaceFolder}",
33+
"remoteRoot": "/openlibrary/"
34+
}
35+
]
2136
}
2237
]
2338
}

bundlesize.config.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
"path": "static/build/js/add-book.*.js",
2525
"maxSize": "4KB"
2626
},
27-
{
28-
"path": "static/build/js/readmore.*.js",
29-
"maxSize": "3KB"
30-
},
3127
{
3228
"path": "static/build/js/modal-links.*.js",
3329
"maxSize": "7KB"

compose.override.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
dockerfile: docker/Dockerfile.oldev
1010
ports:
1111
# Debugger
12-
- 3000:3000
12+
- 127.0.0.1:3000:3000
1313
volumes:
1414
# Persistent volume mount for installed git submodules
1515
- ol-vendor:/openlibrary/vendor
@@ -30,6 +30,9 @@ services:
3030
build:
3131
context: .
3232
dockerfile: docker/Dockerfile.oldev
33+
ports:
34+
# Debugger
35+
- 127.0.0.1:3001:3000
3336
volumes:
3437
- .:/openlibrary
3538
environment:

compose.production.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ services:
337337
# This job runs various monitoring/grafana checks across the entire cluster.
338338
# It has access to the other nodes via the docker socket.
339339
monitoring:
340-
profiles: ["ol-web0", "ol-web1", "ol-web2", "ol-covers0", "ol-www0", "ol-solr0", "ol-solr1"]
340+
profiles: ["ol-web0", "ol-web1", "ol-web2", "ol-covers0", "ol-www0", "ol-solr0", "ol-solr1", "ol-home0"]
341341
build:
342342
context: .
343343
dockerfile: scripts/monitoring/Dockerfile

compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020
image: "${OLIMAGE:-oldev:latest}"
2121
environment:
2222
- OL_CONFIG=${OL_CONFIG:-/openlibrary/conf/openlibrary.yml}
23-
- GUNICORN_OPTS=${GUNICORN_OPTS:- --reload --workers 2 --timeout 180 --max-requests 500}
23+
- GUNICORN_OPTS=${GUNICORN_OPTS:- --reload --workers 1 --timeout 180 --max-requests 500}
2424
command: docker/ol-web-fastapi-start.sh
2525
ports:
2626
- ${FAST_WEB_PORT:-18080}:8080

openlibrary/asgi_app.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import re
66
import sys
7+
from contextlib import asynccontextmanager
78
from pathlib import Path
89

910
import yaml
@@ -115,8 +116,28 @@ async def i18n_middleware(request: Request, call_next):
115116
return response
116117

117118

119+
def setup_debugpy():
120+
import debugpy # noqa: T100
121+
122+
# Start listening for debugger connections
123+
debugpy.listen(('0.0.0.0', 3000)) # noqa: T100
124+
logger.info(
125+
"🐛 Debugger ready to attach from VS Code! Select 'OL: Attach to FastAPI Container'."
126+
)
127+
128+
118129
sentry: Sentry | None = None
119130

131+
132+
@asynccontextmanager
133+
async def lifespan(app: FastAPI):
134+
"""Lifespan context manager for startup and shutdown events."""
135+
# Startup
136+
if os.environ.get("LOCAL_DEV", "false").lower() == "true":
137+
setup_debugpy()
138+
yield
139+
# Shutdown (if needed in the future)
140+
120141

121142
def create_app() -> FastAPI | None:
122143
if "pytest" not in sys.modules:
@@ -141,7 +162,12 @@ def create_app() -> FastAPI | None:
141162
logger.exception("Failed to initialize legacy WSGI app")
142163
raise
143164

144-
app = FastAPI(title="OpenLibrary ASGI", version="0.0.1")
165+
app = FastAPI(
166+
title="OpenLibrary ASGI",
167+
version="0.0.1",
168+
debug=os.environ.get("LOCAL_DEV", "false").lower() == "true",
169+
lifespan=lifespan,
170+
)
145171

146172
app.add_middleware(
147173
CORSMiddleware,
@@ -178,11 +204,11 @@ async def set_context(request: Request, call_next):
178204
def health() -> dict[str, str]:
179205
return {"status": "ok"}
180206

181-
from openlibrary.fastapi.account import router as account_router # type: ignore
182-
from openlibrary.fastapi.languages import router as languages_router # type: ignore
183-
from openlibrary.fastapi.publishers import router as publishers_router # type: ignore
184-
from openlibrary.fastapi.search import router as search_router # type: ignore
185-
from openlibrary.fastapi.subjects import router as subjects_router # type: ignore
207+
from openlibrary.fastapi.account import router as account_router
208+
from openlibrary.fastapi.languages import router as languages_router
209+
from openlibrary.fastapi.publishers import router as publishers_router
210+
from openlibrary.fastapi.search import router as search_router
211+
from openlibrary.fastapi.subjects import router as subjects_router
186212

187213
# Include routers
188214
app.include_router(languages_router)

openlibrary/components/lit/OLReadMore.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import { LitElement, html, css } from 'lit';
77
* - Height-based: Use `max-height` attribute (e.g., "81px")
88
* - Line-based: Use `max-lines` attribute (e.g., "4")
99
*
10+
* @property {String} background-color - Background color for the gradient fade (default: white)
11+
* @property {String} label-size - Size of the toggle button text: "medium" (default) or "small" (12px)
12+
* @property {String} padding-left - Left padding for toggle button on non-mobile (e.g., "8" or "8px")
13+
*
1014
* @example
1115
* <ol-read-more max-height="100px" more-text="Read more" less-text="Read less">
1216
* <p>Long content here...</p>
1317
* </ol-read-more>
1418
*
1519
* @example
16-
* <ol-read-more max-lines="4">
20+
* <ol-read-more max-lines="4" background-color="#f5f5f5" label-size="small">
1721
* <p>Long content here...</p>
1822
* </ol-read-more>
1923
*/
@@ -23,6 +27,9 @@ export class OLReadMore extends LitElement {
2327
maxLines: { type: Number, attribute: 'max-lines' },
2428
moreText: { type: String, attribute: 'more-text' },
2529
lessText: { type: String, attribute: 'less-text' },
30+
backgroundColor: { type: String, attribute: 'background-color' },
31+
labelSize: { type: String, attribute: 'label-size' },
32+
paddingLeft: { type: String, attribute: 'padding-left' },
2633
// Internal state
2734
_expanded: { type: Boolean, state: true },
2835
_unnecessary: { type: Boolean, state: true },
@@ -35,6 +42,7 @@ export class OLReadMore extends LitElement {
3542
--ol-readmore-link-color: hsl(202, 96%, 28%);
3643
--ol-readmore-gradient-color: white;
3744
--ol-readmore-gradient-color-transparent: rgba(255, 255, 255, 0);
45+
--ol-readmore-padding-left: 0;
3846
}
3947
4048
.content-wrapper {
@@ -68,6 +76,7 @@ export class OLReadMore extends LitElement {
6876
var(--ol-readmore-gradient-color) 12px
6977
);
7078
border: none;
79+
border-radius: 0 0 4px 4px;
7180
cursor: pointer;
7281
}
7382
@@ -85,7 +94,7 @@ export class OLReadMore extends LitElement {
8594
8695
@media only screen and (min-width: 800px) {
8796
.toggle-btn {
88-
padding-left: 0;
97+
padding-left: var(--ol-readmore-padding-left);
8998
text-align: left;
9099
}
91100
}
@@ -105,6 +114,12 @@ export class OLReadMore extends LitElement {
105114
.chevron.up {
106115
transform: rotate(180deg);
107116
}
117+
118+
.toggle-btn.small {
119+
font-size: 12px;
120+
padding-top: 16px;
121+
padding-bottom: 8px;
122+
}
108123
`;
109124

110125
constructor() {
@@ -113,12 +128,39 @@ export class OLReadMore extends LitElement {
113128
this.maxLines = null;
114129
this.moreText = 'Read More';
115130
this.lessText = 'Read Less';
131+
this.backgroundColor = null;
132+
this.labelSize = 'medium';
133+
this.paddingLeft = null;
116134
this._expanded = false;
117135
this._unnecessary = false;
118136
}
119137

120138
firstUpdated() {
121139
this._checkIfTruncationNeeded();
140+
this._updateBackgroundColor();
141+
this._updatePaddingLeft();
142+
}
143+
144+
updated(changedProperties) {
145+
if (changedProperties.has('backgroundColor')) {
146+
this._updateBackgroundColor();
147+
}
148+
if (changedProperties.has('paddingLeft')) {
149+
this._updatePaddingLeft();
150+
}
151+
}
152+
153+
_updateBackgroundColor() {
154+
if (this.backgroundColor) {
155+
this.style.setProperty('--ol-readmore-gradient-color', this.backgroundColor);
156+
}
157+
}
158+
159+
_updatePaddingLeft() {
160+
if (this.paddingLeft) {
161+
const value = /^\d+$/.test(this.paddingLeft) ? `${this.paddingLeft}px` : this.paddingLeft;
162+
this.style.setProperty('--ol-readmore-padding-left', value);
163+
}
122164
}
123165

124166
_checkIfTruncationNeeded() {
@@ -171,6 +213,7 @@ export class OLReadMore extends LitElement {
171213
render() {
172214
const showMoreBtn = !this._expanded && !this._unnecessary;
173215
const showLessBtn = this._expanded && !this._unnecessary;
216+
const sizeClass = this.labelSize === 'small' ? 'small' : '';
174217

175218
return html`
176219
<div
@@ -180,15 +223,15 @@ export class OLReadMore extends LitElement {
180223
<slot></slot>
181224
</div>
182225
<button
183-
class="toggle-btn more ${showMoreBtn ? '' : 'hidden'}"
226+
class="toggle-btn more ${sizeClass} ${showMoreBtn ? '' : 'hidden'}"
184227
aria-expanded="false"
185228
@click="${this._handleMoreClick}"
186229
>
187230
${this.moreText}
188231
<svg class="chevron" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>
189232
</button>
190233
<button
191-
class="toggle-btn less ${showLessBtn ? '' : 'hidden'}"
234+
class="toggle-btn less ${sizeClass} ${showLessBtn ? '' : 'hidden'}"
192235
aria-expanded="true"
193236
@click="${this._handleLessClick}"
194237
>

openlibrary/core/edits.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,6 @@ def update_submitter_name(cls, submitter: str, new_username: str, _test=False):
170170
t.rollback() if _test else t.commit()
171171
return rows_changed
172172

173-
@classmethod
174-
def submit_delete_request(cls, olid, submitter, comment=None):
175-
if not comment:
176-
# some default note from submitter
177-
pass
178-
url = f"{olid}/-/edit?m=delete"
179-
cls.submit_request(cls, url, submitter=submitter, comment=comment)
180-
181173
@classmethod
182174
def submit_request(
183175
cls,

openlibrary/i18n/messages.pot

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,6 @@ msgstr ""
618618
msgid "Listen"
619619
msgstr ""
620620

621-
#: ReadMore.html
622-
msgid "Read more"
623-
msgstr ""
624-
625-
#: ReadMore.html
626-
msgid "Read less"
627-
msgstr ""
628-
629621
#: RecentChanges.html RecentChangesAdmin.html RecentChangesUsers.html
630622
#: admin/ip/view.html admin/people/edits.html history.html
631623
#: recentchanges/render.html recentchanges/updated_records.html

openlibrary/macros/ReadMore.html

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)