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

Refactor configurable options and add sphinx docs #1174

Merged
merged 12 commits into from
Nov 19, 2020
9 changes: 8 additions & 1 deletion sdk/python/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ Feature

.. automodule:: feast.feature
:inherited-members:
:members:
:members:

Constants
==================

.. automodule:: feast.constants
:members:
:exclude-members: AuthProvider
6 changes: 3 additions & 3 deletions sdk/python/feast/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from feast.client import Client
from feast.config import Config
from feast.constants import CONFIG_SPARK_LAUNCHER
from feast.constants import ConfigOptions
woop marked this conversation as resolved.
Show resolved Hide resolved
from feast.entity import Entity
from feast.feature_table import FeatureTable
from feast.job_service import start_job_service
Expand Down Expand Up @@ -422,7 +422,7 @@ def stop_stream_to_online(feature_table: str):
Stop stream to online sync job
"""

spark_launcher = Config().get(CONFIG_SPARK_LAUNCHER)
spark_launcher = Config().get(ConfigOptions.SPARK_LAUNCHER)

if spark_launcher == "emr":
import feast.pyspark.aws.jobs
Expand All @@ -441,7 +441,7 @@ def list_jobs():
"""
from tabulate import tabulate

spark_launcher = Config().get(CONFIG_SPARK_LAUNCHER)
spark_launcher = Config().get(ConfigOptions.SPARK_LAUNCHER)

if spark_launcher == "emr":
import feast.pyspark.aws.jobs
Expand Down
122 changes: 55 additions & 67 deletions sdk/python/feast/client.py

Large diffs are not rendered by default.

36 changes: 16 additions & 20 deletions sdk/python/feast/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@
from os.path import expanduser, join
from typing import Dict, Optional

from feast.constants import (
CONFIG_FEAST_ENV_VAR_PREFIX,
CONFIG_FILE_DEFAULT_DIRECTORY,
CONFIG_FILE_NAME,
CONFIG_FILE_SECTION,
FEAST_CONFIG_FILE_ENV_KEY,
)
from feast.constants import FEAST_DEFAULT_OPTIONS as DEFAULTS
from feast.constants import ConfigOptions

_logger = logging.getLogger(__name__)

Expand All @@ -50,13 +43,13 @@ def _init_config(path: str):
os.makedirs(os.path.dirname(config_dir), exist_ok=True)

# Create the configuration file itself
config = ConfigParser(defaults=DEFAULTS)
config = ConfigParser(defaults=ConfigOptions().defaults())
if os.path.exists(path):
config.read(path)

# Store all configuration in a single section
if not config.has_section(CONFIG_FILE_SECTION):
config.add_section(CONFIG_FILE_SECTION)
if not config.has_section(ConfigOptions().CONFIG_FILE_SECTION):
config.add_section(ConfigOptions().CONFIG_FILE_SECTION)

# Save the current configuration
config.write(open(path, "w"))
Expand All @@ -72,8 +65,10 @@ def _get_feast_env_vars():
"""
feast_env_vars = {}
for key in os.environ.keys():
if key.upper().startswith(CONFIG_FEAST_ENV_VAR_PREFIX):
feast_env_vars[key[len(CONFIG_FEAST_ENV_VAR_PREFIX) :]] = os.environ[key]
if key.upper().startswith(ConfigOptions().CONFIG_FEAST_ENV_VAR_PREFIX):
feast_env_vars[
key[len(ConfigOptions().CONFIG_FEAST_ENV_VAR_PREFIX) :]
] = os.environ[key]
return feast_env_vars


Expand Down Expand Up @@ -105,9 +100,10 @@ def __init__(
path = join(
expanduser("~"),
os.environ.get(
FEAST_CONFIG_FILE_ENV_KEY, CONFIG_FILE_DEFAULT_DIRECTORY,
ConfigOptions().FEAST_CONFIG_FILE_ENV,
ConfigOptions().CONFIG_FILE_DEFAULT_DIRECTORY,
),
CONFIG_FILE_NAME,
ConfigOptions().CONFIG_FILE_NAME,
)

config = _init_config(path)
Expand All @@ -130,7 +126,7 @@ def get(self, option):

"""
return self._config.get(
CONFIG_FILE_SECTION,
ConfigOptions().CONFIG_FILE_SECTION,
option,
vars={**_get_feast_env_vars(), **self._options},
)
Expand All @@ -146,7 +142,7 @@ def getboolean(self, option):

"""
return self._config.getboolean(
CONFIG_FILE_SECTION,
ConfigOptions().CONFIG_FILE_SECTION,
option,
vars={**_get_feast_env_vars(), **self._options},
)
Expand All @@ -162,7 +158,7 @@ def getint(self, option):

"""
return self._config.getint(
CONFIG_FILE_SECTION,
ConfigOptions().CONFIG_FILE_SECTION,
option,
vars={**_get_feast_env_vars(), **self._options},
)
Expand All @@ -178,7 +174,7 @@ def getfloat(self, option):

"""
return self._config.getfloat(
CONFIG_FILE_SECTION,
ConfigOptions().CONFIG_FILE_SECTION,
option,
vars={**_get_feast_env_vars(), **self._options},
)
Expand All @@ -190,7 +186,7 @@ def set(self, option, value):
option: Option name to use as key
value: Value to store under option
"""
self._config.set(CONFIG_FILE_SECTION, option, value=str(value))
self._config.set(ConfigOptions().CONFIG_FILE_SECTION, option, value=str(value))

def exists(self, option):
"""
Expand Down
Loading