Skip to content

Commit

Permalink
Merge branch 'main' into machow-feat-narwhals
Browse files Browse the repository at this point in the history
* main:
  CI(deploy): Add more installation configs to surface failure cause (posit-dev#1658)
  `Chat.messages()` no longer trims messages by default (posit-dev#1657)
  tests(controllers): Split _controls.py into separate files (posit-dev#1652)
  Chat tweaks (posit-dev#1607)
  docs: Add modal_show/remove examples (posit-dev#1628)
  Delay sending of chat UI messages until reactive graph is flushed (posit-dev#1593)
  ci(remove future behavior warning): Set the `asyncio_default_fixture_loop_scope` to `fixture` (posit-dev#1655)
  bug: Verify mypy can run on CI (posit-dev#1650)
  Fix CI install failures on Windows (posit-dev#1651)
  Quartodoc 0.7.6 (posit-dev#1636)
  Allow `@chat.transform_assistant_response` function to return `None` (posit-dev#1641)
  feat: Support templates with `_template.json` metadata (posit-dev#1631)
  Fix KeyError when serving static files (posit-dev#1648)
  tests(navsets): Add navsets kitchensink tests (posit-dev#1602)
  Change default claude model to 3.5 sonnet
  • Loading branch information
schloerke committed Aug 30, 2024
2 parents db83bc7 + 24013f4 commit 1155868
Show file tree
Hide file tree
Showing 172 changed files with 9,232 additions and 8,044 deletions.
99 changes: 84 additions & 15 deletions .github/workflows/deploy-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,63 @@ jobs:
playwright-deploys:
# Only allow one `playwright-deploys` job to run at a time. (Independent of branch / PR)
# Only one is allowed to run at a time because it is deploying to the same server location.
concurrency: playwright-deploys
concurrency: playwright-deploys-${{ matrix.config.name }}
runs-on: ${{ matrix.os }}
name: ${{ matrix.config.name }}
strategy:
matrix:
# Matches deploy server python version
python-version: ["3.10"]
os: [ubuntu-latest]
config:
# Released server, shiny, and rsconnect
- name: "pypi-shiny-rsconnect-connect"
released_connect_server: true
pypi_shiny: true
pypi_rsconnect: true
base_test_dir: "./tests/playwright/deploys/express-page_sidebar"
app_name: "pypi-shiny-rsconnect"
test_shinyappsio: false

# Released shiny and rsconnect
# Dev server
- name: "pypi-shiny-rsconnect-dogfood"
released_connect_server: false
pypi_shiny: true
pypi_rsconnect: true
base_test_dir: "./tests/playwright/deploys/express-page_sidebar"
app_name: "pypi-shiny-rsconnect"
test_shinyappsio: false

# Released shiny
# Dogfood server and rsconnect
- name: "pypi-shiny-dev-rsconnect-dogfood"
released_connect_server: false
pypi_shiny: true
pypi_rsconnect: false
base_test_dir: "./tests/playwright/deploys/express-page_sidebar"
app_name: "pypi-shiny-dev-rsconnect"
test_shinyappsio: false

# GitHub shiny v1.0.0 - test if github packages can be installed
# Dogfood server and rsconnect
- name: "github-shiny-dev-rsconnect-dogfood"
released_connect_server: false
github_shiny: true
pypi_shiny: false
pypi_rsconnect: false
base_test_dir: "./tests/playwright/deploys/express-page_sidebar"
app_name: "pypi-shiny-dev-rsconnect"
test_shinyappsio: false

# Dev server, shiny, and rsconnect
- name: "dev-shiny-rsconnect-dogfood"
released_connect_server: false
pypi_shiny: false
pypi_rsconnect: false
base_test_dir: "./tests/playwright/deploys"
test_shinyappsio: true

fail-fast: false

steps:
Expand All @@ -27,7 +77,24 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install rsconnect
- name: Install pypi shiny and htmltools (uninstall GitHub versions)
if: ${{ matrix.config.pypi_shiny }}
run: |
uv pip uninstall shiny htmltools
uv pip install shiny htmltools
- name: Install GitHub [email protected] and [email protected] (uninstall PyPI versions)
if: ${{ matrix.config.github_shiny }}
run: |
uv pip uninstall shiny htmltools
uv pip install "htmltools @ git+https://github.com/posit-dev/[email protected]" "shiny @ git+https://github.com/posit-dev/[email protected]"
- name: Install rsconnect (PyPI)
if: ${{ matrix.config.pypi_rsconnect }}
run: |
uv pip install rsconnect
- name: Install rsconnect (GitHub)
if: ${{ ! matrix.config.pypi_rsconnect }}
run: |
make ci-install-rsconnect
Expand All @@ -36,25 +103,27 @@ jobs:
env:
DEPLOY_APPS: "false"
run: |
make playwright-deploys SUB_FILE=". -vv"
make playwright-deploys TEST_FILE="${{ matrix.config.base_test_dir }} -vv"
- name: Deploy apps and run tests (on `push` or `deploy**` branches)
env:
DEPLOY_APPS: "true"
DEPLOY_CONNECT_SERVER_URL: "https://rsc.radixu.com/"
DEPLOY_CONNECT_SERVER_API_KEY: "${{ secrets.DEPLOY_CONNECT_SERVER_API_KEY }}"
DEPLOY_SHINYAPPS_NAME: "${{ secrets.DEPLOY_SHINYAPPS_NAME }}"
DEPLOY_SHINYAPPS_TOKEN: "${{ secrets.DEPLOY_SHINYAPPS_TOKEN }}"
DEPLOY_SHINYAPPS_SECRET: "${{ secrets.DEPLOY_SHINYAPPS_SECRET }}"
DEPLOY_CONNECT_SERVER_URL: "${{ (matrix.config.released_connect_server && 'https://connect.posit.it/') || 'https://rsc.radixu.com/' }}"
DEPLOY_CONNECT_SERVER_API_KEY: "${{ (matrix.config.released_connect_server && secrets.DEPLOY_CONNECT_POSIT_SERVER_API_KEY) || secrets.DEPLOY_CONNECT_SERVER_API_KEY }}"
DEPLOY_SHINYAPPS_NAME: "${{ matrix.config.test_shinyappsio && matrix.config.shinyapps_name }}"
DEPLOY_SHINYAPPS_TOKEN: "${{ matrix.config.test_shinyappsio && matrix.config.shinyapps_token }}"
DEPLOY_SHINYAPPS_SECRET: "${{ matrix.config.test_shinyappsio && matrix.config.shinyapps_secret }}"
EXPRESS_PAGE_SIDEBAR_NAME: "${{ matrix.config.app_name }}"
DEPLOY_GITHUB_REQUIREMENTS_TXT: "${{ !matrix.config.pypi_shiny }}"
timeout-minutes: 30
# Given we are waiting for external servers to finish,
# we can have many local processes waiting for deployment to finish
run: |
make playwright-deploys SUB_FILE=". -vv --numprocesses 12"
make playwright-deploys TEST_FILE="${{ matrix.config.base_test_dir }} -vv --numprocesses 12"
- uses: actions/upload-artifact@v4
if: failure()
with:
name: "playright-deploys-${{ matrix.os }}-${{ matrix.python-version }}-results"
path: test-results/
retention-days: 5
# - uses: actions/upload-artifact@v4
# if: failure()
# with:
# name: "playright-deploys-${{ matrix.os }}-${{ matrix.python-version }}-results"
# path: test-results/
# retention-days: 5
5 changes: 5 additions & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ jobs:
run: |
make check-format
- name: Verify code can run with mypy (not Windows)
if: steps.install.outcome == 'success' && (success() || failure()) && matrix.os != 'windows-latest'
run: |
make ci-check-mypy-can-run
pypi:
name: "Deploy to PyPI"
runs-on: ubuntu-latest
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* `shiny create` now supports a succinct format for specifying the GitHub repository via the `--github` flag, e.g. `--github posit-dev/py-shiny-templates`. You can now also use `--github` and `--template` together, in which case `--github` should point to a repository containing a directory matching the name provided in `--template`. (#1623)

* `shiny create` now identifies templates in external repositories using a `_template.json` metadata file. This file should contain at an `"id"` and optionally a `"title"` and `"description"`. When `shiny create` is called with the `--github` flag but without a `--template` flag, it will offer a menu listing all available templates in the repository. (#1631)

### Other changes

* A few changes for `ui.Chat()`, including:
* The `.messages()` method no longer trims messages by default (i.e., the default value of `token_limits` is now `None` instead of the overly generic and conservative value of `(4096, 1000)`). See the new generative AI in production templates (via `shiny create`) for examples of setting `token_limits` based on the model being used. (#1657)
* User input that contains markdown now renders the expected HTML. (#1607)
* Busy indication is now visible/apparent during the entire lifecycle of response generation. (#1607)

### Bug fixes

* A handful of fixes for `ui.Chat()`, including:
* A few fixes for `ui.Chat()`, including:
* A fix for use inside Shiny modules. (#1582)
* `.messages(format="google")` now returns the correct role. (#1622)
* `ui.Chat(messages)` are no longer dropped when dynamically rendered. (#1593)
* `transform_assistant_response` can now return `None` and correctly handles change of content on the last chunk. (#1641)

* An empty `ui.input_date()` value no longer crashes Shiny. (#1528)

Expand All @@ -33,6 +42,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Some copies of Windows 10 have registry entries mapping .js files to content type "text/plain", which was causing all sorts of problems for browsers. (#1624)

* Added missing support for `express.ui.navset_card_pill(placement:)`. (#1602)

* Added `.expect_sidebar()` and `.expect_title()` methods for `NavsetCardTab`, `NavsetCardPill`, `NavsetCardUnderline`, and `NavsetBar`. (#1602)

* Added `.expect_placement()` method for `NavsetCardPill` and `NavsetCardUnderline`. (#1602)

### Deprecations

## [1.0.0] - 2024-07-18
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ clean-build: FORCE
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
find . -name '*.egg' -exec rm -rf {} +

# Remove Python file artifacts
clean-pyc: FORCE
Expand Down Expand Up @@ -173,6 +173,8 @@ playwright-shiny: FORCE

# end-to-end tests on deployed apps with playwright; (SUB_FILE="" within tests/playwright/deploys/)
playwright-deploys: FORCE
$(MAKE) playwright PYTEST_BROWSERS="$(PYTEST_DEPLOYS_BROWSERS)" TEST_FILE="$(TEST_FILE)"
playwright-deploys-legacy: FORCE
$(MAKE) playwright TEST_FILE="tests/playwright/deploys/$(SUB_FILE)" PYTEST_BROWSERS="$(PYTEST_DEPLOYS_BROWSERS)"

# end-to-end tests on all py-shiny examples with playwright; (SUB_FILE="" within tests/playwright/examples/)
Expand Down Expand Up @@ -225,6 +227,14 @@ ci-install-rsconnect: FORCE
uv pip install "rsconnect-python @ git+https://github.com/rstudio/rsconnect-python.git"


# This is just to check if mypy can run for other users.
# Not added to `make check` or `make check-fix` as all lint errors are supporessed (as we use pyright).
ci-check-mypy-can-run: FORCE
@echo "-------- Checking types with mypy -----------"
uv pip install mypy
mypy shiny


# ## If caching is ever used, we could run:
# install-deps: FORCE ## install latest dependencies
# pip install --editable ".[dev,test]" --upgrade --upgrade-strategy eager
Expand Down
2 changes: 1 addition & 1 deletion docs/_quartodoc-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ quartodoc:
- title: Navigation (tab) panels
desc: Methods for interacting with Shiny app UI content controller.
contents:
- playwright.controller.NavPanel
- playwright.controller.NavsetBar
- playwright.controller.NavsetCardPill
- playwright.controller.NavsetCardTab
Expand All @@ -58,6 +57,7 @@ quartodoc:
- playwright.controller.NavsetPillList
- playwright.controller.NavsetTab
- playwright.controller.NavsetUnderline
- playwright.controller.NavPanel
- title: Upload and download
desc: Methods for interacting with Shiny app uploading and downloading controller.
contents:
Expand Down
38 changes: 23 additions & 15 deletions docs/_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
from typing import Literal, Optional, TypedDict, Union

import quartodoc.ast as qast
from griffe import dataclasses as dc
from griffe import expressions as exp
from griffe.docstrings import dataclasses as ds
from griffe import (
Alias,
DocstringAttribute,
DocstringParameter,
DocstringSectionParameters,
DocstringSectionText,
Expr,
ExprName,
Function,
Object,
)
from plum import dispatch
from quartodoc import MdRenderer
from quartodoc.pandoc.blocks import DefinitionList
Expand Down Expand Up @@ -42,7 +50,7 @@ def render(self, el: qast.DocstringSectionSeeAlso):
return prefix_bare_functions_with_func(el.value)

@dispatch
def render(self, el: Union[dc.Object, dc.Alias]):
def render(self, el: Union[Object, Alias]):
# If `el` is a protocol class that only has a `__call__` method,
# then we want to display information about the method, not the class.
if len(el.members) == 1 and "__call__" in el.members.keys():
Expand Down Expand Up @@ -78,7 +86,7 @@ def render(self, el: Union[dc.Object, dc.Alias]):
return converted

@dispatch
def render(self, el: ds.DocstringSectionText):
def render(self, el: DocstringSectionText):
# functions like shiny.ui.tags.b have html in their docstrings, so
# we escape them. Note that we are only escaping text sections, but
# since these cover the top text of the docstring, it should solve
Expand All @@ -93,7 +101,7 @@ def render_annotation(self, el: str):
# TODO-future; Can be removed once we use quartodoc 0.3.5
# Related: https://github.com/machow/quartodoc/pull/205
@dispatch
def render(self, el: ds.DocstringAttribute):
def render(self, el: DocstringAttribute):
row = [
sanitize(el.name),
self.render_annotation(el.annotation),
Expand All @@ -106,23 +114,23 @@ def render_annotation(self, el: None):
return ""

@dispatch
def render_annotation(self, el: exp.Expr):
# an expression is essentially a list[exp.ExprName | str]
def render_annotation(self, el: Expr):
# an expression is essentially a list[ExprName | str]
# e.g. Optional[TagList]
# -> [Name(source="Optional", ...), "[", Name(...), "]"]

return "".join(map(self.render_annotation, el))

@dispatch
def render_annotation(self, el: exp.ExprName):
def render_annotation(self, el: ExprName):
# e.g. Name(source="Optional", full="typing.Optional")
return f"[{el.name}](`{el.canonical_path}`)"

@dispatch
# Overload of `quartodoc.renderers.md_renderer` to fix bug where the descriptions
# are cut off and never display other places. Fixing by always displaying the
# documentation.
def summarize(self, obj: Union[dc.Object, dc.Alias]) -> str:
def summarize(self, obj: Union[Object, Alias]) -> str:
# get high-level description
doc = obj.docstring
if doc is None:
Expand All @@ -131,7 +139,7 @@ def summarize(self, obj: Union[dc.Object, dc.Alias]) -> str:
docstring_parts = doc.parsed

if len(docstring_parts) and isinstance(
docstring_parts[0], ds.DocstringSectionText
docstring_parts[0], DocstringSectionText
):
description = docstring_parts[0].value

Expand Down Expand Up @@ -164,7 +172,7 @@ def summarize(self, obj: Union[dc.Object, dc.Alias]) -> str:

# Consolidate the parameter type info into a single column
@dispatch
def render(self, el: ds.DocstringParameter):
def render(self, el: DocstringParameter):
param = f'<span class="parameter-name">{el.name}</span>'
annotation = self.render_annotation(el.annotation)
if annotation:
Expand All @@ -178,14 +186,14 @@ def render(self, el: ds.DocstringParameter):
return (param, el.description)

@dispatch
def render(self, el: ds.DocstringSectionParameters):
def render(self, el: DocstringSectionParameters):
rows = list(map(self.render, el.value))
# rows is a list of tuples of (<parameter>, <description>)

return str(DefinitionList(rows))

@dispatch
def signature(self, el: dc.Function, source: Optional[dc.Alias] = None):
def signature(self, el: Function, source: Optional[Alias] = None):
if el.name == "__call__":
# Ex: experimental.ui._card.ImgContainer.__call__(self, *args: Tag) -> Tagifiable
sig = super().signature(el, source)
Expand Down Expand Up @@ -302,7 +310,7 @@ def is_no_ex_decorator(x):
# Don't throw for things that can't be decorated
return

if not el.is_explicitely_exported:
if not el.is_exported:
# Don't require examples on "implicitly exported" functions
# In practice, this covers methods of exported classes (class still needs ex)
return
Expand Down
2 changes: 1 addition & 1 deletion examples/chat/hello-providers/anthropic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def _():
messages = chat.messages(format="anthropic")
# Create a response message stream
response = await llm.messages.create(
model="claude-3-opus-20240229",
model="claude-3-5-sonnet-20240620",
messages=messages,
stream=True,
max_tokens=1000,
Expand Down
2 changes: 1 addition & 1 deletion examples/chat/playground/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"openai": ["gpt-4o", "gpt-3.5-turbo"],
"claude": [
"claude-3-opus-20240229",
"claude-3-sonnet-20240229",
"claude-3-5-sonnet-20240620",
"claude-3-haiku-20240307",
],
"google": ["gemini-1.5-pro-latest"],
Expand Down
2 changes: 1 addition & 1 deletion js/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16
v18
Loading

0 comments on commit 1155868

Please sign in to comment.