Skip to content

Commit

Permalink
Merge branch 'master' into feat-support-update-static-version
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 authored Oct 28, 2024
2 parents 8c2337a + 9650a1d commit 13af7c1
Show file tree
Hide file tree
Showing 91 changed files with 3,251 additions and 1,452 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-hatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
path: dist

- name: Push Python artifacts to PyPI
uses: pypa/gh-action-pypi-publish@v1.8.14
uses: pypa/gh-action-pypi-publish@v1.9.0
with:
skip-existing: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-hatchling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ jobs:
path: dist

- name: Push build artifacts to PyPI
uses: pypa/gh-action-pypi-publish@v1.8.14
uses: pypa/gh-action-pypi-publish@v1.9.0
with:
skip-existing: true
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -57,6 +57,7 @@ jobs:
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: coverage-${{ matrix.os }}-${{ matrix.python-version }}
path: .coverage*

Expand Down Expand Up @@ -114,7 +115,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions backend/src/hatchling/builders/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class CustomBuilder(Generic[PluginManagerBound]):
PLUGIN_NAME = 'custom'

def __new__( # type: ignore
def __new__( # type: ignore[misc]
cls,
root: str,
plugin_manager: PluginManagerBound | None = None,
Expand Down Expand Up @@ -45,7 +45,7 @@ def __new__( # type: ignore
message = f'Build script does not exist: {build_script}'
raise OSError(message)

hook_class = load_plugin_from_script(path, build_script, BuilderInterface, 'builder') # type: ignore
hook_class = load_plugin_from_script(path, build_script, BuilderInterface, 'builder') # type: ignore[type-abstract]
hook = hook_class(root, plugin_manager=plugin_manager, config=config, metadata=metadata, app=app)

# Always keep the name to avoid confusion
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/builders/hooks/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class CustomBuildHook:
PLUGIN_NAME = 'custom'

def __new__( # type: ignore
def __new__( # type: ignore[misc]
cls,
root: str,
config: dict[str, Any],
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/builders/hooks/plugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

@hookimpl
def hatch_register_build_hook() -> list[type[BuildHookInterface]]:
return [CustomBuildHook, VersionBuildHook] # type: ignore
return [CustomBuildHook, VersionBuildHook] # type: ignore[list-item]
2 changes: 1 addition & 1 deletion backend/src/hatchling/builders/plugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

@hookimpl
def hatch_register_builder() -> list[type[BuilderInterface]]:
return [AppBuilder, BinaryBuilder, CustomBuilder, SdistBuilder, WheelBuilder] # type: ignore
return [AppBuilder, BinaryBuilder, CustomBuilder, SdistBuilder, WheelBuilder] # type: ignore[list-item]
4 changes: 2 additions & 2 deletions backend/src/hatchling/cli/dep/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def dependencies_in_sync(
if sys_path is None:
sys_path = sys.path
if environment is None:
environment = default_environment() # type: ignore
environment = default_environment() # type: ignore[assignment]

installed_distributions = DistributionCache(sys_path)
return all(dependency_in_sync(requirement, environment, installed_distributions) for requirement in requirements) # type: ignore
return all(dependency_in_sync(requirement, environment, installed_distributions) for requirement in requirements) # type: ignore[arg-type]
4 changes: 2 additions & 2 deletions backend/src/hatchling/metadata/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class CustomMetadataHook:
PLUGIN_NAME = 'custom'

def __new__( # type: ignore
def __new__( # type: ignore[misc]
cls,
root: str,
config: dict[str, Any],
Expand All @@ -32,7 +32,7 @@ def __new__( # type: ignore
message = f'Build script does not exist: {build_script}'
raise OSError(message)

hook_class = load_plugin_from_script(path, build_script, MetadataHookInterface, 'metadata_hook') # type: ignore
hook_class = load_plugin_from_script(path, build_script, MetadataHookInterface, 'metadata_hook') # type: ignore[type-abstract]
hook = hook_class(root, config, *args, **kwargs)

# Always keep the name to avoid confusion
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/metadata/plugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

@hookimpl
def hatch_register_metadata_hook() -> type[MetadataHookInterface]:
return CustomMetadataHook # type: ignore
return CustomMetadataHook # type: ignore[return-value]
2 changes: 1 addition & 1 deletion backend/src/hatchling/metadata/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def project_metadata_from_core_metadata(core_metadata: str) -> dict[str, Any]:
header_registry = HeaderRegistry()

message = email.message_from_string(core_metadata)
metadata = {}
metadata: dict[str, Any] = {}

if name := message.get('Name'):
metadata['name'] = name
Expand Down
4 changes: 2 additions & 2 deletions backend/src/hatchling/plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def load_plugin_from_script(path: str, script_name: str, plugin_class: type[T],
from importlib.util import module_from_spec, spec_from_file_location

spec = spec_from_file_location(script_name, path)
module = module_from_spec(spec) # type: ignore
spec.loader.exec_module(module) # type: ignore
module = module_from_spec(spec) # type: ignore[arg-type]
spec.loader.exec_module(module) # type: ignore[union-attr]

plugin_finder = f'get_{plugin_id}'
names = dir(module)
Expand Down
4 changes: 4 additions & 0 deletions backend/src/hatchling/utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
DEFAULT_BUILD_SCRIPT = 'hatch_build.py'
DEFAULT_CONFIG_FILE = 'hatch.toml'


class VersionEnvVars:
VALIDATE_BUMP = 'HATCH_VERSION_VALIDATE_BUMP'
2 changes: 1 addition & 1 deletion backend/src/hatchling/version/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def read(self, *, pattern: str | bool) -> str:
return self.__cached_read_data[0]

def set_version(self, version: str) -> None:
_old_version, file_contents, (start, end) = self.__cached_read_data # type: ignore
_old_version, file_contents, (start, end) = self.__cached_read_data # type: ignore[misc]
with open(self.__path, 'w', encoding='utf-8') as f:
f.write(f'{file_contents[:start]}{version}{file_contents[end:]}')

Expand Down
30 changes: 28 additions & 2 deletions backend/src/hatchling/version/scheme/plugin/interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

import os
from abc import ABC, abstractmethod
from functools import cached_property


class VersionSchemeInterface(ABC): # no cov
Expand Down Expand Up @@ -51,9 +53,33 @@ def config(self) -> dict:
"""
return self.__config

@cached_property
def validate_bump(self) -> bool:
"""
This is the value of the `validate-bump` option, with the `HATCH_VERSION_VALIDATE_BUMP`
environment variable taking precedence. Validation is enabled by default.
```toml config-example
[tool.hatch.version]
validate-bump = true
```
"""
from hatchling.utils.constants import VersionEnvVars

if VersionEnvVars.VALIDATE_BUMP in os.environ:
return os.environ[VersionEnvVars.VALIDATE_BUMP] not in {'false', '0'}

validate_bump = self.config.get('validate-bump', True)
if not isinstance(validate_bump, bool):
message = 'option `validate-bump` must be a boolean'
raise TypeError(message)

return validate_bump

@abstractmethod
def update(self, desired_version: str, original_version: str, version_data: dict) -> str:
"""
This should return a normalized form of the desired version and verify that it
is higher than the original version.
This should return a normalized form of the desired version. If the
[validate_bump](reference.md#hatchling.version.scheme.plugin.interface.VersionSchemeInterface.validate_bump)
property is `True`, this method should also verify that the version is higher than the original version.
"""
2 changes: 1 addition & 1 deletion backend/src/hatchling/version/scheme/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def update(
raise ValueError(message)

next_version = Version(version)
if self.config.get('validate-bump', True) and next_version <= original:
if self.validate_bump and next_version <= original:
message = f'Version `{version}` is not higher than the original version `{original_version}`'
raise ValueError(message)

Expand Down
4 changes: 2 additions & 2 deletions backend/src/hatchling/version/source/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def get_version_data(self) -> dict:
absolute_search_paths.append(os.path.normpath(os.path.join(self.root, search_path)))

spec = spec_from_file_location(os.path.splitext(path)[0], path)
module = module_from_spec(spec) # type: ignore
module = module_from_spec(spec) # type: ignore[arg-type]

old_search_paths = list(sys.path)
try:
sys.path[:] = [*absolute_search_paths, *old_search_paths]
spec.loader.exec_module(module) # type: ignore
spec.loader.exec_module(module) # type: ignore[union-attr]
finally:
sys.path[:] = old_search_paths

Expand Down
4 changes: 2 additions & 2 deletions docs/blog/posts/release-hatch-160.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Hatch [v1.6.0](https://github.com/pypa/hatch/releases/tag/hatch-v1.6.0) brings i

## Build environments

Originally, the environment interface method for [providing builder sub-environments](../../plugins/environment/reference.md#hatch.env.plugin.interface.EnvironmentInterface.build_environment) was intended to be used in conjunction with some cleanup logic in order to provide a fresh setup every time. However, this is unnecessary in practice because build dependencies rarely change.
Originally, the environment interface method for providing builder sub-environments was intended to be used in conjunction with some cleanup logic in order to provide a fresh setup every time. However, this is unnecessary in practice because build dependencies rarely change.

Without caching, repeat build environment use is slow which affects the following scenarios:

- the [`build`](../../cli/reference.md#hatch-build) command
- commands that read project metadata, like [`dep hash`](../../cli/reference.md#hatch-dep-hash), if any fields are [set dynamically](../../config/metadata.md#dynamic)

Now a new environment interface method [`build_environment_exists`](../../plugins/environment/reference.md#hatch.env.plugin.interface.EnvironmentInterface.build_environment_exists) is used by Hatch to determine whether or not it has already been created, for implementations that have a caching mechanism.
Now a new environment interface method `build_environment_exists` is used by Hatch to determine whether or not it has already been created, for implementations that have a caching mechanism.

The [`virtual`](../../plugins/environment/virtual.md) environment type now uses this method to cache build environments.

Expand Down
17 changes: 9 additions & 8 deletions docs/community/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The usual process to make a contribution is to:
1. Check for existing related issues
2. Fork the repository and create a new branch
3. Make your changes
4. Make sure formatting, linting and tests passes.
4. Make sure formatting, linting and tests passes.
5. Add tests if possible to cover the lines you added.
6. Commit, and send a Pull Request.

Expand All @@ -15,41 +15,42 @@ Clone the `hatch` repository, `cd` into it, and create a new branch for your con

```bash
cd hatch
git checkout -b add-my-contribution
git switch -c add-my-contribution
```

## Run the tests

Run the test suite while developing:

```bash
hatch run dev
hatch test
```

Run the test suite with coverage report:

```bash
hatch run cov
hatch test --cover
```

Run the extended test suite with coverage:

```bash
hatch run full
hatch test --cover --all
```

## Lint

Run automated formatting:

```bash
hatch run lint:fmt
hatch fmt
```

Run full linting and type checking:

```bash
hatch run lint:all
hatch fmt --check
hatch run types:check
```

## Docs
Expand All @@ -64,4 +65,4 @@ Build and validate the documentation website:

```bash
hatch run docs:build-check
```
```
4 changes: 2 additions & 2 deletions docs/config/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ dev-mode-exact = true

A build target can be provided by any [builder plugin](../plugins/builder/reference.md). There are three built-in build targets: [wheel](../plugins/builder/wheel.md), [sdist](../plugins/builder/sdist.md), and [custom](../plugins/builder/custom.md).

### Dependencies
### Dependencies ### {: #target-dependencies }

You can specify additional dependencies that will be installed in each build environment, such as for third party builders:

Expand Down Expand Up @@ -283,7 +283,7 @@ or to specific build targets:
[tool.hatch.build.targets.<TARGET_NAME>.hooks.<HOOK_NAME>]
```

### Dependencies
### Dependencies ### {: #hook-dependencies }

You can specify additional dependencies that will be installed in each build environment, such as for third party build hooks:

Expand Down
39 changes: 39 additions & 0 deletions docs/config/internal/build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Build environment configuration

-----

You can fully alter the behavior of the environment used by the [`build`](../../cli/reference.md#hatch-build) command.

## Dependencies

Build environments will always have what is required by the [build system](../build.md#build-system), [targets](../build.md#target-dependencies), and [hooks](../build.md#hook-dependencies).

You can define [dependencies](../environment/overview.md#dependencies) that your builds may require in the environment as well:

```toml config-example
[tool.hatch.envs.hatch-build]
dependencies = [
"cython",
]
```

!!! warning "caution"
It's recommended to only use the standard mechanisms to define build dependencies for better compatibility with other tools.

## Environment variables

You can define [environment variables](../environment/overview.md#environment-variables) that will be set during builds:

```toml config-example
[tool.hatch.envs.hatch-build.env-vars]
SOURCE_DATE_EPOCH = "1580601600"
```

## Installer

By default, [UV is enabled](../../how-to/environment/select-installer.md). You may disable that behavior as follows:

```toml config-example
[tool.hatch.envs.hatch-build]
installer = "pip"
```
17 changes: 17 additions & 0 deletions docs/history/hatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

***Changed:***

- Environment type plugins are now no longer expected to support a pseudo-build environment as any environment now may be used for building. The following methods have been removed: `build_environment`, `build_environment_exists`, `run_builder`, `construct_build_command`

***Added:***

- The `version` and `project metadata` commands now support projects that do not use Hatchling as the build backend
- The `version` command accepts a `--force` option, allowing for downgrades when an explicit version number is given.
- Build environments can now be configured, the default build environment is `hatch-build`
- The environment interface now has the following methods and properties in order to better support builds on remote machines: `project_root`, `sep`, `pathsep`, `fs_context`

## [1.13.0](https://github.com/pypa/hatch/releases/tag/hatch-v1.13.0) - 2024-10-13 ## {: #hatch-v1.13.0 }

***Added:***

- Support managing Python 3.13 distributions

## [1.12.0](https://github.com/pypa/hatch/releases/tag/hatch-v1.12.0) - 2024-05-28 ## {: #hatch-v1.12.0 }

***Changed:***
Expand Down
Loading

0 comments on commit 13af7c1

Please sign in to comment.