Beispiel #1
0
    def _resolve_version(self, spec: AssetSpec) -> None:
        local_versions = self._list_local_versions(spec)
        logger.debug("Local versions", local_versions=local_versions)

        if spec.is_version_complete():
            return

        remote_versions = []
        if self.storage_provider:
            remote_versions = self.storage_provider.get_versions_info(
                spec.name)
            logger.debug("Fetched remote versions",
                         remote_versions=remote_versions)

        all_versions = spec.sort_versions(version_list=set(local_versions +
                                                           remote_versions))

        if not all_versions:
            if not spec.version:
                logger.debug("Asset has no version information")
                # no version is specified and none exist
                # in this case, the asset spec is likely a relative or absolute
                # path to a file/directory
                return None

            raise errors.LocalAssetDoesNotExistError(
                name=spec.name,
                version=spec.version,
                local_versions=local_versions,
            )

        # at least one version info is missing, update to the latest
        spec.set_latest_version(all_versions)
Beispiel #2
0
    def update(self, asset_path: str, name: str, version: str, dry_run=False):
        """
        Update an existing asset version
        """
        spec = AssetSpec(name=name, version=version)
        versions_object_name = self.get_versions_object_name(spec.name)
        if not self.driver.exists(versions_object_name):
            raise errors.AssetDoesNotExistError(spec.name)
        logger.info(
            "Updating asset",
            name=spec.name,
            version=spec.version,
            asset_path=asset_path,
        )
        versions_list = self.get_versions_info(spec.name)

        self.push(asset_path, spec.name, spec.version, dry_run=dry_run)

        with tempfile.TemporaryDirectory() as tmp_dir:
            versions_fn = os.path.join(tmp_dir, "versions.json")
            versions = spec.sort_versions([spec.version] + versions_list)
            with open(versions_fn, "w") as f:
                json.dump({"versions": versions}, f)
            logger.debug(
                "Pushing updated versions file",
                name=spec.name,
                versions=versions,
            )
            if not dry_run:
                self.driver.upload_object(versions_fn, versions_object_name)
Beispiel #3
0
def test_asset_spec_sort_versions():
    spec = AssetSpec(name="name", versioning="simple_date")
    version_list = [
        "2021-11-15T17-30-56Z",
        "2020-11-15T17-30-56Z",
        "2021-10-15T17-30-56Z",
    ]
    result = [
        "2021-11-15T17-30-56Z",
        "2021-10-15T17-30-56Z",
        "2020-11-15T17-30-56Z",
    ]
    assert spec.sort_versions(version_list) == result
Beispiel #4
0
def test_asset_spec_sort_versions(version_list, result):
    spec = AssetSpec(name="name", versioning="major_minor")
    assert spec.sort_versions(version_list) == result