bazelbuild / rules_python

Bazel Python Rules
https://rules-python.readthedocs.io
Apache License 2.0
530 stars 540 forks source link

Salt Installation error #2164

Closed jahzzeel closed 1 month ago

jahzzeel commented 2 months ago

🐞 bug report

Affected Rule

The issue is caused by the rule: pypi__installer/installer/destinations.py", line 170, in write_to_fs raise FileExistsError(message) FileExistsError: File already exists: ./bin/salt ### Is this a regression?

is not working on any version of rules_python (30 to 35) nor any version of Python, I tested Python (3.8, 3.9, 3.11)

Description

rules_python is unable to install https://github.com/saltstack/salt/releases/tag/v3005.1, it raise an error: FileExistsError: File already exists: ./bin/salt

πŸ”¬ Minimal Reproduction

load("@python_deps//:requirements.bzl", "requirement")

py_library( name = "test_lib", srcs = ["init.py"], deps = [ requirement("salt"), ], visibility = ["//visibility:public"] )

Note: python_deps reference to the workspace as:

load("@rules_python//python:repositories.bzl", "python_register_toolchains") python_register_toolchains( name="python_3_8", python_version="3.8" ) load("@python_3_8//:defs.bzl", "interpreter") load("@rules_python//python:pip.bzl", "pip_parse")

pip_parse( name = "python_deps", python_interpreter_target = interpreter, requirements_lock = "//third_party:requirements-lock.txt", )

load("@python_manager_deps//:requirements.bzl", "install_deps")

install_deps()

πŸ”₯ Exception or Error

FileExistsError: File already exists: ./bin/salt

🌍 Your Environment

Operating System:

ubuntu 18

Output of bazel version:

6.3.1

Rules_python version:

http_archive( name = "rules_python", sha256 = "be04b635c7be4604be1ef20542e9870af3c49778ce841ee2d92fcb42f9d9516a", strip_prefix = "rules_python-0.35.0", url = "https://github.com/bazelbuild/rules_python/releases/download/0.35.0/rules_python-0.35.0.tar.gz", )

Anything else relevant?

xangcastle commented 2 months ago

Same issue for me

jahzzeel commented 2 months ago

I found that the error is raised because of this: /home/.cache/bazel/._bazel_user/983210312309831/external/pypi__installer/installer/destinations.py, more specific here:

if os.path.exists(target_path):
    message = f"File already exists: {target_path}"
    raise FileExistsError(message)

I looked into the file and printed some things, It looks like it loops over these files: https://github.com/saltstack/salt/tree/master/scripts and tries to create the ./bin/salt for salt and spm raising the issue in the second one

trex7 commented 2 months ago

Facing same issue on my side as well

groodt commented 1 month ago

This is caused by a badly packaged distribution. It looks like it was fixed in https://github.com/saltstack/salt/pull/63795. It was also causing issues in nixpkgs https://github.com/NixOS/nixpkgs/pull/250689

I am able to reproduce the error outside bazel with salt==3005.1

β‹Š> /v/f/6/j/T/salt_repro .venv/bin/python3 -m installer salt-3005.1/dist/salt-3005.1-py3-none-any.whl                                                                                                                                        21:04:20
Traceback (most recent call last):
  File "/Users/groodt/.pyenv/versions/3.9.16/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/groodt/.pyenv/versions/3.9.16/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/private/var/folders/69/jvn2bd0j6cs31l1ldw922c5c0000gp/T/salt_repro/.venv/lib/python3.9/site-packages/installer/__main__.py", line 98, in <module>
    _main(sys.argv[1:], "python -m installer")
  File "/private/var/folders/69/jvn2bd0j6cs31l1ldw922c5c0000gp/T/salt_repro/.venv/lib/python3.9/site-packages/installer/__main__.py", line 94, in _main
    installer.install(source, destination, {})
  File "/private/var/folders/69/jvn2bd0j6cs31l1ldw922c5c0000gp/T/salt_repro/.venv/lib/python3.9/site-packages/installer/_core.py", line 109, in install
    record = destination.write_file(
  File "/private/var/folders/69/jvn2bd0j6cs31l1ldw922c5c0000gp/T/salt_repro/.venv/lib/python3.9/site-packages/installer/destinations.py", line 203, in write_file
    return self.write_to_fs(
  File "/private/var/folders/69/jvn2bd0j6cs31l1ldw922c5c0000gp/T/salt_repro/.venv/lib/python3.9/site-packages/installer/destinations.py", line 167, in write_to_fs
    raise FileExistsError(message)
FileExistsError: File already exists: /private/var/folders/69/jvn2bd0j6cs31l1ldw922c5c0000gp/T/salt_repro/.venv/bin/salt

I am unable to reproduce the error with salt==3007.1