mirror of
https://github.com/veekun/pokedex.git
synced 2024-08-20 18:16:34 +00:00
Make plumbing respect the same env vars as the CLI. #180
This commit is contained in:
parent
1c230f5990
commit
5e52bef91a
3 changed files with 14 additions and 1 deletions
|
@ -46,6 +46,9 @@ def get_session(options):
|
||||||
session.
|
session.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# WARNING: This logic duplicates that in db.connect(), because there's no
|
||||||
|
# other reliable way to tell where the engine actually came from. Keep it
|
||||||
|
# up to date!
|
||||||
engine_uri = options.engine_uri
|
engine_uri = options.engine_uri
|
||||||
got_from = None
|
got_from = None
|
||||||
if engine_uri:
|
if engine_uri:
|
||||||
|
@ -70,6 +73,9 @@ def get_lookup(options, session=None, recreate=False):
|
||||||
PokedexLookup object.
|
PokedexLookup object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# WARNING: This logic duplicates that in PokedexLookup, because there's no
|
||||||
|
# other reliable way to tell where the engine actually came from. Keep it
|
||||||
|
# up to date!
|
||||||
if recreate and not session:
|
if recreate and not session:
|
||||||
raise ValueError("get_lookup() needs an explicit session to regen the index")
|
raise ValueError("get_lookup() needs an explicit session to regen the index")
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import os
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
from sqlalchemy import MetaData, Table, create_engine, orm
|
from sqlalchemy import MetaData, Table, create_engine, orm
|
||||||
|
@ -13,7 +14,10 @@ def connect(uri=None, session_args={}, engine_args={}):
|
||||||
Calling this function also binds the metadata object to the created engine.
|
Calling this function also binds the metadata object to the created engine.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Default to a URI within the package, which was hopefully created at some point
|
# Fall back to the environment, then a URI within the package
|
||||||
|
if not uri:
|
||||||
|
uri = os.environ.get('POKEDEX_DB_ENGINE', None)
|
||||||
|
|
||||||
if not uri:
|
if not uri:
|
||||||
sqlite_path = pkg_resources.resource_filename('pokedex',
|
sqlite_path = pkg_resources.resource_filename('pokedex',
|
||||||
'data/pokedex.sqlite')
|
'data/pokedex.sqlite')
|
||||||
|
|
|
@ -103,6 +103,9 @@ class PokedexLookup(object):
|
||||||
# must be set
|
# must be set
|
||||||
|
|
||||||
# Defaults
|
# Defaults
|
||||||
|
if not directory:
|
||||||
|
directory = os.environ.get('POKEDEX_INDEX_DIR', None)
|
||||||
|
|
||||||
if not directory:
|
if not directory:
|
||||||
directory = pkg_resources.resource_filename('pokedex',
|
directory = pkg_resources.resource_filename('pokedex',
|
||||||
'data/whoosh-index')
|
'data/whoosh-index')
|
||||||
|
|
Loading…
Reference in a new issue