Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename configure-hasura command to hasura configure #104

Merged
merged 2 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ tortoise-orm = "0.17.5"
pydantic = "^1.8.1"
aiosignalrcore = "^0.9.2"
fcache = "^0.4.7"
click = "^8.0.1"
pyee = "^8.1.0"
APScheduler = "^3.7.0"
sentry-sdk = "^1.1.0"
Expand All @@ -39,6 +38,8 @@ aiolimiter = "^1.0.0-beta.1"
tabulate = "^0.8.9"
python-dotenv = "^0.18.0"
pytezos = {version = "^3.2.4", optional = true}
asyncclick = "^8.0.1"
anyio = "^3.2.1"

[tool.poetry.dev-dependencies]
black = "^20.8b1"
Expand Down
2 changes: 1 addition & 1 deletion src/demo_hic_et_nunc/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM dipdup/dipdup:2.0.0
FROM dipdup/dipdup:2.0.1
COPY demo_hic_et_nunc /home/dipdup/demo_hic_et_nunc
2 changes: 1 addition & 1 deletion src/demo_quipuswap/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM dipdup/dipdup:2.0.0
FROM dipdup/dipdup:2.0.1
COPY demo_quipuswap /home/dipdup/demo_quipuswap
2 changes: 1 addition & 1 deletion src/demo_registrydao/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM dipdup/dipdup:2.0.0
FROM dipdup/dipdup:2.0.1
COPY demo_registrydao /home/dipdup/demo_registrydao
2 changes: 1 addition & 1 deletion src/demo_tezos_domains/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM dipdup/dipdup:2.0.0
FROM dipdup/dipdup:2.0.1
COPY demo_tezos_domains /home/dipdup/demo_tezos_domains
2 changes: 1 addition & 1 deletion src/demo_tezos_domains_big_map/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM dipdup/dipdup:2.0.0
FROM dipdup/dipdup:2.0.1
COPY demo_tezos_domains_big_map /home/dipdup/demo_tezos_domains_big_map
2 changes: 1 addition & 1 deletion src/demo_tzbtc/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM dipdup/dipdup:2.0.0
FROM dipdup/dipdup:2.0.1
COPY demo_tzbtc /home/dipdup/demo_tzbtc
2 changes: 1 addition & 1 deletion src/demo_tzcolors/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM dipdup/dipdup:2.0.0
FROM dipdup/dipdup:2.0.1
COPY demo_tzcolors /home/dipdup/demo_tzcolors
2 changes: 1 addition & 1 deletion src/dipdup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
'0.1': False,
'1.0': False,
'1.1': True,
}
}
12 changes: 11 additions & 1 deletion src/dipdup/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import logging

from dipdup.cli import cli
from dipdup.exceptions import DipDupError

if __name__ == '__main__':
cli(prog_name='dipdup') # type: ignore
try:
cli(prog_name='dipdup', standalone_mode=False) # type: ignore
except KeyboardInterrupt:
pass
except DipDupError as e:
logging.critical(e.__repr__())
logging.info(e.format())
quit(e.exit_code)
69 changes: 26 additions & 43 deletions src/dipdup/cli.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,27 @@
import asyncio
import fileinput
import logging
import os
from dataclasses import dataclass
from functools import wraps
from os.path import dirname, exists, join
from typing import List, cast

import click
import asyncclick as click
import sentry_sdk
from dotenv import load_dotenv
from fcache.cache import FileCache # type: ignore
from sentry_sdk.integrations.aiohttp import AioHttpIntegration

from dipdup import __spec_version__, __version__, spec_version_mapping, spec_reindex_mapping
from dipdup import __spec_version__, __version__, spec_reindex_mapping, spec_version_mapping
from dipdup.codegen import DEFAULT_DOCKER_ENV_FILE, DEFAULT_DOCKER_IMAGE, DEFAULT_DOCKER_TAG, DipDupCodeGenerator
from dipdup.config import DipDupConfig, LoggingConfig, PostgresDatabaseConfig
from dipdup.dipdup import DipDup
from dipdup.exceptions import ConfigurationError, DipDupError, MigrationRequiredError
from dipdup.exceptions import ConfigurationError, MigrationRequiredError
from dipdup.hasura import HasuraGateway
from dipdup.utils import set_decimal_context, tortoise_wrapper

_logger = logging.getLogger('dipdup.cli')


