From 59fef2a20deff1862788e5535ef2ba0a3b796ff5 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Mon, 22 Apr 2024 00:44:42 -0400 Subject: [PATCH] Various cleanups (#1416) --- .github/workflows/build-hatch.yml | 2 +- docs/blog/posts/release-hatch-1100.md | 6 +++--- docs/config/internal/static-analysis.md | 2 +- docs/config/internal/testing.md | 2 +- docs/history/hatch.md | 4 ++-- .../how-to/environment/dependency-resolution.md | 2 +- docs/how-to/environment/select-installer.md | 17 +++++++---------- docs/how-to/run/python-scripts.md | 4 ++-- docs/plugins/environment/virtual.md | 2 +- hatch.toml | 8 ++++---- pyproject.toml | 6 +++--- src/hatch/cli/run/__init__.py | 2 +- src/hatch/env/internal/build.py | 2 +- src/hatch/env/internal/static_analysis.py | 2 +- src/hatch/env/internal/test.py | 2 +- src/hatch/env/internal/uv.py | 2 +- src/hatch/env/virtual.py | 8 ++++++-- tests/cli/env/test_create.py | 4 ++-- 18 files changed, 39 insertions(+), 38 deletions(-) diff --git a/.github/workflows/build-hatch.yml b/.github/workflows/build-hatch.yml index ccda901e1..b710c44cf 100644 --- a/.github/workflows/build-hatch.yml +++ b/.github/workflows/build-hatch.yml @@ -87,7 +87,7 @@ jobs: CARGO: cargo CARGO_BUILD_TARGET: ${{ matrix.job.target }} PYAPP_REPO: pyapp - PYAPP_VERSION: "0.17.0" + PYAPP_VERSION: "0.18.0" PYAPP_UV_ENABLED: "true" PYAPP_PASS_LOCATION: "true" diff --git a/docs/blog/posts/release-hatch-1100.md b/docs/blog/posts/release-hatch-1100.md index d84bb6809..ac53bc06c 100644 --- a/docs/blog/posts/release-hatch-1100.md +++ b/docs/blog/posts/release-hatch-1100.md @@ -29,16 +29,16 @@ See the [tutorial](../../tutorials/testing/overview.md) for a detailed walk-thro ## UV -The package installer [UV](https://github.com/astral-sh/uv), brought to you by the same folks behind [Ruff](https://github.com/astral-sh/ruff), is now supported. In any environment, you can enable the `uv` option to use UV in place of [virtualenv](https://github.com/pypa/virtualenv) & [pip](https://github.com/pypa/pip) for virtual environment creation and dependency management, respectively. This often results in a significant performance benefit. +The package installer [UV](https://github.com/astral-sh/uv), brought to you by the same folks behind [Ruff](https://github.com/astral-sh/ruff), is now supported. In any environment, you can set the `installer` option to `uv` to use UV in place of [virtualenv](https://github.com/pypa/virtualenv) & [pip](https://github.com/pypa/pip) for virtual environment creation and dependency management, respectively. This often results in a significant performance benefit. For example, if you wanted to enable this functionality for the [default](../../config/environment/overview.md#inheritance) environment, you could set the following: ```toml config-example [tool.hatch.envs.default] -uv = true +installer = "uv" ``` -Semi-internal environments like those used for [testing](../../config/internal/testing.md) and [static analysis](../../config/internal/static-analysis.md) have this option enabled by default. +Semi-internal environments like those used for [testing](../../config/internal/testing.md) and [static analysis](../../config/internal/static-analysis.md) have this UV enabled by default. See the [how-to guide](../../how-to/environment/select-installer.md) for more information about switching the installer. diff --git a/docs/config/internal/static-analysis.md b/docs/config/internal/static-analysis.md index 7782e895d..f19f825e4 100644 --- a/docs/config/internal/static-analysis.md +++ b/docs/config/internal/static-analysis.md @@ -127,7 +127,7 @@ By default, [UV is enabled](../../how-to/environment/select-installer.md). You m ```toml config-example [tool.hatch.envs.hatch-static-analysis] -uv = false +installer = "pip" ``` ## Default settings diff --git a/docs/config/internal/testing.md b/docs/config/internal/testing.md index b8054ae4b..5eccc4ba4 100644 --- a/docs/config/internal/testing.md +++ b/docs/config/internal/testing.md @@ -113,5 +113,5 @@ By default, [UV is enabled](../../how-to/environment/select-installer.md). You m ```toml config-example [tool.hatch.envs.hatch-test] -uv = false +installer = "pip" ``` diff --git a/docs/history/hatch.md b/docs/history/hatch.md index b7171e0e7..b5894006a 100644 --- a/docs/history/hatch.md +++ b/docs/history/hatch.md @@ -28,8 +28,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Upgrade default CPython distributions to 20240415 - Upgrade default PyPy distributions to 7.3.15 - Upgrade Ruff to 0.4.1 -- Upgrade PyApp to 0.17.0 for binary builds -- Bump the minimum supported version of Hatchling to 1.24.1 +- Upgrade PyApp to 0.18.0 for binary builds +- Bump the minimum supported version of Hatchling to 1.24.2 ***Fixed:*** diff --git a/docs/how-to/environment/dependency-resolution.md b/docs/how-to/environment/dependency-resolution.md index 8b67d4912..7e6c928b4 100644 --- a/docs/how-to/environment/dependency-resolution.md +++ b/docs/how-to/environment/dependency-resolution.md @@ -14,7 +14,7 @@ PIP_EXTRA_INDEX_URL = "https://token:{env:GITLAB_API_TOKEN}@gitlab.com/api/v4/gr ## UV -If you're [using UV](select-installer.md), a different set of [environment variables](https://github.com/astral-sh/uv/tree/0.1.31#environment-variables) are available to configure its behavior. The previous example would look like this instead: +If you're [using UV](select-installer.md), a different set of [environment variables](https://github.com/astral-sh/uv/tree/0.1.35#environment-variables) are available to configure its behavior. The previous example would look like this instead: ```toml config-example [tool.hatch.envs.default.env-vars] diff --git a/docs/how-to/environment/select-installer.md b/docs/how-to/environment/select-installer.md index fa06d4897..e3d94b11a 100644 --- a/docs/how-to/environment/select-installer.md +++ b/docs/how-to/environment/select-installer.md @@ -9,15 +9,15 @@ The [virtual](../../plugins/environment/virtual.md) environment type by default !!! warning "caveat" UV is under active development and may not work for all dependencies. -To do so, enable the `uv` [option](../../plugins/environment/virtual.md#options). For example, if you wanted to enable this functionality for the [default](../../config/environment/overview.md#inheritance) environment, you could set the following: +To do so, set the `installer` [option](../../plugins/environment/virtual.md#options) to `uv`. For example, if you wanted to enable this functionality for the [default](../../config/environment/overview.md#inheritance) environment, you could set the following: ```toml config-example [tool.hatch.envs.default] -uv = true +installer = "uv" ``` !!! tip - All environments that enable UV will have the path to `uv` available as the `HATCH_UV` environment variable. + All environments that enable UV will have the path to UV available as the `HATCH_UV` environment variable. ## Configuring the version @@ -32,7 +32,7 @@ dependencies = [ ## Externally managed -If you want to manage UV yourself, you can expose it to Hatch by setting the `HATCH_ENV_TYPE_VIRTUAL_UV_PATH` environment variable which should be the absolute path to a UV binary for Hatch to use instead. This implicitly [enables](#enabling-uv) the `uv` option. +If you want to manage UV yourself, you can expose it to Hatch by setting the `HATCH_ENV_TYPE_VIRTUAL_UV_PATH` environment variable which should be the absolute path to a UV binary for Hatch to use instead. This implicitly [enables UV](#enabling-uv). ## Installer script alias @@ -40,14 +40,11 @@ If you have [scripts](../../config/environment/overview.md#scripts) or [commands ```toml config-example [[tool.hatch.envs.example.matrix]] -installer = ["uv", "pip"] +tool = ["uv", "pip"] [tool.hatch.envs.example.overrides] -matrix.installer.uv = [ - { value = true, if = ["uv"] }, - { value = false, if = ["pip"] }, -] -matrix.installer.scripts = [ +matrix.tool.installer = { value = "{matrix:tool}" } +matrix.tool.scripts = [ { key = "pip", value = "{env:HATCH_UV} pip {args}", if = ["uv"] }, ] ``` diff --git a/docs/how-to/run/python-scripts.md b/docs/how-to/run/python-scripts.md index b639915e5..84c71294b 100644 --- a/docs/how-to/run/python-scripts.md +++ b/docs/how-to/run/python-scripts.md @@ -57,12 +57,12 @@ Syncing dependencies ## Environment configuration -You may use the `[tool.hatch]` table directly to control the script's [environment](../../config/environment/overview.md). For example, if you wanted to disable UV (which is [enabled](../environment/select-installer.md) by default for scripts), you could add the following: +You may use the `[tool.hatch]` table directly to control the script's [environment](../../config/environment/overview.md). For example, if you wanted to disable UV (which is [enabled](../environment/select-installer.md#enabling-uv) by default for scripts), you could add the following: ```python tab="script.py" # /// script # ... # [tool.hatch] -# uv = false +# installer = "pip" # /// ``` diff --git a/docs/plugins/environment/virtual.md b/docs/plugins/environment/virtual.md index 1f350d756..50ca5aa04 100644 --- a/docs/plugins/environment/virtual.md +++ b/docs/plugins/environment/virtual.md @@ -21,7 +21,7 @@ type = "virtual" | `python-sources` | `['external', 'internal']` | This may be set to an array of strings that are either the literal `internal` or `external`. External considers only Python executables that are already on `PATH`. Internal considers only [internally managed Python distributions](#internal-distributions). | | `path` | | An explicit path to the virtual environment. The path may be absolute or relative to the project root. Any environments that [inherit](../../config/environment/overview.md#inheritance) this option will also use this path. The environment variable `HATCH_ENV_TYPE_VIRTUAL_PATH` may be used, which will take precedence. | | `system-packages` | `false` | Whether or not to give the virtual environment access to the system `site-packages` directory | -| `uv` | `false` | Whether or not to use [UV](https://github.com/astral-sh/uv) in place of virtualenv & pip for virtual environment creation and dependency management, respectively. If you intend to provide UV yourself, you may set the `HATCH_ENV_TYPE_VIRTUAL_UV_PATH` environment variable which should be the absolute path to a UV binary. This environment variable implicitly enables the `uv` option (if unset). | +| `installer` | `pip` | When set to `uv`, [UV](https://github.com/astral-sh/uv) will be used in place of virtualenv & pip for virtual environment creation and dependency management, respectively. If you intend to provide UV yourself, you may set the `HATCH_ENV_TYPE_VIRTUAL_UV_PATH` environment variable which should be the absolute path to a UV binary. This environment variable implicitly sets the `installer` option to `uv` (if unset). | ## Location diff --git a/hatch.toml b/hatch.toml index 90d95223d..cd416b3cd 100644 --- a/hatch.toml +++ b/hatch.toml @@ -2,7 +2,7 @@ config-path = "ruff_defaults.toml" [envs.default] -uv = true +installer = "uv" post-install-commands = [ "uv pip install {verbosity:flag:-1} -e ./backend", ] @@ -90,7 +90,7 @@ build-check = [ [envs.backend] detached = true -uv = true +installer = "uv" dependencies = [ "build~=0.7.0", "httpx", @@ -104,7 +104,7 @@ version = "cd backend && hatch version {args}" [envs.upkeep] detached = true -uv = true +installer = "uv" dependencies = [ "httpx", "ruff", @@ -126,7 +126,7 @@ update-ruff = [ [envs.release] detached = true -uv = true +installer = "uv" dependencies = [ "hatchling", ] diff --git a/pyproject.toml b/pyproject.toml index b481a5988..fcf5ea375 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["hatchling>=1.24.1", "hatch-vcs>=0.3.0"] +requires = ["hatchling>=1.24.2", "hatch-vcs>=0.3.0"] build-backend = "hatchling.build" [project] @@ -39,7 +39,7 @@ classifiers = [ ] dependencies = [ "click>=8.0.6", - "hatchling>=1.24.1", + "hatchling>=1.24.2", "httpx>=0.22.0", "hyperlink>=21.0.0", "keyring>=23.5.0", @@ -51,7 +51,7 @@ dependencies = [ "tomli-w>=1.0", "tomlkit>=0.11.1", "userpath~=1.7", - "uv>=0.1.33", + "uv>=0.1.35", "virtualenv>=20.16.2", "zstandard<1", ] diff --git a/src/hatch/cli/run/__init__.py b/src/hatch/cli/run/__init__.py index 1842be7d8..388c76ffe 100644 --- a/src/hatch/cli/run/__init__.py +++ b/src/hatch/cli/run/__init__.py @@ -77,7 +77,7 @@ def run(ctx: click.Context, args: tuple[str, ...]): config = metadata.get('tool', {}).get('hatch', {}) config['skip-install'] = True - config.setdefault('uv', True) + config.setdefault('installer', 'uv') config.setdefault('dependencies', []) config['dependencies'].extend(metadata.get('dependencies', [])) diff --git a/src/hatch/env/internal/build.py b/src/hatch/env/internal/build.py index 3ae0f68c5..3442d4566 100644 --- a/src/hatch/env/internal/build.py +++ b/src/hatch/env/internal/build.py @@ -6,7 +6,7 @@ def get_default_config() -> dict[str, Any]: return { 'skip-install': True, - 'uv': True, + 'installer': 'uv', 'dependencies': ['build[virtualenv]>=1.0.3'], 'scripts': { 'build-all': 'python -m build', diff --git a/src/hatch/env/internal/static_analysis.py b/src/hatch/env/internal/static_analysis.py index 78881a362..f441aa5dd 100644 --- a/src/hatch/env/internal/static_analysis.py +++ b/src/hatch/env/internal/static_analysis.py @@ -6,7 +6,7 @@ def get_default_config() -> dict[str, Any]: return { 'skip-install': True, - 'uv': True, + 'installer': 'uv', 'dependencies': [f'ruff=={RUFF_DEFAULT_VERSION}'], 'scripts': { 'format-check': 'ruff format{env:HATCH_FMT_ARGS:} --check --diff {args:.}', diff --git a/src/hatch/env/internal/test.py b/src/hatch/env/internal/test.py index 693b2b731..da2e650aa 100644 --- a/src/hatch/env/internal/test.py +++ b/src/hatch/env/internal/test.py @@ -5,7 +5,7 @@ def get_default_config() -> dict[str, Any]: return { - 'uv': True, + 'installer': 'uv', 'dependencies': [ 'coverage-enable-subprocess==1.0', 'coverage[toml]~=7.4', diff --git a/src/hatch/env/internal/uv.py b/src/hatch/env/internal/uv.py index 7d79b66db..10aac49c0 100644 --- a/src/hatch/env/internal/uv.py +++ b/src/hatch/env/internal/uv.py @@ -6,5 +6,5 @@ def get_default_config() -> dict[str, Any]: return { 'skip-install': True, - 'uv': True, + 'installer': 'uv', } diff --git a/src/hatch/env/virtual.py b/src/hatch/env/virtual.py index cb2669ba2..285edb32a 100644 --- a/src/hatch/env/virtual.py +++ b/src/hatch/env/virtual.py @@ -81,7 +81,11 @@ def __init__(self, *args, **kwargs): @cached_property def use_uv(self) -> bool: - return self.config.get('uv', bool(self.explicit_uv_path)) + return self.installer == 'uv' or bool(self.explicit_uv_path) + + @cached_property + def installer(self) -> str: + return self.config.get('installer', 'pip') @cached_property def explicit_uv_path(self) -> str: @@ -125,7 +129,7 @@ def uv_path(self) -> str: @staticmethod def get_option_types() -> dict: - return {'system-packages': bool, 'path': str, 'python-sources': list, 'uv': bool} + return {'system-packages': bool, 'path': str, 'python-sources': list, 'installer': str, 'uv-path': str} def activate(self): self.virtual_env.activate() diff --git a/tests/cli/env/test_create.py b/tests/cli/env/test_create.py index 1002edf0d..465aa7def 100644 --- a/tests/cli/env/test_create.py +++ b/tests/cli/env/test_create.py @@ -149,7 +149,7 @@ def test_uv_shipped(hatch, helpers, temp_dir, config_file): helpers.update_project_environment( project, 'default', - {'skip-install': True, 'uv': True, **project.config.envs['default']}, + {'skip-install': True, 'installer': 'uv', **project.config.envs['default']}, ) helpers.update_project_environment(project, 'test', {}) @@ -205,7 +205,7 @@ def test_uv_env(hatch, helpers, temp_dir, config_file): helpers.update_project_environment( project, 'default', - {'skip-install': True, 'uv': True, **project.config.envs['default']}, + {'skip-install': True, 'installer': 'uv', **project.config.envs['default']}, ) helpers.update_project_environment(project, 'hatch-uv', {'dependencies': ['uv>=0.1.31']}) helpers.update_project_environment(project, 'test', {})