Skip to content

Commit 3e92570

Browse files
committed
Fix macOS installation by dynamically skipping legacy MaxText directory
1 parent 16b6848 commit 3e92570

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

build_hooks.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Custom build hooks for PyPI."""
1616

1717
import os
18+
import sys
1819
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
1920

2021
TPU_REQUIREMENTS_PATH = "src/dependencies/requirements/generated_requirements/tpu-requirements.txt"
@@ -33,9 +34,27 @@ def get_tpu_dependencies():
3334

3435

3536
class CustomBuildHook(BuildHookInterface):
36-
"""A custom hook to inject TPU dependencies into the core wheel dependencies."""
37+
"""A custom hook to handle platform-specific package configuration for MaxText."""
3738

3839
def initialize(self, version, build_data): # pylint: disable=unused-argument
39-
tpu_deps = get_tpu_dependencies()
40-
build_data["dependencies"] = tpu_deps
41-
print(f"Successfully injected {len(tpu_deps)} TPU dependencies into the wheel's core requirements.")
40+
"""Adjusts the build_data dictionary to customize the wheel's package structure."""
41+
# The following TPU dependency injection is disabled because TPU-specific requirements
42+
# are now managed via optional dependencies (extras) in pyproject.toml
43+
# (e.g., pip install maxtext[tpu]).
44+
# tpu_deps = get_tpu_dependencies()
45+
# build_data["dependencies"] = tpu_deps
46+
# print(f"Successfully injected {len(tpu_deps)} TPU dependencies into the wheel's core requirements.")
47+
48+
# macOS specific logic to avoid case-sensitivity issues with MaxText and maxtext directories
49+
build_data["force_include"] = build_data.get("force_include", {})
50+
if sys.platform == "darwin":
51+
print("macOS detected. Skipping legacy MaxText shims to avoid case-sensitivity conflicts.")
52+
# Always include the __init__.py in the lowercase 'maxtext' package on macOS.
53+
# This ensures that 'import maxtext' (and thus 'import MaxText' on macOS)
54+
# has the proper version and metadata.
55+
build_data["force_include"]["src/MaxText/__init__.py"] = "maxtext/__init__.py"
56+
else:
57+
# On other platforms, include 'src/MaxText' as its own top-level package for legacy support.
58+
# We do NOT add __init__.py to 'maxtext' here to maintain exact parity with previous builds.
59+
print("Included src/MaxText as a top-level package for non-macOS platforms.")
60+
build_data["force_include"]["src/MaxText"] = "MaxText"

docs/install_maxtext.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ uv pip install maxtext[runner] --resolution=lowest
6161
6262
> **Note:** The maxtext package contains a comprehensive list of all direct and transitive dependencies, with lower bounds, generated by [seed-env](https://github.com/google-ml-infra/actions/tree/main/python_seed_env). We highly recommend the `--resolution=lowest` flag. It instructs `uv` to install the specific, tested versions of dependencies defined by MaxText, rather than the latest available ones. This ensures a consistent and reproducible environment, which is critical for stable performance and for running benchmarks.
6363
64+
> **Note:** MaxText is only tested on Linux during releases.
65+
6466
## From Source
6567

6668
If you plan to contribute to MaxText or need the latest unreleased features, install from source.

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ Repository = "https://github.com/AI-Hypercomputer/maxtext.git"
4040
allow-direct-references = true
4141

4242
[tool.hatch.build.targets.wheel]
43-
packages = ["src/MaxText", "src/maxtext", "src/dependencies"]
43+
packages = ["src/maxtext", "src/dependencies"]
4444

45-
# TODO: Add this hook back when it handles device-type parsing
46-
# [tool.hatch.build.targets.wheel.hooks.custom]
47-
# path = "build_hooks.py"
45+
[tool.hatch.build.targets.wheel.hooks.custom]
46+
path = "build_hooks.py"
4847

4948
[project.scripts]
5049
install_maxtext_tpu_github_deps = "dependencies.github_deps.install_pre_train_deps:main"

0 commit comments

Comments
 (0)