diff --git a/CHANGELOG.md b/CHANGELOG.md index fd5fc5a2e..5438bfaee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,19 @@ Releases prior to 7.0 has been removed from this file to declutter search result ## [Unreleased] -### Fidex +### Added + +- cli: Added `init --no-base` option to skip creating the base template. +- env: Added `DIPDUP_NO_BASE` environment variable to skip creating the base template. + +### Fixed - cli: Fixed `new` command using incorrect template. +### Changed + +- cli: `init --base` option is now enabled by default. + ## [8.3.1] - 2025-04-08 ### Added diff --git a/Makefile b/Makefile index a868326ea..45d072ad4 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,7 @@ demos: ## Recreate demo projects from templates DIPDUP_NO_SYMLINK=1 python scripts/demos.py init ${DEMO} demos_refresh: - for demo in `ls src | grep demo | grep -v etherlink`; do cd src/$$demo && DIPDUP_NO_SYMLINK=1 dipdup init -b -f && cd ../..; done + for demo in `ls src | grep demo | grep -v etherlink`; do cd src/$$demo && DIPDUP_NO_SYMLINK=1 dipdup init --force && cd ../..; done before_release: ## Prepare for a new release after updating version in pyproject.toml make format lint update demos test docs diff --git a/docs/1.getting-started/1.installation.md b/docs/1.getting-started/1.installation.md index bebcb5a60..cfdf36296 100644 --- a/docs/1.getting-started/1.installation.md +++ b/docs/1.getting-started/1.installation.md @@ -36,7 +36,7 @@ make install source .venv/bin/activate ``` -If you prefer to use other package manager, edit `configs/replay.yaml` file and run `dipdup init -b -f`. +If you prefer to use other package manager, edit `configs/replay.yaml` file and run `dipdup init --force`. ## Docker diff --git a/docs/1.getting-started/4.package.md b/docs/1.getting-started/4.package.md index 88ae65239..1c6bf5ac8 100644 --- a/docs/1.getting-started/4.package.md +++ b/docs/1.getting-started/4.package.md @@ -39,7 +39,7 @@ When upgrading to a newer version of DipDup, particularly major releases, you ma To refresh your project package, run: ```shell [Terminal] -dipdup init -b -f +dipdup init --force make install ``` diff --git a/docs/12.faq.md b/docs/12.faq.md index d97d92a98..7f2b34afc 100644 --- a/docs/12.faq.md +++ b/docs/12.faq.md @@ -178,7 +178,7 @@ For historical reasons, Python package management is a mess. There are multiple Using PDM/Poetry is not required to run DipDup, but strongly recommended. Choosing one over the other is a matter of personal preference. _As of writing_, Poetry is [faster](https://lincolnloop.github.io/python-package-manager-shootout/), more popular, and has a nicer CLI, while PDM is more PEP-compatible and allows dependency overrides. -You can choose the preferred tool (or none) when initializing a project with `dipdup new` command. If you change your mind later, modify the `replay.yaml` file and run `dipdup init --base --force`. +You can choose the preferred tool (or none) when initializing a project with `dipdup new` command. If you change your mind later, modify the `replay.yaml` file and run `dipdup init --force`. ## Miscellaneous diff --git a/docs/5.advanced/2.environment-variables.md b/docs/5.advanced/2.environment-variables.md index f3ad47e7c..525e1c18a 100644 --- a/docs/5.advanced/2.environment-variables.md +++ b/docs/5.advanced/2.environment-variables.md @@ -19,6 +19,8 @@ DipDup uses multiple environment variables internally. They read once on process | `DIPDUP_MIGRATIONS` | Enable migrations with `aerich` | | `DIPDUP_NEXT` | Enable experimental features from the next major release that require schema changes | | `DIPDUP_NO_SYMLINK` | Don't create magic symlink in the package root even when used as cwd | +| `DIPDUP_NO_LINTER` | Don't format and lint generated files with ruff | +| `DIPDUP_NO_BASE` | Don't generate project template base | | `DIPDUP_NO_VERSION_CHECK` | Disable warning about running unstable or out-of-date DipDup version | | `DIPDUP_PACKAGE_PATH` | Disable package discovery and use the specified path | | `DIPDUP_REPLAY_PATH` | Path to datasource replay files; used in tests (dev only) | diff --git a/docs/7.references/1.cli.md b/docs/7.references/1.cli.md index d19218c3c..88c6eb574 100644 --- a/docs/7.references/1.cli.md +++ b/docs/7.references/1.cli.md @@ -190,7 +190,13 @@ Discord:
-b, --base
-

