def _initialize(self): from pypeapp.deployment import Deployment from pypeapp.lib.Terminal import Terminal try: import configparser except Exception: import ConfigParser as configparser cur_dir = os.path.dirname(os.path.abspath(__file__)) config_file_path = os.path.join(cur_dir, "config.ini") if os.path.exists(config_file_path): config = configparser.ConfigParser() config.read(config_file_path) try: value = config["DEFAULT"]["dev"] if value.lower() == "true": os.environ["PYPE_DEV"] = "1" except KeyError: pass # if not called, console coloring will get mangled in python. Terminal() pype_setup = os.getenv('PYPE_SETUP_PATH') d = Deployment(pype_setup) tools, config_path = d.get_environment_data() os.environ['PYPE_CONFIG'] = config_path os.environ['TOOL_ENV'] = os.path.normpath( os.path.join(config_path, 'environments')) self._add_modules() self._load_default_environments(tools=tools) self.print_info()
def _add_modules(self): """Include in **PYTHONPATH** all necessary packages. This will add all paths to deployed repos and also everything in ""vendor/python"". It will add it to :class:`sys.path` and to **PYTHONPATH** environment variable. .. note:: This will append, not overwrite existing paths """ from pypeapp.deployment import Deployment d = Deployment(os.environ.get('PYPE_SETUP_PATH', None)) paths = d.get_deployment_paths() # add self paths.append(os.environ.get('PYPE_SETUP_PATH')) # additional vendor packages vendor_path = os.path.join(os.getenv('PYPE_SETUP_PATH'), 'vendor', 'python') with os.scandir(vendor_path) as vp: for entry in vp: if entry.is_dir(): paths.append(entry.path) self._update_python_path(paths)
def test_read_deployment_file(self, set_path, deploy_file): """ Tests if we can read deployment file. :param set_path: pype setup root path :type set_path: string :param deploy_file: path to valid temporary deploy file :type deploy_file: string """ d = Deployment(set_path) data = d._read_deployment_file(deploy_file) assert data.get('repositories')[0].get('name') == "avalon-core" assert data.get('repositories')[1].get('branch') == "develop"
def validate(self): """Run deployment validation process. Upon failure it will exit with return code 200 to signal shell installation process about validation error. .. seealso:: :func:`Deployment.validate` """ from pypeapp.deployment import Deployment, DeployException d = Deployment(os.environ.get('PYPE_SETUP_PATH', None)) try: d.validate() except DeployException: sys.exit(200)
def deploy(self, force): """ This will run deployment process. Upon failure it will exit with return code 200 to signal shell installation process about deployment error. .. seealso:: :func:`Deployment.deploy` """ from pypeapp.deployment import Deployment, DeployException d = Deployment(os.environ.get('PYPE_ROOT', None)) try: d.deploy(force) except DeployException: sys.exit(200) pass
def test_invalid_path_raises_exception(self): """ Tests if invalid path provided to :class:`Deployment` will raise an exception. """ with pytest.raises(DeployException) as excinfo: Deployment('some_invalid_path') assert "PYPE_ROOT" in str(excinfo.value)
def test_determine_deployment_file(self, tmp_path): d = Deployment(tmp_path.as_posix()) path = Path(d._pype_root) deploy_dir = path / d._deploy_dir deploy_dir.mkdir() default_deploy_file = deploy_dir / d._deploy_file default_deploy_file.write_text('default') r = d._determine_deployment_file() assert r == os.path.normpath(default_deploy_file.as_posix()) override_dir = deploy_dir / "override" override_dir.mkdir() # it still should pick default one r = d._determine_deployment_file() assert r == os.path.normpath(default_deploy_file.as_posix()) override_deploy_file = override_dir / d._deploy_file override_deploy_file.write_text('override') # now it should pick override r = d._determine_deployment_file() assert r == os.path.normpath(override_deploy_file.as_posix())
def _initialize(self): from pypeapp.storage import Storage from pypeapp.deployment import Deployment from pypeapp.lib.Terminal import Terminal # if not called, console coloring will get mangled in python. Terminal() pype_setup = os.getenv('PYPE_ROOT') d = Deployment(pype_setup) tools, config_path = d.get_environment_data() os.environ['PYPE_CONFIG'] = config_path os.environ['TOOL_ENV'] = os.path.normpath( os.path.join( config_path, 'environments')) self._add_modules() Storage().update_environment() self._load_default_environments(tools=tools) self.print_info()
def test_validate_deployment(self, tmp_path, deploy_file): d = Deployment(os.path.normpath(tmp_path.as_posix())) deploy_test_path = tmp_path / "deploy" deploy_test_path.mkdir() root_path = os.path.abspath('.') # copy deploy and schema to temp test dir copyfile( os.path.join(root_path, d._deploy_dir, d._schema_file), os.path.join(os.path.normpath(deploy_test_path.as_posix()), d._schema_file)) copyfile( os.path.join(root_path, d._deploy_dir, d._deploy_file), os.path.join(os.path.normpath(deploy_test_path.as_posix()), d._deploy_file)) repo_test_path = tmp_path / "repos" repo_test_path.mkdir() # should fail as `repos` is empty with pytest.raises(DeployException) as excinfo: d.validate() assert excinfo.match(r"Repo path doesn't exist")
def setup_deployment(self, tmp_path, deploy_json=None): """ Setup environment for deployment test. Create temporary **deploy** and **repos** directories with correct **deploy.json** and it's schema. :param tmp_path: path to temporary directory :type tmp_path: string :param deploy_json: provide optional content for **deploy.json** :type deploy_json: str :returns: Deployment instance :rtype: :class:`Deployment` """ d = Deployment(os.path.normpath(tmp_path.as_posix())) deploy_test_path = tmp_path / "deploy" deploy_test_path.mkdir() root_path = os.path.abspath('.') # copy deploy and schema to temp test dir copyfile( os.path.join(root_path, d._deploy_dir, d._schema_file), os.path.join(os.path.normpath(deploy_test_path.as_posix()), d._schema_file)) if deploy_json is not None: with open( os.path.join(os.path.normpath(deploy_test_path.as_posix()), d._deploy_file), "w") as dfile: json.dump(deploy_json, dfile) else: copyfile( os.path.join(root_path, d._deploy_dir, d._deploy_file), os.path.join(os.path.normpath(deploy_test_path.as_posix()), d._deploy_file)) repo_test_path = tmp_path / "repos" repo_test_path.mkdir() return d
# -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # # import os # import sys # sys.path.insert(0, os.path.abspath('.')) import os from pypeapp.pypeLauncher import PypeLauncher from pypeapp.deployment import Deployment pype_setup = os.getenv('PYPE_SETUP_PATH') d = Deployment(pype_setup) launcher = PypeLauncher() tools, config_path = d.get_environment_data() os.environ['PYPE_CONFIG'] = config_path os.environ['TOOL_ENV'] = os.path.normpath(os.path.join(config_path, 'environments')) launcher._add_modules() launcher._load_default_environments(tools=tools) # -- Project information ----------------------------------------------------- project = 'pype' copyright = '2019, Orbi Tools' author = 'Orbi Tools'
def test_read_invalid_deployment_file(self, set_path): d = Deployment(set_path) with pytest.raises(FileNotFoundError): d._read_deployment_file('wfjagp')
def test_validate_schema(self, invalid_deploy_file, deploy_file): d = Deployment(os.path.abspath('.')) r = d._validate_schema(d._read_deployment_file(invalid_deploy_file)) assert r is False r = d._validate_schema(d._read_deployment_file(deploy_file)) assert r is True
def test_read_schema_raises_exception(self, set_path): d = Deployment(set_path) with pytest.raises(DeployException): d._read_schema("blabla")
def test_read_schema(self, set_path): d = Deployment(set_path) schema_file = os.path.join(d._pype_root, d._deploy_dir, d._schema_file) pprint(schema_file) schema = d._read_schema(schema_file) assert schema.get('title') == 'pype:deployment-schema'