def click_command_wrapper(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
try:
return asyncio.run(fn(*args, **kwargs))
except DipDupError as e:
_logger.critical(e.__repr__())
_logger.info(e.format())
quit(e.exit_code)

return wrapper


@dataclass
class CLIContext:
config_paths: List[str]
Expand All @@ -50,7 +35,6 @@ class CLIContext:
@click.option('--env-file', '-e', type=str, multiple=True, help='Path to .env file', default=[])
@click.option('--logging-config', '-l', type=str, help='Path to logging YAML config', default='logging.yml')
@click.pass_context
@click_command_wrapper
async def cli(ctx, config: List[str], env_file: List[str], logging_config: str):
try:
path = join(os.getcwd(), logging_config)
Expand Down Expand Up @@ -94,7 +78,6 @@ async def cli(ctx, config: List[str], env_file: List[str], logging_config: str):
@click.option('--reindex', is_flag=True, help='Drop database and start indexing from scratch')
@click.option('--oneshot', is_flag=True, help='Synchronize indexes wia REST and exit without starting WS connection')
@click.pass_context
@click_command_wrapper
async def run(ctx, reindex: bool, oneshot: bool) -> None:
config: DipDupConfig = ctx.obj.config
config.initialize()
Expand All @@ -104,7 +87,6 @@ async def run(ctx, reindex: bool, oneshot: bool) -> None:

@cli.command(help='Initialize new dipdup project')
@click.pass_context
@click_command_wrapper
async def init(ctx):
config: DipDupConfig = ctx.obj.config
config.pre_initialize()
Expand All @@ -114,7 +96,6 @@ async def init(ctx):

@cli.command(help='Migrate project to the new spec version')
@click.pass_context
@click_command_wrapper
async def migrate(ctx):
def _bump_spec_version(spec_version: str):
for config_path in ctx.obj.config_paths:
Expand All @@ -141,32 +122,12 @@ def _bump_spec_version(spec_version: str):

@cli.command(help='Clear development request cache')
@click.pass_context
@click_command_wrapper
async def clear_cache(ctx):
FileCache('dipdup', flag='cs').clear()


@cli.command(help='Configure Hasura GraphQL Engine')
@click.option('--reset', is_flag=True, help='Reset metadata before configuring')
@click.pass_context
@click_command_wrapper
async def configure_hasura(ctx, reset: bool):
config: DipDupConfig = ctx.obj.config
url = config.database.connection_string
models = f'{config.package}.models'
if not config.hasura:
_logger.error('`hasura` config section is empty')
return
hasura_gateway = HasuraGateway(config.package, config.hasura, cast(PostgresDatabaseConfig, config.database))

async with tortoise_wrapper(url, models):
async with hasura_gateway:
await hasura_gateway.configure(reset)


@cli.group()
@click.pass_context
@click_command_wrapper
async def docker(ctx):
...

Expand All @@ -176,7 +137,29 @@ async def docker(ctx):
@click.option('--tag', '-t', type=str, help='DipDup Docker tag', default=DEFAULT_DOCKER_TAG)
@click.option('--env-file', '-e', type=str, help='Path to env_file', default=DEFAULT_DOCKER_ENV_FILE)
@click.pass_context
@click_command_wrapper
async def docker_init(ctx, image: str, tag: str, env_file: str):
config: DipDupConfig = ctx.obj.config
await DipDupCodeGenerator(config, {}).generate_docker(image, tag, env_file)


@cli.group()
@click.pass_context
async def hasura(ctx):
...


@hasura.command(name='configure', help='Configure Hasura GraphQL Engine')
@click.option('--reset', is_flag=True, help='Reset metadata before configuring')
@click.pass_context
async def hasura_configure(ctx, reset: bool):
config: DipDupConfig = ctx.obj.config
url = config.database.connection_string
models = f'{config.package}.models'
if not config.hasura:
_logger.error('`hasura` config section is empty')
return
hasura_gateway = HasuraGateway(config.package, config.hasura, cast(PostgresDatabaseConfig, config.database))

async with tortoise_wrapper(url, models):
async with hasura_gateway:
await hasura_gateway.configure(reset)
3 changes: 2 additions & 1 deletion src/dipdup/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ def format_help(self) -> str:
)
message = _migration_required_message.format(version_table=version_table)
if self.reindex:
message += _tab +_reindexing_required_message
message += _tab + _reindexing_required_message
return message


class ReindexingRequiredError(DipDupError):
"""Performed migration requires reindexing"""

def format_help(self) -> str:
return _reindexing_required_message

Expand Down