def test_env_vars_from_file_whitespace(self): tmpdir = tempfile.mkdtemp('env_file') self.addCleanup(shutil.rmtree, tmpdir) with codecs.open('{}/whitespace.env'.format(str(tmpdir)), 'w', encoding='utf-8') as f: f.write('WHITESPACE =yes\n') with pytest.raises(ConfigurationError) as exc: env_vars_from_file(str(os.path.join(tmpdir, 'whitespace.env'))) assert 'environment variable' in exc.exconly()
def test_env_vars_from_file_whitespace(self): tmpdir = pytest.ensuretemp('env_file') self.addCleanup(tmpdir.remove) with codecs.open('{}/whitespace.env'.format(str(tmpdir)), 'w', encoding='utf-8') as f: f.write('WHITESPACE =yes\n') with pytest.raises(ConfigurationError) as exc: env_vars_from_file(str(tmpdir.join('whitespace.env'))) assert 'environment variable' in exc.exconly()
def environment(self): env = {} layout = self.env.get('DORK_DIRECTORY_LAYOUT', False) source = self.env.get('DORK_SOURCE') if layout: matches = [path for path in glob.glob(os.path.abspath(layout)) if dork_compose.helpers.is_subdir(source, path)] if not matches: return env env['DORK_SOURCE'] = max(matches, key=len) if env['DORK_SOURCE'] != source: hotcode = [path for path in env.get('DORK_HOTCODE', '').split(';') if path != ''] hotcode.append(source[len(env['DORK_SOURCE'])+1:]) env['DORK_HOTCODE'] = ';'.join(hotcode) if self.library: files = filter(lambda x: x, self.env.get('COMPOSE_FILE', '').split(':')) if os.path.isfile(self.library + '/docker-compose.yml'): files.insert(0, self.library + '/docker-compose.yml') os.environ.update({ 'COMPOSE_FILE': ':'.join(files) }) envfile = '%s/.env' % self.library if os.path.isfile(envfile): for key, value in env_vars_from_file(envfile).iteritems(): if key not in self.env: env[key] = os.path.expandvars(value) return env
def test_env_vars_from_file_bom(self): tmpdir = pytest.ensuretemp('env_file') self.addCleanup(tmpdir.remove) with codecs.open('{}/bom.env'.format(str(tmpdir)), 'w', encoding='utf-8') as f: f.write('\ufeffPARK_BOM=박봄\n') assert env_vars_from_file(str(tmpdir.join('bom.env'))) == { 'PARK_BOM': '박봄' }
def test_env_vars_from_file_bom(self): tmpdir = tempfile.mkdtemp('env_file') self.addCleanup(shutil.rmtree, tmpdir) with codecs.open('{}/bom.env'.format(str(tmpdir)), 'w', encoding='utf-8') as f: f.write('\ufeffPARK_BOM=박봄\n') assert env_vars_from_file(str(os.path.join(tmpdir, 'bom.env'))) == { 'PARK_BOM': '박봄' }
def test_env_vars(self, test_name, content, expected): tmpdir = tempfile.mkdtemp('env_file') self.addCleanup(shutil.rmtree, tmpdir) file_abs_path = str(os.path.join(tmpdir, ".env")) with codecs.open(file_abs_path, 'w', encoding='utf-8') as f: f.write(content) assert env_vars_from_file( file_abs_path) == expected, '"{}" Failed'.format(test_name)
def environment(self): old_environment = os.environ.copy() path = filter(len, os.path.abspath(os.path.curdir).split('/')) current = '' while len(path): current = current + '/' + path.pop(0) envfile = '%s/.dork.env' % current if os.path.isfile(envfile): for key, value in env_vars_from_file(envfile).iteritems(): os.environ[key] = os.path.expandvars(value) continue envfile = '%s/.env' % current if os.path.isfile(envfile): for key, value in env_vars_from_file(envfile).iteritems(): os.environ[key] = os.path.expandvars(value) env = os.environ.copy() os.environ = old_environment return env
def test_env_vars_from_file_quoted(self): tmpdir = pytest.ensuretemp('env_file') self.addCleanup(tmpdir.remove) with codecs.open('{}/quoted.env'.format(str(tmpdir)), 'w', encoding='utf-8') as f: f.write('DOUBLE_QUOTES="testing \"double\" quotes"\n') f.write("SINGLE_QUOTES='testing \'single\' quotes'\n") assert env_vars_from_file(str(tmpdir.join('quoted.env'))) == { 'DOUBLE_QUOTES': 'testing "double" quotes', 'SINGLE_QUOTES': "testing 'single' quotes", }
def update_environment(): # Collect separate environment dict from .env files in # current and parent directories. env = {} path = filter(len, os.path.abspath(os.path.curdir).split('/')) current = '' if 'DORK_PLUGINS' not in os.environ: os.environ['DORK_PLUGINS'] = DEFAULT_PLUGINS while len(path): current = current + '/' + path.pop(0) envfile = '%s/.env' % current if os.path.isfile(envfile): env.update(env_vars_from_file(envfile)) os.environ.update(env)
) PYLINT_CONFIGS = ( "maintainer-quality-tools/master/travis/cfg/travis_run_pylint_pr.cfg", "maintainer-quality-tools/master/travis/cfg/travis_run_pylint.cfg", "maintainer-quality-tools/master/travis/cfg/travis_run_pylint_beta.cfg", ) CONFIGS = PYLINT_CONFIGS + ( "maintainer-quality-tools/master/travis/cfg/travis_run_flake8.cfg", "pylint-odoo/master/pylint_odoo/examples/.jslintrc", ) DEST = path.join(path.dirname(__file__), "doodba") ROOT = path.abspath(path.join(DEST, "..", "..")) ENV_FILE = path.join(ROOT, ".env") SCAFFOLDING_NAME = path.basename(path.abspath(ROOT)) env = env_vars_from_file(ENV_FILE) # Use the right Python version for current Doodba project version = env.get("ODOO_MINOR") if version in {"7.0", "8.0", "9.0", "10.0"}: executable = shutil.which("python2") or shutil.which("python") else: executable = sys.executable try: os.remove(path.join(DEST, "python")) except FileNotFoundError: pass os.symlink(executable, path.join(DEST, "python")) # Enable development environment by default try:
def environment(self): filename = '%s/.env' % self.library if os.path.isfile(filename): for key, value in env_vars_from_file(filename).iteritems(): self.env[key] = self.env.get(key, value) return self.env