Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when running pyodide build on an unsupported Python version #93

Open
agriyakhetarpal opened this issue Jan 24, 2025 · 1 comment

Comments

@agriyakhetarpal
Copy link
Member

I came across this one today.

Running pyodide build displays

───────────────────────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────────────────────╮
│ /Users/agriyakhetarpal/envs/skimage-dev/lib/python3.13/site-packages/pyodide_build/cli/build.py:180 in main                                          │
│                                                                                                                                                      │
│   177 │   ctx: typer.Context = typer.Context,  # type: ignore[assignment]                                                                            │
│   178 ) -> None:                                                                                                                                     │
│   179 │   """Use pypa/build to build a Python package from source, pypi or url."""                                                                   │
│ ❱ 180 │   init_environment()                                                                                                                         │
│   181 │   try:                                                                                                                                       │
│   182 │   │   check_emscripten_version()                                                                                                             │
│   183 │   except RuntimeError as e:                                                                                                                  │
│                                                                                                                                                      │
│ /Users/agriyakhetarpal/envs/skimage-dev/lib/python3.13/site-packages/pyodide_build/build_env.py:59 in init_environment                               │
│                                                                                                                                                      │
│    56 │                                                                                                                                              │
│    57 │   root = search_pyodide_root(Path.cwd())                                                                                                     │
│    58 │   if not root:  # Not in Pyodide tree                                                                                                        │
│ ❱  59 │   │   root = _init_xbuild_env(quiet=quiet)                                                                                                   │
│    60 │                                                                                                                                              │
│    61 │   os.environ["PYODIDE_ROOT"] = str(root)                                                                                                     │
│    62                                                                                                                                                │
│                                                                                                                                                      │
│ /Users/agriyakhetarpal/envs/skimage-dev/lib/python3.13/site-packages/pyodide_build/build_env.py:84 in _init_xbuild_env                               │
│                                                                                                                                                      │
│    81 │   with context:                                                                                                                              │
│    82 │   │   manager = CrossBuildEnvManager(xbuildenv_path)                                                                                         │
│    83 │   │   if manager.current_version is None:                                                                                                    │
│ ❱  84 │   │   │   manager.install()                                                                                                                  │
│    85 │   │                                                                                                                                          │
│    86 │   │   manager.check_version_marker()                                                                                                         │
│    87                                                                                                                                                │
│                                                                                                                                                      │
│ /Users/agriyakhetarpal/envs/skimage-dev/lib/python3.13/site-packages/pyodide_build/xbuildenv.py:175 in install                                       │
│                                                                                                                                                      │
│   172 │   │   │   version = _url_to_version(url)                                                                                                     │
│   173 │   │   │   download_url = url                                                                                                                 │
│   174 │   │   else:                                                                                                                                  │
│ ❱ 175 │   │   │   version = version or self._find_latest_version()                                                                                   │
│   176 │   │   │                                                                                                                                      │
│   177 │   │   │   local_versions = build_env.local_versions()                                                                                        │
│   178 │   │   │   release = self._find_remote_release(version)                                                                                       │
│                                                                                                                                                      │
│ /Users/agriyakhetarpal/envs/skimage-dev/lib/python3.13/site-packages/pyodide_build/xbuildenv.py:239 in _find_latest_version                          │
│                                                                                                                                                      │
│   236 │   │   )                                                                                                                                      │
│   237 │   │                                                                                                                                          │
│   238 │   │   if not latest:                                                                                                                         │
│ ❱ 239 │   │   │   raise ValueError("No compatible cross-build environment found")                                                                    │
│   240 │   │                                                                                                                                          │
│   241 │   │   return latest.version                                                                                                                  │
│   242                                                                                                                                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: No compatible cross-build environment found

and running pyodide xbuildenv install 0.27.2 gives

╭───────────────────────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────────────────────╮
│ /Users/agriyakhetarpal/envs/skimage-dev/lib/python3.13/site-packages/pyodide_build/cli/xbuildenv.py:61 in _install                                   │
│                                                                                                                                                      │
│    58 │   if url:                                                                                                                                    │
│    59 │   │   manager.install(url=url, force_install=force_install)                                                                                  │
│    60 │   else:                                                                                                                                      │
│ ❱  61 │   │   manager.install(version=version, force_install=force_install)                                                                          │
│    62 │                                                                                                                                              │
│    63 │   typer.echo(f"Pyodide cross-build environment installed at {path.resolve()}")                                                               │
│    64                                                                                                                                                │
│                                                                                                                                                      │
│ /Users/agriyakhetarpal/envs/skimage-dev/lib/python3.13/site-packages/pyodide_build/xbuildenv.py:183 in install                                       │
│                                                                                                                                                      │
│   180 │   │   │   │   python_version=local_versions["python"],                                                                                       │
│   181 │   │   │   │   pyodide_build_version=local_versions["pyodide-build"],                                                                         │
│   182 │   │   │   ):                                                                                                                                 │
│ ❱ 183 │   │   │   │   raise ValueError(                                                                                                              │
│   184 │   │   │   │   │   f"Version {version} is not compatible with the current environment."                                                       │
│   185 │   │   │   │   )                                                                                                                              │
│   186                                                                                                                                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Version 0.27.2 is not compatible with the current environment.

So, I checked the Python version and I got Python 3.13.1 (main, Dec 3 2024, 17:59:52) [Clang 16.0.0 (clang-1600.0.26.4)].

I feel that this could be reported better, somehow, perhaps through a simple check when running pyodide build, which sees if sys.version_info >= (3,12) and sys.version_info < (3, 13) returns True (or whichever the value of requires-python is in the metadata) and asks users to switch a supported Python version.

@ryanking13
Copy link
Member

+1. Thanks for opening the issue.

Also, I would like to remove the stack trace when it is an expected error. The long stack trace is very confusing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants