Skip to content

Commit

Permalink
ENG-3777: Run Python notebooks in SDK Circle-CI
Browse files Browse the repository at this point in the history
  • Loading branch information
JMkrish committed Dec 8, 2023
1 parent f80e915 commit ed6d7ef
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 40 deletions.
17 changes: 16 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ jobs:
# image: ubuntu-2204:2022.07.1
docker:
- image: cimg/python:3.11.0
environment:
# ENV_VAR_TENANT: $ENV_VAR_TENANT
# ENV_VAR_USERNAME: $ENV_VAR_USERNAME
# ENV_VAR_PASSWORD: $ENV_VAR_PASSWORD
# ENV_VAR_API_KEY: $ENV_VAR_API_KEY
# ENV_VAR_API_SECRET: $ENV_VAR_API_SECRET
ENV_VAR_TENANT: "demo-sdk-test"
ENV_VAR_USERNAME: "[email protected]"
ENV_VAR_PASSWORD: "pass1234"
ENV_VAR_API_KEY: "dfa170cd-ae1f-4a4d-98d2-8b7aa65d776b"
ENV_VAR_API_SECRET: "sma_ZTyg2msZexRVfSlg5OczUCmzpNfh26ywW6zle0mzGBzI_"
steps:
# Make sure that the build doesn't accidentally pull images from Docker Hub.
# Pulls from Docker Hub may fail due to rate-limiting after Nov 1 2020.
Expand All @@ -61,8 +72,12 @@ jobs:
command: |
set -x
pip install -r requirements-codecoverage.txt
echo "ENV_VAR_API_SECRET value is: ${ENV_VAR_API_SECRET}"
echo "PYTHONPATH value is: ${PYTHONPATH}"
pip install -e .
mkdir test-results
coverage run -m pytest --junitxml=test-results/junit.xml tests
# coverage run -m pytest --nbmake --nbmake-timeout=3000 -n=auto --junitxml=test-results/junit.xml examples/Quick\ Start.ipynb
coverage run -m pytest --nbmake --nbmake-timeout=3000 -n=auto --junitxml=test-results/junit.xml tests examples/Quick\ Start.ipynb examples/Query\ Examples.ipynb
- run:
name: Compile Coverage Report
command: |
Expand Down
44 changes: 39 additions & 5 deletions examples/Query Examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,43 @@
"source": [
"from smsdk import client\n",
"from datetime import datetime, timedelta\n",
"import pandas as pd"
"import pandas as pd\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"env_var_tenant = 'ENV_VAR_TENANT'\n",
"env_var_api_key = 'ENV_VAR_API_KEY'\n",
"env_var_api_secret = 'ENV_VAR_API_SECRET'\n",
"\n",
"# Check if the environment variable exists\n",
"if env_var_tenant in os.environ:\n",
" # Retrieve the value of the environment variable\n",
" tenant = os.environ[env_var_tenant]\n",
"else:\n",
" # Use a default value if the environment variable is not present\n",
" tenant = 'demo'\n",
"\n",
"# Check if the environment variable exists\n",
"if env_var_api_key in os.environ:\n",
" # Retrieve the value of the environment variable\n",
" api_key = os.environ[env_var_api_key]\n",
"else:\n",
" # Use a default value if the environment variable is not present\n",
" api_key = ''\n",
"\n",
"# Check if the environment variable exists\n",
"if env_var_api_secret in os.environ:\n",
" # Retrieve the value of the environment variable\n",
" api_secret = os.environ[env_var_api_secret]\n",
"else:\n",
" # Use a default value if the environment variable is not present\n",
" api_secret = ''"
]
},
{
Expand Down Expand Up @@ -58,9 +94,7 @@
}
],
"source": [
"api_key = ''\n",
"api_secret = ''\n",
"cli = client.Client('demo')\n",
"cli = client.Client(tenant)\n",
"cli.login('apikey', \n",
" key_id = api_key, \n",
" secret_id = api_secret)\n",
Expand Down Expand Up @@ -2078,7 +2112,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.8.18"
},
"orig_nbformat": 2,
"vscode": {
Expand Down
105 changes: 72 additions & 33 deletions examples/Quick Start.ipynb
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
{
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5-final"
},
"orig_nbformat": 2,
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2,
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example: Quick Start\n",
"\n",
Expand All @@ -35,18 +15,17 @@
"- Listing machines \n",
"- Listing machine attributes/stats \n",
"- Running a basic query"
],
"cell_type": "markdown",
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime \n",
"from smsdk import client"
"from smsdk import client\n",
"import os"
]
},
{
Expand All @@ -55,8 +34,33 @@
"metadata": {},
"outputs": [],
"source": [
"tenant = 'my_tenant'\n",
"cli = client.Client(tenant)"
"env_var_tenant = 'ENV_VAR_TENANT'\n",
"env_var_username = 'ENV_VAR_USERNAME'\n",
"env_var_password = 'ENV_VAR_PASSWORD'\n",
"\n",
"# Check if the environment variable exists\n",
"if env_var_tenant in os.environ:\n",
" # Retrieve the value of the environment variable\n",
" tenant = os.environ[env_var_tenant]\n",
"else:\n",
" # Use a default value if the environment variable is not present\n",
" tenant = 'my_tenant'\n",
"\n",
"# Check if the environment variable exists\n",
"if env_var_username in os.environ:\n",
" # Retrieve the value of the environment variable\n",
" username = os.environ[env_var_username]\n",
"else:\n",
" # Use a default value if the environment variable is not present\n",
" username = '[email protected]'\n",
"\n",
"# Check if the environment variable exists\n",
"if env_var_password in os.environ:\n",
" # Retrieve the value of the environment variable\n",
" password = os.environ[env_var_password]\n",
"else:\n",
" # Use a default value if the environment variable is not present\n",
" password = 'asdf%^&*1234'"
]
},
{
Expand All @@ -65,9 +69,22 @@
"metadata": {},
"outputs": [],
"source": [
"username = '[email protected]'\n",
"password = 'asdf%^&*1234'\n",
"print(tenant)\n",
"print(username)\n",
"print(password)\n",
"\n",
"assert tenant == \"demo-sdk-test\"\n",
"assert username == \"[email protected]\"\n",
"assert password == \"pass1234\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cli = client.Client(tenant)\n",
"cli.login('basic', email=username, password=password)"
]
},
Expand Down Expand Up @@ -121,5 +138,27 @@
"outputs": [],
"source": []
}
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
},
"orig_nbformat": 2
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 3 additions & 1 deletion requirements-codecoverage.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Use public repo for coverall upload

codecov==2.1.13
coverage==7.3.2
coverage==7.3.2
nbmake==1.4.6
pytest-xdist==3.5.0

0 comments on commit ed6d7ef

Please sign in to comment.