Repository: ray-project/ray
File: ci/build/build_wheel.py (Python)

Code before:
        rayciversion_path = root / ".rayciversion"
        if not rayciversion_path.exists():
            raise BuildError(f"Missing {rayciversion_path}")
        raymake_version = rayciversion_path.read_text().strip()
        manylinux_version = cls._parse_file(
            root / "rayci.env", r'MANYLINUX_VERSION=["\']?([^"\'\s]+)'
        )
        commit = cls._get_git_commit(root)

        return cls(
            python_version=python_version,
            output_dir=Path(output_dir),
            ray_root=root,
            hosttype=host,
            arch_suffix=suffix,
            wheel_platform=plat,
            raymake_version=raymake_version,
            manylinux_version=manylinux_version,
            commit=commit,
        )

    @staticmethod
    def _find_ray_root() -> Path:
        start = Path(__file__).resolve()
        for parent in [start, *start.parents]:
            if (parent / "rayci.env").exists():
                return parent
        if (Path.cwd() / "rayci.env").exists():
            return Path.cwd()
        raise BuildError("Could not find Ray root (missing rayci.env).")

    @staticmethod
    def _detect_platform() -> tuple[str, str, str]:
        sys_os = platform.system()
        m = platform.machine().lower()
        arch = (
            "x86_64"
            if m in ("amd64", "x86_64")
            else "aarch64"
            if m in ("arm64", "aarch64")
            else m
        )

        mapping = {
            ("Darwin", "aarch64"): ("aarch64", "-aarch64", "macosx_12_0_arm64"),
            ("Linux", "x86_64"): ("x86_64", "", "manylinux_2_17_x86_64"),
            ("Linux", "aarch64"): ("aarch64", "-aarch64", "manylinux_2_17_aarch64"),
        }
        if (sys_os, arch) not in mapping:
            raise BuildError(f"Unsupported platform: {sys_os}-{m}")
        return mapping[(sys_os, arch)]

Review comment (suggestion):
maybe find `.rayciversion` file instead, or maybe the `.git` directory? it is unclear that we will keep `rayci.env` at root dir. in fact, the `rayci.env` file might be better put under the `ci/` dir..

Code after:
        )
        commit = cls._get_git_commit(root)

        return cls(
            python_version=python_version,
            output_dir=Path(output_dir),
            ray_root=root,
            hosttype=host,
            arch_suffix=suffix,
            raymake_version=raymake_version,
            manylinux_version=manylinux_version,
            commit=commit,
        )

    @staticmethod
    def _find_ray_root() -> Path:
        start = Path(__file__).resolve()
        for parent in [start, *start.parents]:
            if (parent / ".rayciversion").exists():
                return parent
        if (Path.cwd() / ".rayciversion").exists():
            return Path.cwd()
        raise BuildError("Could not find Ray root (missing .rayciversion).")

    @staticmethod
    def _detect_platform() -> tuple[str, str]:
        """Return (hosttype, arch_suffix) for current platform."""
        sys_os = platform.system()
        m = platform.machine().lower()
        arch = (
            "x86_64"
            if m in ("amd64", "x86_64")
            else "aarch64"
            if m in ("arm64", "aarch64")
            else m
        )

        mapping = {
            ("Darwin", "aarch64"): ("aarch64", "-aarch64"),
            ("Linux", "x86_64"): ("x86_64", ""),
            ("Linux", "aarch64"): ("aarch64", "-aarch64"),
        }
        if (sys_os, arch) not in mapping:
            raise BuildError(f"Unsupported platform: {sys_os}-{m}")
        return mapping[(sys_os, arch)]

    @staticmethod
    def _parse_file(path: Path, pattern: str) -> str:
        if not path.exists():
            raise BuildError(f"Missing {path}")
        match = re.search(pattern, path.read_text(), re.M)