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

PDM corrupts binary executable (ruff) #2045

Closed
1 task done
pawamoy opened this issue Jun 21, 2023 · 1 comment · Fixed by #2054
Closed
1 task done

PDM corrupts binary executable (ruff) #2045

pawamoy opened this issue Jun 21, 2023 · 1 comment · Fixed by #2054
Assignees
Labels
🐛 bug Something isn't working

Comments

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Jun 21, 2023

  • I have searched the issue tracker and believe that this is not a duplicate.

Steps to reproduce

# setup
mkdir pdm-ruff-repro
cd pdm-ruff-repro
cat >pyproject.toml <<EOF
[project]
name = ""
version = ""
description = ""
authors = [
    {name = "Hi PDM", email = "hi@pdm.com"},
]
dependencies = [
    "ruff>=0.0.274",
]
requires-python = ">=3.7"
license = {text = "MIT"}
EOF
touch test.py
pdm config --local python.use_venv false
pdm install

# assert that it initially works:
pdm run ruff check test.py  # OK
cp __pypackages__/3.7/bin/ruff ruff37  # backup executable

# now switch Python version and back:
pdm use -f python3.8
pdm use -f python3.7

# assert executable was changed
diff __pypackages__/3.7/bin/ruff ruff37
# Binary files __pypackages__/3.7/bin/ruff and ruff37 differ

# assert ruff does not work anymore
pdm run ruff check test.py  # no output, failure
__pypackages__/3.7/bin/ruff check test.py
# [1]    178079 segmentation fault (core dumped)  __pypackages__/3.7/bin/ruff check test.py

Actual behavior

PDM corrupts binary executable scripts, probably when trying to replace the shebang.

Expected behavior

Would it make sense to only try replacing the shebang on non-binary files?
Maybe by trying to open the file as text (utf8) and if it fails, do nothing? Otherwise continue with the regex replace?

Environment Information

# Paste the output of `pdm info && pdm info --env` below:
PDM version:
  2.7.4
Python Interpreter:
  /home/pawamoy/.basher-packages/pyenv/pyenv/versions/3.7.15/bin/python3.7 (3.7)
Project Root:
  /home/pawamoy/pdm-ruff-repro
Local Packages:
  /home/pawamoy/pdm-ruff-repro/__pypackages__/3.7
{
  "implementation_name": "cpython",
  "implementation_version": "3.7.15",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "6.3.8-arch1-1",
  "platform_system": "Linux",
  "platform_version": "#1 SMP PREEMPT_DYNAMIC Wed, 14 Jun 2023 20:10:31 +0000",
  "python_full_version": "3.7.15",
  "platform_python_implementation": "CPython",
  "python_version": "3.7",
  "sys_platform": "linux"
}
@pawamoy pawamoy added the 🐛 bug Something isn't working label Jun 21, 2023
@frostming frostming self-assigned this Jun 26, 2023
frostming added a commit that referenced this issue Jun 26, 2023
Fixes #2045

Signed-off-by: Frost Ming <me@frostming.com>
@pawamoy
Copy link
Sponsor Contributor Author

pawamoy commented Jun 26, 2023

Thank you for reviewing my PR, finding a better solution and implementing it! Greatly appreciated 🚀
I've installed and tested PDM's main branch, and it works perfectly 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
2 participants