Skip to content

Commit

Permalink
update notebooks according to latest changes in config
Browse files Browse the repository at this point in the history
  • Loading branch information
pmayd committed Oct 29, 2023
1 parent 1f74065 commit 4675f6d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
15 changes: 7 additions & 8 deletions nb/00_Setup.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"import dotenv\n",
"import pystatis\n",
"from pystatis.config import get_supported_db, config\n",
"from pystatis import config # always access config this way and do not import config from config!\n",
"\n",
"print(\"pystatis version: \", pystatis.__version__)\n",
"dotenv.load_dotenv()"
Expand All @@ -34,8 +33,8 @@
"outputs": [],
"source": [
"# only execute if you want to delete your config file for test purposes\n",
"pystatis.config.delete_config()\n",
"pystatis.config.init_config()"
"config.delete_config()\n",
"config.init_config()"
]
},
{
Expand Down Expand Up @@ -67,15 +66,15 @@
"metadata": {},
"outputs": [],
"source": [
"pystatis.setup_credentials()"
"pystatis.setup_credentials() # also part of config module"
]
},
{
"cell_type": "markdown",
"id": "d7d92f0d",
"metadata": {},
"source": [
"Once you have set up your credentials, they are stored in the `config.ini`. You can use `pystatis.config.load_config()` to retrieve these values."
"Once you have set up your credentials, they are stored in the `config.ini` and in the `config` object of the `config.py` module. You don't have to know this as regular user, this is more internal knowledge."
]
},
{
Expand All @@ -87,9 +86,9 @@
"source": [
"from pprint import pprint\n",
"\n",
"for db in get_supported_db():\n",
"for db in config.get_supported_db():\n",
" print(\"Database: \", db)\n",
" for k, v in config[db].items():\n",
" for k, v in config.config[db].items():\n",
" print(k, v)\n",
" print()"
]
Expand Down
12 changes: 6 additions & 6 deletions nb/01_Databases.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"import pystatis.db as pystatdb\n",
"from pystatis import logincheck"
"from pystatis import set_db, logincheck, db"
]
},
{
Expand All @@ -16,7 +15,8 @@
"metadata": {},
"outputs": [],
"source": [
"pystatdb.get_db()"
"# expected to fail so you know you have to call set_db() first\n",
"db.get_db()"
]
},
{
Expand All @@ -26,7 +26,7 @@
"outputs": [],
"source": [
"# expected to fail!\n",
"pystatdb.set_db(\"test\")"
"set_db(\"test\")"
]
},
{
Expand All @@ -35,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"pystatdb.set_db(\"genesis\")\n",
"set_db(\"genesis\")\n",
"logincheck()"
]
},
Expand All @@ -45,7 +45,7 @@
"metadata": {},
"outputs": [],
"source": [
"pystatdb.set_db(\"zensus\")\n",
"set_db(\"zensus\")\n",
"logincheck()"
]
}
Expand Down
15 changes: 12 additions & 3 deletions nb/helloworld.ipynb → nb/02_helloworld.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@
"import logging\n",
"logging.basicConfig(level=logging.INFO)\n",
"\n",
"from pystatis import logincheck, whoami"
"from pystatis import logincheck, whoami, set_db"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"set_db(\"genesis\")"
]
},
{
Expand All @@ -35,7 +44,7 @@
"metadata": {},
"outputs": [],
"source": [
"# test your login credentials (set via config functions)\n",
"# test your login credentials (set via setup_credentials() from config module)\n",
"logincheck()"
]
}
Expand All @@ -56,7 +65,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.11.5"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
4 changes: 2 additions & 2 deletions nb/table.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"logging.basicConfig(level=logging.INFO)\n",
"\n",
"from pystatis import Table\n",
"from pystatis.db import set_db"
"from pystatis import db"
]
},
{
Expand All @@ -23,7 +23,7 @@
"metadata": {},
"outputs": [],
"source": [
"set_db(\"genesis\")"
"db.set_db(\"genesis\")"
]
},
{
Expand Down
10 changes: 2 additions & 8 deletions src/pystatis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@
print("Version:", pstat.__version__)
```
"""
import pystatis.cache
import pystatis.config
import pystatis.cube
import pystatis.db
import pystatis.find
import pystatis.helloworld
import pystatis.profile
import pystatis.table
from pystatis.cache import clear_cache
from pystatis.config import setup_credentials
from pystatis.cube import Cube
from pystatis.db import set_db
from pystatis.find import Find
from pystatis.helloworld import logincheck, whoami
from pystatis.table import Table
Expand All @@ -31,6 +24,7 @@
"Find",
"logincheck",
"remove_result",
"set_db",
"setup_credentials",
"Table",
"whoami",
Expand Down
5 changes: 2 additions & 3 deletions src/pystatis/http_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

import requests

from pystatis import config, db
from pystatis.cache import (
cache_data,
hit_in_cash,
normalize_name,
read_from_cache,
)
from pystatis.config import get_cache_dir
from pystatis import db
from pystatis.exception import DestatisStatusError

logger = logging.getLogger(__name__)
Expand All @@ -40,7 +39,7 @@ def load_data(
Returns:
Union[str, dict]: The data as raw text or JSON dict.
"""
cache_dir = Path(get_cache_dir())
cache_dir = Path(config.get_cache_dir())
name = params.get("name")

if name is not None:
Expand Down

0 comments on commit 4675f6d

Please sign in to comment.