From 0beb03fe53641ae99024a0b1e39325a64305c4d0 Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Thu, 11 Jun 2020 10:30:46 -0600 Subject: [PATCH] allow floats for package versions, add a test with a float-like branch --- CHANGELOG.md | 1 + core/dbt/contracts/project.py | 20 +++++++++++++++++-- core/dbt/deps/git.py | 2 +- core/dbt/deps/registry.py | 4 +--- .../test_simple_dependency.py | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdee1e6f5d5..384ed38274d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Fixes - dbt compile and ls no longer create schemas if they don't already exist ([#2525](https://github.com/fishtown-analytics/dbt/issues/2525), [#2528](https://github.com/fishtown-analytics/dbt/pull/2528)) - `dbt deps` now respects the `--project-dir` flag, so using `dbt deps --project-dir=/some/path` and then `dbt run --project-dir=/some/path` will properly find dependencies ([#2519](https://github.com/fishtown-analytics/dbt/issues/2519), [#2534](https://github.com/fishtown-analytics/dbt/pull/2534)) +- `packages.yml` revision/version fields can be float-like again (`revision: '1.0'` is valid). ([#2518](https://github.com/fishtown-analytics/dbt/issues/2518), [#2535](https://github.com/fishtown-analytics/dbt/pull/2535)) ## dbt 0.17.0 (June 08, 2020) diff --git a/core/dbt/contracts/project.py b/core/dbt/contracts/project.py index d028a11fbf1..884d82d4577 100644 --- a/core/dbt/contracts/project.py +++ b/core/dbt/contracts/project.py @@ -48,17 +48,33 @@ class LocalPackage(Package): local: str +# `float` also allows `int`, according to PEP484 (and jsonschema!) +RawVersion = Union[str, float] + + @dataclass class GitPackage(Package): git: str - revision: Optional[str] + revision: Optional[RawVersion] warn_unpinned: Optional[bool] = None + def get_revisions(self) -> List[str]: + if self.revision is None: + return [] + else: + return [str(self.revision)] + @dataclass class RegistryPackage(Package): package: str - version: Union[str, List[str]] + version: Union[RawVersion, List[RawVersion]] + + def get_versions(self) -> List[str]: + if isinstance(self.version, list): + return [str(v) for v in self.version] + else: + return [str(self.version)] PackageSpec = Union[LocalPackage, GitPackage, RegistryPackage] diff --git a/core/dbt/deps/git.py b/core/dbt/deps/git.py index 238ac754703..8d77775f654 100644 --- a/core/dbt/deps/git.py +++ b/core/dbt/deps/git.py @@ -105,7 +105,7 @@ def __init__( def from_contract( cls, contract: GitPackage ) -> 'GitUnpinnedPackage': - revisions = [contract.revision] if contract.revision else [] + revisions = contract.get_revisions() # we want to map None -> True warn_unpinned = contract.warn_unpinned is not False diff --git a/core/dbt/deps/registry.py b/core/dbt/deps/registry.py index 5f6b05f6d1b..4f98ce9ccab 100644 --- a/core/dbt/deps/registry.py +++ b/core/dbt/deps/registry.py @@ -85,9 +85,7 @@ def _check_in_index(self): def from_contract( cls, contract: RegistryPackage ) -> 'RegistryUnpinnedPackage': - raw_version = contract.version - if isinstance(raw_version, str): - raw_version = [raw_version] + raw_version = contract.get_versions() versions = [ semver.VersionSpecifier.from_version_string(v) diff --git a/test/integration/006_simple_dependency_test/test_simple_dependency.py b/test/integration/006_simple_dependency_test/test_simple_dependency.py index 51422d6c8f9..837590c0265 100644 --- a/test/integration/006_simple_dependency_test/test_simple_dependency.py +++ b/test/integration/006_simple_dependency_test/test_simple_dependency.py @@ -26,7 +26,7 @@ def packages_config(self): "packages": [ { 'git': 'https://github.com/fishtown-analytics/dbt-integration-project', - 'revision': 'dbt/0.17.0', + 'revision': '1.0', } ] }