def calc_init_value(self, value): if value is None: # it's None # TODO: may be we still can "normalize" the value return value if isinstance(value, Path): return target(str(value), config=self.target_config) if isinstance(value, Target): # it's deferred result - > we load it lately return value # we process value regardless parse! # cf_value.require_parse: if self.env_interpolation and isinstance(value, six.string_types): try: value = expand_env_var(value) except Exception as ex: logger.warning( "failed to expand variable '%s' : %s", safe_string(value), str(ex) ) # in case we are output and have value: # it's Target or it's str to be converted as target load_value = self.load_on_build and not self.is_output() return self.value_type.parse_value( value, load_value=load_value, target_config=self.target_config )
def get(self, section, key, default=None, expand_env=True): config_value = self.get_config_value(section=section, key=key) if config_value: value = config_value.value if expand_env: value = expand_env_var(value) value = STR_VALUE_TYPE._interpolate_from_str(value) return value return default
def init_databand_env(): if in_quiet_mode(): # we should not print anything if we are in shell completion! import logging logging.getLogger().setLevel(logging.CRITICAL + 1) # MAIN PART OF THE SCRIPT if ENV_DBND_HOME not in os.environ: _set_project_root() if ENV_DBND_HOME not in os.environ: raise DatabandHomeError( "\nDBND_HOME could not be found when searching from current directory '%s' to root folder!\n " "Trying fixing that issue by:\n" "\t 1. Explicitly set current directory to DBND HOME via: `export DBND_HOME=ROOT_OF_YOUR_PROJECT`.\n" "\t 2. `cd` into your project directory.\n" "\t 3. Create one of the following files inside current directory: [%s].\n" "\t 4. Run 'dbnd project-init' in current directory." % (os.getcwd(), ", ".join(_MARKER_FILES))) _dbnd_home = os.environ[ENV_DBND_HOME] if ENV_DBND_SYSTEM not in os.environ: dbnd_system = os.path.join(_dbnd_home, ".dbnd") if not os.path.exists(dbnd_system) and os.path.exists( os.path.join(_dbnd_home, "dbnd")): dbnd_system = os.path.join(_dbnd_home, "dbnd") os.environ[ENV_DBND_SYSTEM] = dbnd_system if ENV_DBND_LIB not in os.environ: os.environ[ENV_DBND_LIB] = _databand_package if "AIRFLOW_HOME" not in os.environ: os.environ["AIRFLOW_HOME"] = airflow_home = os.path.join( os.environ[ENV_DBND_SYSTEM], "airflow") else: airflow_home = expand_env_var(os.environ["AIRFLOW_HOME"]) # airflow config override airflow_user_config = os.path.join(airflow_home, "airflow.cfg") if ENV_AIRFLOW_CONFIG not in os.environ and not os.path.exists( airflow_user_config): # User did not define his own airflow configuration # Use dbnd core lib configuration os.environ[ENV_AIRFLOW_CONFIG] = os.path.join(_databand_package, "conf", "airflow.cfg") if _DBND_DEBUG_INIT: print(_env_banner()) _init_windows_python_path()