Skip to content

feat: add --fresh flag to recreate environments from scratch - #2356

Open
parasraju wants to merge 1 commit into
pypa:masterfrom
parasraju:fresh-env-flag
Open

feat: add --fresh flag to recreate environments from scratch#2356
parasraju wants to merge 1 commit into
pypa:masterfrom
parasraju:fresh-env-flag

Conversation

@parasraju

Copy link
Copy Markdown

Description

Add a --fresh flag to hatch env run that removes and recreates the environment before running commands. Also supports the HATCH_FRESH environment variable.

Related Issue

Closes #2138

Changes

  • src/hatch/config/constants.py: Added FRESH = "HATCH_FRESH" env var constant
  • src/hatch/cli/env/run.py: Added --fresh Click option to hatch env run, pass through to runner context
  • src/hatch/cli/application.py: Threaded resh parameter through
    unner_context() and prepare_environment()
  • src/hatch/project/core.py: If resh=True and environment exists, remove it and reset metadata before recreation
  • ests/cli/env/test_run.py: Added est_fresh test

Usage

hatch env run --fresh ENV:command

Or via environment variable:
HATCH_FRESH=1 hatch run ENV:command

Add a --fresh flag to 'hatch env run' that removes and recreates
the environment before running commands. Also supports the
HATCH_FRESH environment variable.

Closes pypa#2138
@cjames23

Copy link
Copy Markdown
Member

We have a new set of commands under dep for lockfiles that should be reused here, specifically hatch dep sync. I am generally not a fan of a flag for full recreation of venvs like this because the use cases are typically you just want to take which ever dependencies have updates instead of a new full graph resolution and IO for downloads. I would be okay with adding a flag to hatch dep sync that does not require a lock file for syncing the environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add flag for fresh Environment

2 participants