Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/actions/download…
Browse files Browse the repository at this point in the history
…-artifact-4
  • Loading branch information
ofek committed Mar 4, 2024
2 parents 3afeeae + e2ae3f6 commit 392ec29
Show file tree
Hide file tree
Showing 72 changed files with 1,355 additions and 362 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Wait for tests to succeed
uses: lewagon/[email protected].1
uses: lewagon/[email protected].3
with:
ref: ${{ github.ref }}
check-name: check
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/build-hatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
CARGO: cargo
CARGO_BUILD_TARGET: ${{ matrix.job.target }}
PYAPP_REPO: pyapp
PYAPP_VERSION: "0.11.1"
PYAPP_VERSION: "0.14.0"
PYAPP_PIP_EXTERNAL: "true"
PYAPP_PASS_LOCATION: "true"

Expand All @@ -106,12 +106,14 @@ jobs:
tar --strip-components=1 -xzf - -C $PYAPP_REPO
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install Hatch
run: pip install -e .
run: |-
pip install -e .
pip install -e ./backend
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
Expand Down Expand Up @@ -215,7 +217,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

Expand Down Expand Up @@ -285,7 +287,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

Expand Down Expand Up @@ -473,4 +475,4 @@ jobs:
installers/*
- name: Push Python artifacts to PyPI
uses: pypa/[email protected].11
uses: pypa/[email protected].12
2 changes: 1 addition & 1 deletion .github/workflows/build-hatchling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ jobs:
ls dist
# - name: Push build artifacts to PyPI
# uses: pypa/[email protected].11
# uses: pypa/[email protected].12
# with:
# skip-existing: true
2 changes: 1 addition & 1 deletion .github/workflows/docs-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'

Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python ${{ env.STABLE_PYTHON_VERSION }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.STABLE_PYTHON_VERSION }}

Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -147,7 +147,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python ${{ env.STABLE_PYTHON_VERSION }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.STABLE_PYTHON_VERSION }}

Expand All @@ -160,7 +160,9 @@ jobs:
run: pip install --upgrade flit poetry pipenv

- name: Install ourself
run: pip install .
run: |
pip install .
pip install ./backend
- name: Benchmark
run: |
Expand Down
1 change: 0 additions & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"editables>=0.3",
"packaging>=21.3",
"pathspec>=0.10.1",
"pluggy>=1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.21.0'
__version__ = '1.21.1'
8 changes: 5 additions & 3 deletions backend/src/hatchling/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ def get_requires_for_build_editable(config_settings: dict[str, Any] | None = Non
"""
https://peps.python.org/pep-0660/#get-requires-for-build-editable
"""
from hatchling.builders.constants import EDITABLES_REQUIREMENT
from hatchling.builders.wheel import WheelBuilder

builder = WheelBuilder(os.getcwd())
return builder.config.dependencies
return [*builder.config.dependencies, EDITABLES_REQUIREMENT]


def build_editable(
Expand Down Expand Up @@ -124,7 +125,8 @@ def prepare_metadata_for_build_editable(
"""
https://peps.python.org/pep-0660/#prepare-metadata-for-build-editable
"""
from hatchling.builders.wheel import EDITABLES_MINIMUM_VERSION, WheelBuilder
from hatchling.builders.constants import EDITABLES_REQUIREMENT
from hatchling.builders.wheel import WheelBuilder

builder = WheelBuilder(os.getcwd())

Expand All @@ -134,7 +136,7 @@ def prepare_metadata_for_build_editable(

extra_dependencies = []
if not builder.config.dev_mode_dirs and builder.config.dev_mode_exact:
extra_dependencies.append(f'editables~={EDITABLES_MINIMUM_VERSION}')
extra_dependencies.append(EDITABLES_REQUIREMENT)

with open(os.path.join(directory, 'METADATA'), 'w', encoding='utf-8') as f:
f.write(builder.config.core_metadata_constructor(builder.metadata, extra_dependencies=extra_dependencies))
Expand Down
8 changes: 4 additions & 4 deletions backend/src/hatchling/builders/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ def exclude_spec(self) -> pathspec.GitIgnoreSpec | None:

all_exclude_patterns = self.default_global_exclude()

if not self.ignore_vcs:
all_exclude_patterns.extend(self.load_vcs_exclusion_patterns())

exclude_patterns = exclude_config.get('exclude', self.default_exclude())
if not isinstance(exclude_patterns, list):
message = f'Field `{exclude_location}` must be an array of strings'
Expand All @@ -207,9 +210,6 @@ def exclude_spec(self) -> pathspec.GitIgnoreSpec | None:

all_exclude_patterns.append(exclude_pattern)

if not self.ignore_vcs:
all_exclude_patterns.extend(self.load_vcs_exclusion_patterns())

if all_exclude_patterns:
self.__exclude_spec = pathspec.GitIgnoreSpec.from_lines(all_exclude_patterns)

Expand Down Expand Up @@ -589,7 +589,7 @@ def dependencies(self) -> list[str]:
dependencies[dependency] = None

require_runtime_dependencies = self.require_runtime_dependencies
require_runtime_features = {feature: None for feature in self.require_runtime_features}
require_runtime_features = dict.fromkeys(self.require_runtime_features)
for hook_name, config in self.hook_config.items():
hook_require_runtime_dependencies = config.get('require-runtime-dependencies', False)
if not isinstance(hook_require_runtime_dependencies, bool):
Expand Down
3 changes: 3 additions & 0 deletions backend/src/hatchling/builders/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ class BuildEnvVars:
HOOK_ENABLE_PREFIX = 'HATCH_BUILD_HOOK_ENABLE_'
CLEAN = 'HATCH_BUILD_CLEAN'
CLEAN_HOOKS_AFTER = 'HATCH_BUILD_CLEAN_HOOKS_AFTER'


EDITABLES_REQUIREMENT = 'editables~=0.3'
2 changes: 1 addition & 1 deletion backend/src/hatchling/builders/plugin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


class IncludedFile:
__slots__ = ('path', 'relative_path', 'distribution_path')
__slots__ = ('distribution_path', 'path', 'relative_path')

def __init__(self, path: str, relative_path: str, distribution_path: str) -> None:
self.path = path
Expand Down
30 changes: 17 additions & 13 deletions backend/src/hatchling/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from hatchling.__about__ import __version__
from hatchling.builders.config import BuilderConfig
from hatchling.builders.constants import EDITABLES_REQUIREMENT
from hatchling.builders.plugin.interface import BuilderInterface
from hatchling.builders.utils import (
format_file_hash,
Expand All @@ -32,8 +33,6 @@
from hatchling.builders.plugin.interface import IncludedFile


EDITABLES_MINIMUM_VERSION = '0.3'

TIME_TUPLE = Tuple[int, int, int, int, int, int]


Expand Down Expand Up @@ -178,6 +177,7 @@ def default_file_selection_options(self) -> FileSelectionOptions:
if include or packages or only_include:
return FileSelectionOptions(include, exclude, packages, only_include)

project_names: set[str] = set()
for project_name in (
self.builder.normalize_file_name_component(self.builder.metadata.core.raw_name),
self.builder.normalize_file_name_component(self.builder.metadata.core.name),
Expand All @@ -192,7 +192,6 @@ def default_file_selection_options(self) -> FileSelectionOptions:

module_file = f'{project_name}.py'
if os.path.isfile(os.path.join(self.root, module_file)):
normalized_project_name = self.get_raw_fs_path_name(self.root, module_file)
return FileSelectionOptions([], exclude, [], [module_file])

from glob import glob
Expand All @@ -202,19 +201,24 @@ def default_file_selection_options(self) -> FileSelectionOptions:
relative_path = os.path.relpath(possible_namespace_packages[0], self.root)
namespace = relative_path.split(os.sep)[0]
return FileSelectionOptions([], exclude, [namespace], [])
project_names.add(project_name)

if self.bypass_selection or self.build_artifact_spec is not None or self.get_force_include():
self.set_exclude_all()
return FileSelectionOptions([], exclude, [], [])

project_names_text = ' or '.join(sorted(project_names))
message = (
'Unable to determine which files to ship inside the wheel using the following heuristics: '
'https://hatch.pypa.io/latest/plugins/builder/wheel/#default-file-selection\n\nAt least one '
'file selection option must be defined in the `tool.hatch.build.targets.wheel` table, see: '
'https://hatch.pypa.io/latest/config/build/\n\nAs an example, if you intend to ship a '
'directory named `foo` that resides within a `src` directory located at the root of your '
'project, you can define the following:\n\n[tool.hatch.build.targets.wheel]\n'
'packages = ["src/foo"]'
f'Unable to determine which files to ship inside the wheel using the following heuristics: '
f'https://hatch.pypa.io/latest/plugins/builder/wheel/#default-file-selection\n\n'
f'The most likely cause of this is that there is no directory that matches the name of your '
f'project ({project_names_text}).\n\n'
f'At least one file selection option must be defined in the `tool.hatch.build.targets.wheel` '
f'table, see: https://hatch.pypa.io/latest/config/build/\n\n'
f'As an example, if you intend to ship a directory named `foo` that resides within a `src` '
f'directory located at the root of your project, you can define the following:\n\n'
f'[tool.hatch.build.targets.wheel]\n'
f'packages = ["src/foo"]'
)
raise ValueError(message)

Expand Down Expand Up @@ -460,7 +464,7 @@ def build_editable_detection(self, directory: str, **build_data: Any) -> str:
try:
exposed_packages[distribution_module] = os.path.join(
self.root,
f'{relative_path[:relative_path.index(distribution_path)]}{distribution_module}',
f'{relative_path[: relative_path.index(distribution_path)]}{distribution_module}',
)
except ValueError:
message = (
Expand Down Expand Up @@ -495,7 +499,7 @@ def build_editable_detection(self, directory: str, **build_data: Any) -> str:
for raw_dependency in editable_project.dependencies():
dependency = raw_dependency
if dependency == 'editables':
dependency += f'~={EDITABLES_MINIMUM_VERSION}'
dependency = EDITABLES_REQUIREMENT
else: # no cov
pass

Expand Down Expand Up @@ -673,7 +677,7 @@ def get_best_matching_tag(self) -> str:
plat = tag_parts[2]
current_arch = platform.mac_ver()[2]
new_arch = 'universal2' if set(archs) == {'x86_64', 'arm64'} else archs[0]
tag_parts[2] = f'{plat[:plat.rfind(current_arch)]}{new_arch}'
tag_parts[2] = f'{plat[: plat.rfind(current_arch)]}{new_arch}'

if self.config.macos_max_compat:
import re
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/metadata/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def python_constraint(self) -> SpecifierSet:
return cast(SpecifierSet, self._python_constraint)

@property
def license(self) -> str: # noqa: A003
def license(self) -> str:
"""
https://peps.python.org/pep-0621/#license
"""
Expand Down
4 changes: 3 additions & 1 deletion backend/src/hatchling/ouroboros.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ def get_requires_for_build_editable( # type: ignore[no-redef]
"""
https://peps.python.org/pep-0660/#get-requires-for-build-editable
"""
return read_dependencies()
from hatchling.builders.constants import EDITABLES_REQUIREMENT

return [*read_dependencies(), EDITABLES_REQUIREMENT]
8 changes: 4 additions & 4 deletions backend/src/hatchling/plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@


def load_plugin_from_script(path: str, script_name: str, plugin_class: type[T], plugin_id: str) -> type[T]:
import importlib
from importlib.util import module_from_spec, spec_from_file_location

spec = importlib.util.spec_from_file_location(script_name, path) # type: ignore
module = importlib.util.module_from_spec(spec) # type: ignore
spec.loader.exec_module(module)
spec = spec_from_file_location(script_name, path)
module = module_from_spec(spec) # type: ignore
spec.loader.exec_module(module) # type: ignore

plugin_finder = f'get_{plugin_id}'
names = dir(module)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, root: str) -> None:

self.add_context(DefaultContextFormatter(self.__root))

def format(self, *args: Any, **kwargs: Any) -> str: # noqa: A003
def format(self, *args: Any, **kwargs: Any) -> str:
return self.__formatter.format(*args, **kwargs)

def add_context(self, context: DefaultContextFormatter) -> None:
Expand Down
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 @@ -93,6 +93,6 @@ def update_release(original_version: Version, new_release_parts: list[int]) -> t


def parse_letter_version(*args: Any, **kwargs: Any) -> tuple[str, int]:
from packaging.version import _parse_letter_version
from packaging.version import _parse_letter_version # noqa: PLC2701

return cast(Tuple[str, int], _parse_letter_version(*args, **kwargs))
8 changes: 4 additions & 4 deletions backend/src/hatchling/version/source/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class CodeSource(VersionSourceInterface):
PLUGIN_NAME = 'code'

def get_version_data(self) -> dict:
import importlib
import sys
from importlib.util import module_from_spec, spec_from_file_location

relative_path = self.config.get('path')
if not relative_path:
Expand Down Expand Up @@ -44,13 +44,13 @@ def get_version_data(self) -> dict:

absolute_search_paths.append(os.path.normpath(os.path.join(self.root, search_path)))

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

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

Expand Down
7 changes: 7 additions & 0 deletions docs/.hooks/title_from_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def on_page_content(
html, # noqa: ARG001
page,
**kwargs, # noqa: ARG001
):
if title := page._title_from_render: # noqa: SLF001
page.meta['title'] = title
Loading

0 comments on commit 392ec29

Please sign in to comment.