def update_repository(repository_dir, git_url, revision="origin/master"): """Get the latest version of a revision or clone the repository""" should_clone = True if io.exists(repository_dir): # If the target directory already exists remote_url = None try: remote_url = get_remote_url(repository_dir) except Exception: # pylint: disable=broad-except # If the directory is not a git repository, `get_remote_url` will throw pass if remote_url == git_url: # If the remotes are the same, clean and fetch io.execute("git clean -dfx", repository_dir) io.execute("git fetch --all", repository_dir) # No need to clone should_clone = False else: # If the remotes mismatch, remove the old one io.remove(repository_dir) if should_clone: io.execute(f"git clone {git_url} {repository_dir}") io.execute(f"git reset --hard {revision}", repository_dir)
def get_project_config(config_path: str = Configuration.get_config_path() ) -> dict: """Load the global configuration of the project""" project_config_path = os.path.join( config_path, Configuration.get_config_project_filename()) if not io.exists(project_config_path): raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), project_config_path) project_config = yaml_lib.read_yaml(project_config_path) return _resolve_variables_deep(project_config)
def get_project_config() -> dict: """Load the configuration of the current environment (global configuration)""" project_config_path = os.path.join( Configuration.get_config_path(), Configuration.get_config_projet_filename()) if not io.exists(project_config_path): raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), project_config_path) project_config = io.from_yaml(project_config_path) return _resolve_variables_deep(project_config)
def get_app_config(app_name: str) -> dict: """Load the configuration of an app""" app_config_path = os.path.join( Configuration.get_config_path(), Configuration.get_config_app_folder(), f"{app_name}.yaml", ) if not io.exists(app_config_path): raise AppConfigurationNotFoundError(app_name) app_config = io.from_yaml(app_config_path) environment_config = get_project_config() config = dict_utils.deep_merge(environment_config, app_config) # Awaiting for implementation # validate configuration using nestor-config-validator return _resolve_variables_deep(config)
def test_exists_not_existing_file(self, path_mock): path_mock.return_value.exists.return_value = False result = io.exists("unexisting/path") path_mock.assert_called_once_with("unexisting/path") path_mock.return_value.exists.assert_called_once() self.assertFalse(result)
def test_exists_not_existing_file(): existing_path = Path(os.path.dirname(__file__), "abcdefghijklmnopqrstuvwxyz.py").resolve() assert not io.exists(existing_path)
def test_exists_existing_file(): existing_path = Path(os.path.dirname(__file__), "__init__.py").resolve() assert io.exists(existing_path)