Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjusting VSCode settings for PYTHONPATH #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PYTHONPATH=./src
# PLEASE be careful not to commit credential information
# .env files are added into the .gitignore in order to avoid committing them
SNOWSQL_ACCOUNT=<replace with your account identifer>
SNOWSQL_USER=<replace with your username>
SNOWSQL_ROLE=<replace with your role>
SNOWSQL_PWD=<replace with your password>
SNOWSQL_DATABASE=<replace with your database>
SNOWSQL_SCHEMA=<replace with your schema>
SNOWSQL_WAREHOUSE=<replace with your warehouse>
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,5 @@ dmypy.json

.DS_Store

app.zip
app.zip
oryx-build-commands.txt
23 changes: 23 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"terminal.integrated.env.osx": {
"PYTHONPATH": "${env:PYTHONPATH}:${workspaceFolder}/src",
},
"terminal.integrated.env.linux": {
"PYTHONPATH": "${env:PYTHONPATH}:${workspaceFolder}/src",
},
"terminal.integrated.env.windows": {
"PYTHONPATH": "${env:PYTHONPATH};${workspaceFolder}/src",
},
/* Env files are practical for storing settings.
For example to connect to the database or setting the PYTHONPATH

*/
"python.envFile": "${workspaceFolder}/.env",
"files.exclude": {
"**/.git": true,
"Lib": true,
"Include": true,
"Scripts": true,
"**/__pycache__":true
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ To develop your applications locally, you will need
- Python 3.8 or greater
- An IDE or code editor (VS Code, PyCharm, etc.)

> NOTE: `PYTHONPATH` is an environment variable in Python that specifies a list of directories where Python should look for modules and packages when importing them. It is crucial when your source code is organized below the "src" folder, as setting `PYTHONPATH` to include the parent directory of "src" ensures that Python can locate and import your modules correctly, facilitating seamless collaboration and efficient module management within your project.

## Usage

Once you've set your credentials and installed the packages, you can test your connection to Snowflake by executing the stored procedure in [`app.py`](src/procs/app.py):
Expand Down
4 changes: 2 additions & 2 deletions resources.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ CREATE OR REPLACE PROCEDURE HELLO_WORLD_PROC()
LANGUAGE PYTHON
RUNTIME_VERSION = 3.8
IMPORTS = ('@artifacts/&artifact_name')
HANDLER = 'src.app.run'
HANDLER = 'app.run'
PACKAGES = ('pytest','snowflake-snowpark-python','tomli','toml');

CREATE OR REPLACE FUNCTION COMBINE(a String, b String)
RETURNS String
LANGUAGE PYTHON
RUNTIME_VERSION = 3.8
IMPORTS = ('@artifacts/&artifact_name')
HANDLER = 'src.functions.combine'
HANDLER = 'functions.combine'
PACKAGES = ('pytest','snowflake-snowpark-python','tomli','toml');
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
install of this project
"""

from setuptools import setup, find_packages
from setuptools import setup

PACKAGE_NAME="Example_Snowpark_Python_project"
setup(
name="Example Snowpark Python project",
name=PACKAGE_NAME,
version="0.1.0",
packages=find_packages()
# Specify the package directory
package_dir={'': 'src'},
# Include all files from the src directory
package_data={PACKAGE_NAME: ['*']}
)

# you can run python setup.py bdist_wheel
6 changes: 3 additions & 3 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from snowflake.snowpark.session import Session
from snowflake.snowpark.dataframe import col, DataFrame
from snowflake.snowpark.functions import udf
from src import functions
import functions

def run(snowpark_session: Session) -> DataFrame:
"""
Expand Down Expand Up @@ -35,11 +35,11 @@ def run(snowpark_session: Session) -> DataFrame:
if __name__ == "__main__":
# This entrypoint is used for local development (`$ python src/procs/app.py`)

from src.util.local import get_env_var_config
from util.local import get_env_var_config

print("Creating session...")
session = Session.builder.configs(get_env_var_config()).create()
session.add_import(functions.__file__, 'src.functions')
session.add_import(functions.__file__, 'functions')

print("Running stored procedure...")
result = run(session)
Expand Down
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest
from snowflake.snowpark.session import Session
from src.util.local import get_env_var_config
from util.local import get_env_var_config

@pytest.fixture
def session(scope='module'):
Expand Down
6 changes: 3 additions & 3 deletions test/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"""

from snowflake.snowpark.session import Session
from src import functions
from src.app import run
import functions
from app import run

def test_app_dim(session: Session):
session.add_import(functions.__file__, 'src.functions')
session.add_import(functions.__file__, 'functions')
expected = session.create_dataframe(
[["Welcome to Snowflake!"], ["Learn more: https://www.snowflake.com/snowpark/"]],
["hello_world"])
Expand Down
2 changes: 1 addition & 1 deletion test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Tests for the functions module.
"""

from src.functions import combine
from functions import combine

def test_combine():
expected = "hello world"
Expand Down