Include template base: pyproject.toml, Dockerfile, etc.

+

Include template base (default)

+
+ +
+
+-b, --no-base
+

Skip template base

diff --git a/docs/9.release-notes/1.v8.3.md b/docs/9.release-notes/1.v8.3.md index b5d762b85..241bd1c52 100644 --- a/docs/9.release-notes/1.v8.3.md +++ b/docs/9.release-notes/1.v8.3.md @@ -32,7 +32,7 @@ In this release, we've enhanced the integration: - Default project templates are configured to use `uv` by default - Better handling of dependencies and virtual environments -To switch to uv in existing projects, update your `configs/replay.yaml` and run `dipdup init -b -f`. +To switch to uv in existing projects, update your `configs/replay.yaml` and run `dipdup init --force`. ::banner{type="warning"} Note that `uv` build backend (see [#3957](https://github.com/astral-sh/uv/issues/3957), available separately as `uv_build` package) doesn't support non-standard layout of DipDup packages. Hatchling build backend handles both editable and non-editable builds correctly. @@ -56,7 +56,7 @@ Existing projects will continue to work with 8.3 without any modifications. If you want to use recent improvements like the MCP server, uv package manager, and Ruff formatter, refresh your project template: ```shell [Terminal] -dipdup init -b -f +dipdup init --force make install ``` diff --git a/docs/9.release-notes/_8.0_changelog.md b/docs/9.release-notes/_8.0_changelog.md index e0555feed..ea9876d8c 100644 --- a/docs/9.release-notes/_8.0_changelog.md +++ b/docs/9.release-notes/_8.0_changelog.md @@ -6,6 +6,7 @@ - cli: Added `--pre` flag to `self` group commands to install pre-release versions. - cli: Added `--raw` option to `config export` command to dump config preserving the original structure. - cli: Added `-C` option, a shorthand for `-c . -c configs/dipdup..yaml`. +- cli: Added `init --no-base` option to skip creating the base template. - cli: Added `package verify` command to check the package consistency. - cli: Added full project migration support for 3.0 spec. - cli: Added spec_version 3.0 support to `migrate` command. @@ -13,6 +14,7 @@ - database: Added `dipdup_status` view to the schema. - env: Added `DIPDUP_JSON_LOG` environment variable to enable JSON logging. - env: Added `DIPDUP_LOW_MEMORY` variable to reduce the size of caches and buffers. +- env: Added `DIPDUP_NO_BASE` environment variable to skip creating the base template. - env: Added `DIPDUP_PACKAGE_PATH` environment variable to override discovered package path. - package: Added built-in `batch` handler to modify higher-level indexing logic. - starknet.events: Added `starknet.events` index kind to process Starknet events. @@ -25,6 +27,7 @@ - cli: Don't save reports for successful test runs. - cli: Don't update existing installation in `self install` command unless asked to. - cli: Fixed `--pre` installer flag. +- cli: Fixed `new` command using incorrect template. - cli: Fixed env files not being loaded in some commands. - cli: Fixed errors raised when the project package is invalid. - cli: Fixed progress estimation when there are indexes with `last_level` option set. @@ -54,6 +57,7 @@ ### Changed - api: `/performance` endpoint response format has been changed. +- cli: `init --base` option is now enabled by default. - config: Index configs accept `datasources` list instead of `datasource` field. - config: Index kinds have been renamed and grouped by the network. - config: Index template values now can be any JSON-serializable object. diff --git a/src/dipdup/cli.py b/src/dipdup/cli.py index 4b0301b9d..8fab271bb 100644 --- a/src/dipdup/cli.py +++ b/src/dipdup/cli.py @@ -180,6 +180,9 @@ def wrapper(ctx: click.Context, *args: Any, **kwargs: Any) -> None: except (KeyboardInterrupt, asyncio.CancelledError): pass except Exception as e: + if isinstance(e, click.UsageError): + raise + from dipdup.report import save_report package = ctx.obj.config.package if ctx.obj else 'unknown' @@ -347,7 +350,8 @@ async def run(ctx: click.Context) -> None: @cli.command() @click.option('--force', '-f', is_flag=True, help='Overwrite existing types and ABIs.') -@click.option('--base', '-b', is_flag=True, help='Include template base: pyproject.toml, Dockerfile, etc.') +@click.option('--base', '-b', is_flag=True, help='Include template base (default)') +@click.option('--no-base', '-b', is_flag=True, help='Skip template base') @click.option('--no-linter', is_flag=True, help='Skip linter and formatter.') @click.argument( 'include', @@ -361,6 +365,7 @@ async def init( ctx: click.Context, force: bool, base: bool, + no_base: bool, no_linter: bool, include: list[str], ) -> None: @@ -370,12 +375,17 @@ async def init( """ from dipdup.dipdup import DipDup + if base: + if no_base: + raise click.BadParameter('You cannot use both `--base` and `--no-base` options at the same time') + _logger.warning('`--base` option became default; use `--no-base` to disable it') + config: DipDupConfig = ctx.obj.config dipdup = DipDup(config) await dipdup.init( force=force, - base=base or bool(include), + no_base=no_base or bool(include), no_linter=no_linter, include=set(include), ) @@ -416,9 +426,10 @@ async def migrate(ctx: click.Context, dry_run: bool) -> None: ) await _cli_unwrapper(init)( ctx=ctx, - base=True, + base=False, force=True, no_linter=True, + no_base=False, include=[], ) @@ -993,6 +1004,7 @@ async def new( base=False, force=force, no_linter=False, + no_base=False, include=[], ) diff --git a/src/dipdup/codegen/__init__.py b/src/dipdup/codegen/__init__.py index fb3ef6631..a1488fc31 100644 --- a/src/dipdup/codegen/__init__.py +++ b/src/dipdup/codegen/__init__.py @@ -84,14 +84,14 @@ def get_typeclass_name(self, schema_path: Path) -> str: ... async def init( self, force: bool = False, - base: bool = False, no_linter: bool = False, + no_base: bool = False, ) -> None: # NOTE: Package structure self._package.initialize() # NOTE: Common files - if base or self._include: + if not (env.NO_BASE or no_base): _logger.info('Recreating base template with replay.yaml') render_base( answers=self._package.replay, @@ -116,7 +116,7 @@ async def init( await self.generate_handlers() await self.generate_batch_handler() - if not env.NO_LINTER and not no_linter: + if not (env.NO_LINTER or no_linter): self._package.format_lint() async def generate_hooks(self) -> None: diff --git a/src/dipdup/dipdup.py b/src/dipdup/dipdup.py index 4f513dba8..1b850a751 100644 --- a/src/dipdup/dipdup.py +++ b/src/dipdup/dipdup.py @@ -655,8 +655,8 @@ def schema(self) -> Schema: async def init( self, force: bool = False, - base: bool = False, no_linter: bool = False, + no_base: bool = False, include: set[str] | None = None, ) -> None: """Create new or update existing dipdup project""" @@ -690,7 +690,7 @@ async def init( ) await codegen.init( force=force, - base=base, + no_base=no_base, no_linter=no_linter, ) diff --git a/src/dipdup/env.py b/src/dipdup/env.py index 58776f353..0b901a0f3 100644 --- a/src/dipdup/env.py +++ b/src/dipdup/env.py @@ -91,6 +91,7 @@ def reload_env() -> None: MIGRATIONS, \ NEXT, \ NO_LINTER, \ + NO_BASE, \ NO_SYMLINK, \ NO_VERSION_CHECK, \ PACKAGE_PATH, \ @@ -105,6 +106,7 @@ def reload_env() -> None: MIGRATIONS = get_bool('DIPDUP_MIGRATIONS') NEXT = get_bool('DIPDUP_NEXT') NO_LINTER = get_bool('DIPDUP_NO_LINTER') + NO_BASE = get_bool('DIPDUP_NO_BASE') NO_SYMLINK = get_bool('DIPDUP_NO_SYMLINK') NO_VERSION_CHECK = get_bool('DIPDUP_NO_VERSION_CHECK') PACKAGE_PATH = get_path('DIPDUP_PACKAGE_PATH') @@ -126,6 +128,7 @@ def set_test() -> None: MIGRATIONS: bool = get_bool('DIPDUP_MIGRATIONS') NEXT: bool = get_bool('DIPDUP_NEXT') NO_LINTER: bool = get_bool('DIPDUP_NO_LINTER') +NO_BASE: bool = get_bool('DIPDUP_NO_BASE') NO_SYMLINK: bool = get_bool('DIPDUP_NO_SYMLINK') NO_VERSION_CHECK: bool = get_bool('DIPDUP_NO_VERSION_CHECK') PACKAGE_PATH: Path | None = get_path('DIPDUP_PACKAGE_PATH')