Skip to content

Commit a684712

Browse files
Wizard1209Vladimir Bobrikovdroserasprout
authored
(2/2) Introduce spec_version 2.0 (#654)
Co-authored-by: Vladimir Bobrikov <[email protected]> Co-authored-by: Lev Gorodetskiy <[email protected]>
1 parent d82d5b6 commit a684712

File tree

5 files changed

+12
-63
lines changed

5 files changed

+12
-63
lines changed

src/dipdup/__init__.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,3 @@
77
# NOTE: Load version from package
88
__version__ = importlib.metadata.version('dipdup')
99
__spec_version__ = '1.2'
10-
11-
version = tuple(__version__.split('.'))
12-
major_version = version[0]
13-
minor_version = f'{version[0]}.{version[1]}'
14-
15-
spec_version_mapping = {
16-
'0.1': '<=0.4.3',
17-
'1.0': '>=1.0.0, <=1.1.2',
18-
'1.1': '>=2.0.0, <=2.0.9',
19-
'1.2': '>=3.0.0',
20-
}
21-
spec_reindex_mapping = {
22-
'0.1': False,
23-
'1.0': False,
24-
'1.1': True,
25-
'1.2': True,
26-
}

src/dipdup/cli.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515

1616
import asyncclick as click
1717

18-
from dipdup import __spec_version__
1918
from dipdup import __version__
2019
from dipdup import env
21-
from dipdup import spec_reindex_mapping
22-
from dipdup import spec_version_mapping
2320
from dipdup.utils.sys import IGNORE_CONFIG_CMDS
2421
from dipdup.utils.sys import set_up_logging
2522
from dipdup.utils.sys import set_up_process
@@ -159,7 +156,6 @@ async def cli(ctx: click.Context, config: list[str], env_file: list[str]) -> Non
159156
from dipdup.config import DipDupConfig
160157
from dipdup.exceptions import ConfigurationError
161158
from dipdup.exceptions import InitializationRequiredError
162-
from dipdup.exceptions import MigrationRequiredError
163159
from dipdup.sentry import init_sentry
164160

165161
_config = DipDupConfig.load(config_paths)
@@ -180,13 +176,6 @@ async def cli(ctx: click.Context, config: list[str], env_file: list[str]) -> Non
180176
except Exception as e:
181177
raise InitializationRequiredError(f'Failed to create a project package: {e}') from e
182178

183-
# NOTE: Ensure that `spec_version` is valid and supported
184-
if _config.spec_version not in spec_version_mapping:
185-
raise ConfigurationError(f'Unknown `spec_version`, correct ones: {", ".join(spec_version_mapping)}')
186-
if _config.spec_version != __spec_version__:
187-
reindex = spec_reindex_mapping[__spec_version__]
188-
raise MigrationRequiredError(_config.spec_version, __spec_version__, reindex)
189-
190179
@dataclass
191180
class CLIContext:
192181
config_paths: list[str]

src/dipdup/exceptions.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
from typing import Optional
99
from typing import Type
1010

11-
from tabulate import tabulate
1211
from tortoise.models import Model
1312

14-
from dipdup import spec_version_mapping
1513
from dipdup.enums import ReindexingReason
1614

1715
tab = ('_' * 80) + '\n\n'
@@ -161,37 +159,6 @@ def _help(self) -> str:
161159
"""
162160

163161

164-
@dataclass(repr=False)
165-
class MigrationRequiredError(Error):
166-
"""Project and DipDup spec versions don't match"""
167-
168-
from_: str
169-
to: str
170-
reindex: bool = False
171-
172-
def _help(self) -> str:
173-
version_table = tabulate(
174-
[
175-
['current', self.from_, spec_version_mapping[self.from_]],
176-
['required', self.to, spec_version_mapping[self.to]],
177-
],
178-
headers=['', 'spec_version', 'DipDup version'],
179-
)
180-
reindex = '\n\n' + tab + ReindexingRequiredError(ReindexingReason.migration).help() if self.reindex else ''
181-
return f"""
182-
Project migration required!
183-
184-
{version_table.strip()}
185-
186-
Perform the following actions:
187-
188-
1. Run `dipdup migrate`.
189-
2. Review and commit changes.
190-
191-
See https://docs.dipdup.io/release-notes for more information. {reindex}
192-
"""
193-
194-
195162
@dataclass(repr=False)
196163
class ReindexingRequiredError(Error):
197164
"""Unable to continue indexing with existing database"""

src/dipdup/project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pydantic import Field
1010
from tabulate import tabulate
1111

12-
from dipdup import major_version
12+
from dipdup import __version__
1313
from dipdup.exceptions import ConfigurationError
1414
from dipdup.utils.codegen import load_template
1515
from dipdup.utils.codegen import write
@@ -123,7 +123,7 @@ def prompt(self) -> str:
123123
class JinjaAnswers(dict[str, Any]):
124124
def __init__(self, *args: str, **kwargs: Any) -> None:
125125
super().__init__(*args, **kwargs)
126-
self['dipdup_version'] = major_version
126+
self['dipdup_version'] = __version__
127127

128128
def __getattr__(self, item: str) -> Any:
129129
return self[item]

src/dipdup/yaml.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from pydantic.json import pydantic_encoder
2626
from ruamel.yaml import YAML
2727

28+
from dipdup import __spec_version__
2829
from dipdup.exceptions import ConfigurationError
2930

3031
# NOTE: ${VARIABLE:-default} | ${VARIABLE}
@@ -105,6 +106,8 @@ def load(
105106

106107
config.update(yaml.load(path_yaml))
107108

109+
config.validate_version()
110+
108111
# FIXME: Can't use `from_` field alias in dataclass; fixed in dipdup.yaml instead
109112
# FIXME: See https://github.com/pydantic/pydantic/issues/4286
110113
fix_dataclass_field_aliases(config)
@@ -121,3 +124,10 @@ def dump(self) -> str:
121124
buffer = StringIO()
122125
yaml.dump(config_yaml, buffer)
123126
return buffer.getvalue()
127+
128+
def validate_version(self) -> None:
129+
config_spec_version = self['spec_version']
130+
if config_spec_version != __spec_version__:
131+
raise ConfigurationError(
132+
f'Incompatible spec version: expected {__spec_version__}, got {config_spec_version}. See https://docs.dipdup.io/config/spec_version'
133+
)

0 commit comments

Comments
 (0)