forked from hans/Nominatim
allow None and str for project_dir in NominatimAPI init
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
"""
|
||||
Implementation of classes for API access via libraries.
|
||||
"""
|
||||
from typing import Mapping, Optional, Any, AsyncIterator, Dict, Sequence, List, Tuple, cast
|
||||
from typing import Mapping, Optional, Any, AsyncIterator, Dict, Sequence, List,\
|
||||
Union, Tuple, cast
|
||||
import asyncio
|
||||
import sys
|
||||
import contextlib
|
||||
@@ -41,7 +42,7 @@ class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes
|
||||
|
||||
This class should usually be used as a context manager in 'with' context.
|
||||
"""
|
||||
def __init__(self, project_dir: Path,
|
||||
def __init__(self, project_dir: Optional[Union[str, Path]] = None,
|
||||
environ: Optional[Mapping[str, str]] = None,
|
||||
loop: Optional[asyncio.AbstractEventLoop] = None) -> None:
|
||||
""" Initiate a new frontend object with synchronous API functions.
|
||||
@@ -365,7 +366,7 @@ class NominatimAPI:
|
||||
This class should usually be used as a context manager in 'with' context.
|
||||
"""
|
||||
|
||||
def __init__(self, project_dir: Path,
|
||||
def __init__(self, project_dir: Optional[Union[str, Path]] = None,
|
||||
environ: Optional[Mapping[str, str]] = None) -> None:
|
||||
""" Initiate a new frontend object with synchronous API functions.
|
||||
|
||||
|
||||
@@ -59,15 +59,17 @@ class Configuration:
|
||||
other than string.
|
||||
"""
|
||||
|
||||
def __init__(self, project_dir: Optional[Path],
|
||||
def __init__(self, project_dir: Optional[Union[Path, str]],
|
||||
environ: Optional[Mapping[str, str]] = None) -> None:
|
||||
self.environ = environ or os.environ
|
||||
self.project_dir = project_dir
|
||||
self.config_dir = paths.CONFIG_DIR
|
||||
self._config = dotenv_values(str(self.config_dir / 'env.defaults'))
|
||||
if self.project_dir is not None and (self.project_dir / '.env').is_file():
|
||||
self.project_dir = self.project_dir.resolve()
|
||||
self._config.update(dotenv_values(str(self.project_dir / '.env')))
|
||||
if project_dir is not None:
|
||||
self.project_dir: Optional[Path] = Path(project_dir).resolve()
|
||||
if (self.project_dir / '.env').is_file():
|
||||
self._config.update(dotenv_values(str(self.project_dir / '.env')))
|
||||
else:
|
||||
self.project_dir = None
|
||||
|
||||
class _LibDirs:
|
||||
module: Path
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"""
|
||||
Exporting a Nominatim database to SQlite.
|
||||
"""
|
||||
from typing import Set, Any
|
||||
from typing import Set, Any, Optional, Union
|
||||
import datetime as dt
|
||||
import logging
|
||||
from pathlib import Path
|
||||
@@ -21,7 +21,8 @@ from nominatim_api.sql.sqlalchemy_types import Geometry, IntArray
|
||||
|
||||
LOG = logging.getLogger()
|
||||
|
||||
async def convert(project_dir: Path, outfile: Path, options: Set[str]) -> None:
|
||||
async def convert(project_dir: Optional[Union[str, Path]],
|
||||
outfile: Path, options: Set[str]) -> None:
|
||||
""" Export an existing database to sqlite. The resulting database
|
||||
will be usable against the Python frontend of Nominatim.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user