Add --preview flag to snow streamlit deploy for personal-workspace deploys#3002
Draft
sfc-gh-svishnu wants to merge 1 commit into
Draft
Add --preview flag to snow streamlit deploy for personal-workspace deploys#3002sfc-gh-svishnu wants to merge 1 commit into
--preview flag to snow streamlit deploy for personal-workspace deploys#3002sfc-gh-svishnu wants to merge 1 commit into
Conversation
…ploys Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-review checklist
Changes description
Context
Streamlit developers iterating on a SiS app today have to deploy to a real database and stage in their account every time they want to preview a change. That requires picking a target DB/schema, owning a stage, and (for SPCS apps) uploading artifacts to a per-app versioned stage and running
ALTER STREAMLIT … ADD LIVE VERSION FROM LAST. For quick "is this change working?" iterations against the SPCS container runtime, that's heavier than it needs to be — and on accounts where the developer doesn't own a database it's outright blocking.This PR adds a
--previewflag tosnow streamlit deploythat targets the user's personal database (user$.public.<name>) and sources the app from the user's default workspace live version (snow://workspace/USER$.PUBLIC.DEFAULT$/versions/live). Local artifacts are still bundled fromsnowflake.ymland uploaded to a per-entity subfolder under the workspace; the streamlit object is created withCREATE_CODE_STAGE = FALSEandFROM '<workspace_uri>'. SPCS container runtime fields (RUNTIME_NAME,COMPUTE_POOL) are honored when present insnowflake.yml. NoADD LIVE VERSION, no separate stage to manage.What this enables
snow streamlit deploy --previewdeploys touser$.public.<name>, scoped to the current user. No need to choose or own a database.snow://workspace/USER$.PUBLIC.DEFAULT$/versions/live/<entity_id>/, and the streamlit reads from the workspace live URI (noALTER STREAMLIT … ADD LIVE VERSIONround-trip).runtime_name: SYSTEM$ST_CONTAINER_RUNTIME_PY3_11andcompute_pool: …are set insnowflake.yml, the emitted SQL includes the matchingRUNTIME_NAME/COMPUTE_POOLclauses. Warehouse-runtime previews drop those clauses but still emitCREATE_CODE_STAGE = FALSE.user$is a server-side alias resolved at SQL execution time; the CLI resolves it client-side viaSELECT 'USER$' || CURRENT_USER()so the Snowsight URL points atUSER$<USERNAME>.PUBLIC.<NAME>(not the literaluser%24).--pruneis rejected up-front (it would prune unrelated files), andforce_overwrite=Trueis scoped to the per-entity subfolder.grants:fromsnowflake.ymlare skipped with a console warning because they target the YAML FQN, not the preview FQN — applying them in preview mode would either fail or silently grant on a different streamlit object.--preview --legacyand--preview --pruneerror out withCliErrorbefore any work happens. Re-deploying without--replaceerrors with a clear "already exists" message.Sample emitted SQL
(Warehouse-runtime previews omit the
RUNTIME_NAME/COMPUTE_POOLlines.)How it works (user-facing flow)
snow streamlit deploy --preview(optionally with--replace) from a project withsnowflake.yml.--preview --legacyand--preview --prunebefore any project work.snowflake.yml(bundle()).user$.public.<name>already exists viaDESCRIBE STREAMLIT; without--replace, this aborts withClickException.snow://workspace/USER$.PUBLIC.DEFAULT$/versions/live/<entity_id>/.prune=Falseandforce_overwrite=Trueare forced to keep other workspace files untouched while still updating this preview's files.CREATE [OR REPLACE] STREAMLIT user$.public.<name> FROM '…/versions/live' …is executed (with SPCS clauses if applicable).grants:fromsnowflake.ymlare skipped with a console warning if present.Flow diagram
flowchart TD A["snow streamlit deploy --preview [--replace]"] --> B{"--preview --legacy<br/>or --preview --prune?"} B -- Yes --> Z[CliError: incompatible flags] B -- No --> C[v1 to v2 conversion if needed] C --> D["bundle() local artifacts"] D --> E["DESCRIBE STREAMLIT user$.public.<name>"] E --> F{Exists & no --replace?} F -- Yes --> Y[ClickException: already exists] F -- No --> G["sync_deploy_root_with_stage<br/>to .../versions/live/<entity_id>/<br/>(prune=False, force_overwrite=True)"] G --> H{SPCS runtime in yaml?} H -- Yes --> I["CREATE STREAMLIT ... FROM workspace<br/>+ RUNTIME_NAME + COMPUTE_POOL<br/>+ CREATE_CODE_STAGE = FALSE"] H -- No --> J["CREATE STREAMLIT ... FROM workspace<br/>+ CREATE_CODE_STAGE = FALSE"] I --> K{Has grants in yaml?} J --> K K -- Yes --> L["console.warning:<br/>Skipping grants in --preview mode"] K -- No --> M["StreamlitManager.grant_privileges()"] L --> N["Resolve personal DB:<br/>SELECT 'USER$' || CURRENT_USER()"] M --> N N --> O["Snowsight URL:<br/>USER$<USER>.PUBLIC.<NAME>"]Files added/modified
No new files; preview is layered onto the existing
_deploy_legacy/_deploy_versioneddispatch as a third sibling_deploy_preview.Testing
hatch run pytest tests/streamlit/).snowhouse_connectionend-to-end:hatch run snow streamlit deploy --preview --replace --connection snowhouse_connection --project … --format jsondeploys, files land atsnow://workspace/USER$.PUBLIC.DEFAULT$/versions/live/<entity_id>/, the streamlit is created atuser$.public.<name>with the SPCS runtime + compute pool clauses, and the returned URL correctly uses the resolvedUSER$<USERNAME>.PUBLIC.<NAME>identifier.Out-of-scope follow-ups
pyproject.tomlrequirement for SPCSv2 apps — the SiS container runtime requires apyproject.tomlfor dependency installation, but the existing in-tree fixture (tests_integration/test_data/projects/streamlit_spcs_v2/) ships onlyrequirements.txt. Affects both preview and non-preview SPCS deploys — worth a follow-up to auto-generate a minimalpyproject.tomlfromrequirements.txtwhenruntime_nameindicates SPCSv2.snow streamlit describe/dropfor preview-deployed apps — both subcommands resolve via the YAML FQN, notuser$.public.<name>. Out of scope here; worth a follow-up if real users hit it.Made with Cursor