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

fix: Obtain default Python version for Python hub repo from versions.bzl file #138

Merged

Conversation

gfringeli
Copy link
Contributor

Issue

rules_python 1.0.0 removes the DEFAULT_PYTHON_VERSION constant from the Python hub repo's interpreters.bzl file. Instead, the version must be read from the versions.bzl file, introduced in rules_python 0.37.0.

As a result, creating a Python environment with rules_pycross (main branch) and rules_python 1.0.0 leads to the following error.

INFO: Repository rules_pycross++environments+pycross_environments_myproject instantiated at:
  <builtin>: in <toplevel>
Repository rule pycross_environments_repo defined at:
  /private/var/tmp/_bazel_gabriel/17eb730aec70ae18dde0e6ba1d906dff/external/rules_pycross+/pycross/private/toolchain_helpers.bzl:430:44: in <toplevel>
ERROR: /private/var/tmp/_bazel_gabriel/17eb730aec70ae18dde0e6ba1d906dff/external/rules_pycross+/pycross/private/toolchain_helpers.bzl:221:9: An error occurred during the fetch of repository 'rules_pycross++environments+pycross_environments_myproject':
   Traceback (most recent call last):
        File "/private/var/tmp/_bazel_gabriel/17eb730aec70ae18dde0e6ba1d906dff/external/rules_pycross+/pycross/private/toolchain_helpers.bzl", line 390, column 44, in _pycross_environment_repo_impl
                version_info = _get_python_version_info(rctx)
        File "/private/var/tmp/_bazel_gabriel/17eb730aec70ae18dde0e6ba1d906dff/external/rules_pycross+/pycross/private/toolchain_helpers.bzl", line 350, column 65, in _get_python_version_info
                default_version = _get_default_python_version_bzlmod(rctx, rctx.attr.pythons_hub_repo)
        File "/private/var/tmp/_bazel_gabriel/17eb730aec70ae18dde0e6ba1d906dff/external/rules_pycross+/pycross/private/toolchain_helpers.bzl", line 221, column 9, in _get_default_python_version_bzlmod
                fail("Unable to determine default version for python hub repo '{}'".format(pythons_hub_repo))
Error in fail: Unable to determine default version for python hub repo '@@rules_python++python+pythons_hub//:pythons_hub'
ERROR: Error loading '@@rules_pycross+//pycross/extensions:lock_repos.bzl' for module extensions, requested by /Users/gabriel/Desktop/projects/myproject/MODULE.bazel:49:27: at /private/var/tmp/_bazel_gabriel/17eb730aec70ae18dde0e6ba1d906dff/external/rules_pycross+/pycross/extensions/lock_repos.bzl:3:6: at /private/var/tmp/_bazel_gabriel/17eb730aec70ae18dde0e6ba1d906dff/external/rules_pycross+/pycross/private/bzlmod/lock_repos.bzl:5:6: Encountered error while reading extension file 'locks.bzl': no such package '@@rules_pycross++lock_import+lock_import_repos_hub//': no such package '@@rules_pycross++environments+pycross_environments_myproject//': Unable to determine default version for python hub repo '@@rules_python++python+pythons_hub//:pythons_hub': at /private/var/tmp/_bazel_gabriel/17eb730aec70ae18dde0e6ba1d906dff/external/rules_pycross+/pycross/extensions/lock_repos.bzl:3:6: at /private/var/tmp/_bazel_gabriel/17eb730aec70ae18dde0e6ba1d906dff/external/rules_pycross+/pycross/private/bzlmod/lock_repos.bzl:5:6: Encountered error while reading extension file 'locks.bzl': no such package '@@rules_pycross++lock_import+lock_import_repos_hub//': no such package '@@rules_pycross++environments+pycross_environments_myproject//': Unable to determine default version for python hub repo '@@rules_python++python+pythons_hub//:pythons_hub'
INFO: Elapsed time: 2.988s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
FAILED: 
    Fetching module extension lock_import in @@rules_pycross+//pycross/extensions:lock_import.bzl; starting

Solution

Read default Python version from versions.bzl file, if it exists, and fall back to interpreters.bzl otherwise.

Verified

This commit was signed with the committer’s verified signature. The key has expired.
jeff-mccoy Megamind
…bzl file
Copy link
Owner

@jvolkman jvolkman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jvolkman jvolkman merged commit 2bff754 into jvolkman:main Jan 6, 2025
63 checks passed
@blockjon-dd
Copy link

I'd like to use this. Could this be published to the central registry?

@betaboon
Copy link
Collaborator

betaboon commented Jan 22, 2025

I'd like to use this. Could this be published to the central registry?

until released you can use an override:

git_override(
    module_name = "rules_pycross",
    commit = "20fba49f17655c45f51e1bc293a329c8e1785abf",
    remote = "https://github.com/jvolkman/rules_pycross",
)

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

Successfully merging this pull request may close these issues.

None yet

4 participants