Skip to content

Commit

Permalink
sis-local: Update install path and improve running_in_sis() impl (#20)
Browse files Browse the repository at this point in the history
* Update install path and improve running_in_sis() impl

* More explainable running_in_sis()
  • Loading branch information
sfc-gh-jcarroll authored Jun 21, 2023
1 parent 6030ac2 commit a192462
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions samples/streamlit-in-snowflake/sis-local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and provide a much smoother experience doing local development and porting to Si
Just like Snowpark, **it requires python 3.8.**

```shell
pip install "streamlit_in_snowflake @ git+https://github.com/blackary/sis-tricks.git#subdirectory=sis-local"
pip install "streamlit_in_snowflake @ git+https://github.com/Snowflake-Labs/sf-samples.git#subdirectory=samples/streamlit-in-snowflake/sis-local"
```

In general, we recommend managing your environment with Conda,
Expand All @@ -33,11 +33,11 @@ from snowflake.snowpark.exceptions import SnowparkSessionException


def running_in_sis() -> bool:
try:
sess = get_active_session()
return True
except SnowparkSessionException:
return False
import snowflake.connector.connection
import inspect
# snowflake.connector.connection.SnowflakeConnection does not exist inside a Stored Proc or Streamlit.
# It is only part of the external package. So this returns true only in SiS.
return 0 == len([x for x in inspect.getmembers(snowflake.connector.connection) if x[0] == 'SnowflakeConnection'])


if running_in_sis():
Expand Down
4 changes: 2 additions & 2 deletions samples/streamlit-in-snowflake/sis-local/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
3. Run the following

```shell
pip install "streamlit_in_snowflake @ git+https://github.com/blackary/sis-tricks.git#subdirectory=sis-local"
pip install "streamlit_in_snowflake @ git+https://github.com/Snowflake-Labs/sf-samples.git#subdirectory=samples/streamlit-in-snowflake/sis-local"
python -m streamlit run sis_app.py
```

Expand All @@ -28,6 +28,6 @@ conda init --all # See conda docs on what this does / how to use it
conda env create -f environment.yml
conda activate sis-example
# Install streamlit_in_snowflake and run the example app as above
pip install -r "streamlit_in_snowflake @ git+https://github.com/blackary/sis-tricks.git#subdirectory=sis-local"
pip install "streamlit_in_snowflake @ git+https://github.com/Snowflake-Labs/sf-samples.git#subdirectory=samples/streamlit-in-snowflake/sis-local"
python -m streamlit run sis_app.py
```
10 changes: 5 additions & 5 deletions samples/streamlit-in-snowflake/sis-local/example/sis_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@


def running_in_sis() -> bool:
try:
sess = get_active_session()
return True
except SnowparkSessionException:
return False
import snowflake.connector.connection
import inspect
# snowflake.connector.connection.SnowflakeConnection does not exist inside a Stored Proc or Streamlit.
# It is only part of the external package. So this returns true only in SiS.
return 0 == len([x for x in inspect.getmembers(snowflake.connector.connection) if x[0] == 'SnowflakeConnection'])


if running_in_sis():
Expand Down

0 comments on commit a192462

Please sign in to comment.