Skip to content

Commit dc0761b

Browse files
authored
chore(uvicorn): Remove PR source of uvicorn (#1950)
1 parent ca671cd commit dc0761b

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ doc = [
134134
"griffe>=1.3.2",
135135
]
136136

137-
[tool.uv.sources]
138-
# https://github.com/encode/uvicorn/pull/2602
139-
uvicorn = { git = "https://github.com/schloerke/uvicorn", branch = "reload-exclude-abs-path" }
140137

141138
[project.urls]
142139
Homepage = "https://github.com/posit-dev/py-shiny"

shiny/_main.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,32 @@ def run_app(
359359

360360
reload_args: ReloadArgs = {}
361361
if reload:
362+
if shiny_bookmarks_folder_name in reload_excludes:
363+
# Related: https://github.com/posit-dev/py-shiny/pull/1950
364+
#
365+
# Temp hack to work around uvicorn
366+
# https://github.com/encode/uvicorn/pull/2602 which will incorrectly reload
367+
# an app if any matching files in `RELOAD_INCLUDES_DEFAULT` (e.g. `*.png`)
368+
# are uploaded within `shiny_bookmarks` (an excluded relative directory).
369+
#
370+
# By extending `reload_excludes` to ignore everything under the bookmarks folder, we
371+
# can prevent the unexpected reload from happening for the root session. File
372+
# matches are performed via `pathlib.PurePath.match`, which is a right-match and
373+
# only supports `*` glob.
374+
#
375+
# Ignore up to five modules deep. This should cover most cases.
376+
#
377+
# Note: file uploads are always in the root session, so they are always
378+
# stored in the root bookmark dir of `shiny_bookmarks_folder_name / *`.
379+
reload_excludes = [
380+
*reload_excludes,
381+
str(Path(shiny_bookmarks_folder_name) / "*"),
382+
str(Path(shiny_bookmarks_folder_name) / "*" / "*"),
383+
str(Path(shiny_bookmarks_folder_name) / "*" / "*" / "*"),
384+
str(Path(shiny_bookmarks_folder_name) / "*" / "*" / "*" / "*"),
385+
str(Path(shiny_bookmarks_folder_name) / "*" / "*" / "*" / "*" / "*"),
386+
]
387+
362388
reload_args = {
363389
"reload": reload,
364390
# Adding `reload_includes` param while `reload=False` produces an warning

shiny/api-examples/notification_show/app-core.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def server(input: Inputs, output: Outputs, session: Session):
1414
@reactive.effect
1515
@reactive.event(input.show)
1616
def _():
17-
nonlocal ids
1817
nonlocal n
1918
# Save the ID for removal later
2019
id = ui.notification_show("Message " + str(n), duration=None)
@@ -24,7 +23,6 @@ def _():
2423
@reactive.effect
2524
@reactive.event(input.remove)
2625
def _():
27-
nonlocal ids
2826
if ids:
2927
ui.notification_remove(ids.pop())
3028

shiny/api-examples/notification_show/app-express.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
@reactive.effect
1212
@reactive.event(input.show)
1313
def _():
14-
global ids
1514
global n
1615
# Save the ID for removal later
1716
id = ui.notification_show("Message " + str(n), duration=None)
@@ -22,6 +21,5 @@ def _():
2221
@reactive.effect
2322
@reactive.event(input.remove)
2423
def _():
25-
global ids
2624
if ids:
2725
ui.notification_remove(ids.pop())

shiny/bookmark/_bookmark.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ async def _scoped_on_bookmark(self, root_state: BookmarkState) -> None:
610610
)
611611

612612
# Make subdir for scope
613-
# TODO: Barret; Is this for uploaded files?!?
613+
#
614+
# Folder only used by author callbacks. File uploads are handled by root session
614615
if root_state.dir is not None:
615616
scope_subpath = self._ns
616617
scoped_state.dir = Path(root_state.dir) / scope_subpath

tests/pytest/test_reactives.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,13 @@ async def test_async_sequential():
235235
async def react_chain(n: int):
236236
@calc()
237237
async def r():
238-
nonlocal exec_order
239238
exec_order.append(f"r{n}-1")
240239
await asyncio.sleep(0)
241240
exec_order.append(f"r{n}-2")
242241
return x() + 10
243242

244243
@effect()
245244
async def _():
246-
nonlocal exec_order
247245
exec_order.append(f"o{n}-1")
248246
await asyncio.sleep(0)
249247
exec_order.append(f"o{n}-2")
@@ -402,19 +400,16 @@ async def test_effect_priority():
402400

403401
@effect(priority=1)
404402
def o1():
405-
nonlocal results
406403
v()
407404
results.append(1)
408405

409406
@effect(priority=2)
410407
def o2():
411-
nonlocal results
412408
v()
413409
results.append(2)
414410

415411
@effect(priority=1)
416412
def o3():
417-
nonlocal results
418413
v()
419414
results.append(3)
420415

@@ -425,7 +420,6 @@ def o3():
425420
# invalidate others by changing v).
426421
@effect(priority=2)
427422
def o4():
428-
nonlocal results
429423
v()
430424
results.append(4)
431425

@@ -453,19 +447,16 @@ async def test_async_effect_priority():
453447

454448
@effect(priority=1)
455449
async def o1():
456-
nonlocal results
457450
v()
458451
results.append(1)
459452

460453
@effect(priority=2)
461454
async def o2():
462-
nonlocal results
463455
v()
464456
results.append(2)
465457

466458
@effect(priority=1)
467459
async def o3():
468-
nonlocal results
469460
v()
470461
results.append(3)
471462

@@ -476,7 +467,6 @@ async def o3():
476467
# invalidate others by changing v).
477468
@effect(priority=2)
478469
async def o4():
479-
nonlocal results
480470
v()
481471
results.append(4)
482472

@@ -506,7 +496,6 @@ async def test_effect_destroy():
506496

507497
@effect()
508498
def o1():
509-
nonlocal results
510499
v()
511500
results.append(1)
512501

@@ -524,7 +513,6 @@ def o1():
524513

525514
@effect()
526515
def o2():
527-
nonlocal results
528516
v()
529517
results.append(1)
530518

0 commit comments

Comments
 (0)