Skip to content

Commit ddc6929

Browse files
Add option to specify env files, fix index config hash validation (#99)
1 parent cdf8dbb commit ddc6929

File tree

5 files changed

+47
-25
lines changed

5 files changed

+47
-25
lines changed

poetry.lock

Lines changed: 29 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ sentry-sdk = "^1.1.0"
3737
pyhumps = "^3.0.2"
3838
aiolimiter = "^1.0.0-beta.1"
3939
tabulate = "^0.8.9"
40+
python-dotenv = "^0.18.0"
4041
pytezos = {version = "^3.2.4", optional = true}
4142

4243
[tool.poetry.dev-dependencies]

src/dipdup/cli.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
import os
55
from dataclasses import dataclass
66
from functools import wraps
7-
from os.path import dirname, join
7+
from os.path import dirname, exists, join
88
from typing import List, cast
99

1010
import click
1111
import sentry_sdk
12+
from dotenv import load_dotenv
1213
from fcache.cache import FileCache # type: ignore
1314
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
1415

@@ -46,10 +47,11 @@ class CLIContext:
4647
@click.group()
4748
@click.version_option(__version__)
4849
@click.option('--config', '-c', type=str, multiple=True, help='Path to dipdup YAML config', default=['dipdup.yml'])
50+
@click.option('--env-file', '-e', type=str, multiple=True, help='Path to .env file', default=[])
4951
@click.option('--logging-config', '-l', type=str, help='Path to logging YAML config', default='logging.yml')
5052
@click.pass_context
5153
@click_command_wrapper
52-
async def cli(ctx, config: List[str], logging_config: str):
54+
async def cli(ctx, config: List[str], env_file: List[str], logging_config: str):
5355
try:
5456
path = join(os.getcwd(), logging_config)
5557
_logging_config = LoggingConfig.load(path)
@@ -58,6 +60,13 @@ async def cli(ctx, config: List[str], logging_config: str):
5860
_logging_config = LoggingConfig.load(path)
5961
_logging_config.apply()
6062

63+
for env_path in env_file:
64+
env_path = join(os.getcwd(), env_path)
65+
if not exists(env_path):
66+
raise ConfigurationError(f'env file `{env_path}` does not exist')
67+
_logger.info('Applying env_file `%s`', env_path)
68+
load_dotenv(env_path, override=True)
69+
6170
_config = DipDupConfig.load(config)
6271
if _config.spec_version not in spec_version_mapping:
6372
raise ConfigurationError('Unknown `spec_version`, correct ones: {}')

src/dipdup/config.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,9 @@ def __post_init_post_parse__(self) -> None:
517517
NameMixin.__post_init_post_parse__(self)
518518

519519
def hash(self) -> str:
520-
return hashlib.sha256(
521-
json.dumps(
522-
self,
523-
default=pydantic_encoder,
524-
).encode(),
525-
).hexdigest()
520+
config_json = json.dumps(self, default=pydantic_encoder)
521+
config_hash = hashlib.sha256(config_json.encode()).hexdigest()
522+
return config_hash
526523

527524
@property
528525
def datasource_config(self) -> TzktDatasourceConfig:

src/dipdup/index.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async def _process_queue(self) -> None:
7676

7777
async def _initialize_index_state(self) -> None:
7878
self._logger.info('Getting state for index `%s`', self._config.name)
79-
index_hash = self._config.hash()
79+
index_config_hash = self._config.hash()
8080
state = await State.get_or_none(
8181
index_name=self._config.name,
8282
index_type=self._config.kind,
@@ -86,11 +86,11 @@ async def _initialize_index_state(self) -> None:
8686
state = state_cls(
8787
index_name=self._config.name,
8888
index_type=self._config.kind,
89-
index_hash=index_hash,
89+
index_hash=index_config_hash,
9090
level=self._config.first_block,
9191
)
9292

93-
elif state.hash != index_hash:
93+
elif state.index_hash != index_config_hash:
9494
self._logger.warning('Config hash mismatch (config has been changed), reindexing')
9595
await self._ctx.reindex()
9696

0 commit comments

Comments
 (0)