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

Compile code in run_setup #4816

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MarcinKonowalczyk
Copy link

Summary of changes

Closes #4815

exec(code, locals()) in gets a code string and then calls compile internally. This PR adds an explicit compile step (as it is already the case in many other places in the codebase) which enables better filename and code hints in the printed traceback (see issue above).

Old:

...
  File "/Users/marcin/.pyenv/versions/3.12.3/envs/default/lib/python3.12/site-packages/setuptools/build_meta.py", line 522, in run_setup
    super().run_setup(setup_script=setup_script)
  File "/Users/marcin/.pyenv/versions/3.12.3/envs/default/lib/python3.12/site-packages/setuptools/build_meta.py", line 320, in run_setup
    exec(code, locals())
  File "<string>", line 14, in <module>
  File "<string>", line 12, in baz
  File "<string>", line 9, in bar
  File "<string>", line 6, in foo
BadPackageError: This package is bad
[end of output]
...

New:

...
  File "~/.local/lib/python3.14/site-packages/setuptools/build_meta.py", line 525, in run_setup
    super().run_setup(setup_script=setup_script)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.local/lib/python3.14/site-packages/setuptools/build_meta.py", line 323, in run_setup
    exec(source, locals())
    ~~~~^^^^^^^^^^^^^^^^^^
  File "~/.../bad_package/setup.py", line 14, in <module>
    baz()
    ~~~^^
  File "~/.../bad_package/setup.py", line 12, in baz
    bar()
    ~~~^^
  File "~/.../bad_package/setup.py", line 9, in bar
    foo()
    ~~~^^
  File "~/.../bad_package/setup.py", line 6, in foo
    raise BadPackageError("This package is bad")
BadPackageError: This package is bad
[end of output]
...

Pull Request Checklist

@abravalheri
Copy link
Contributor

I had problems in the past with compile, so I would prefer not to change this one.

The documentation also mentions:

Warning It is possible to crash the Python interpreter with a sufficiently large/complex string when compiling to an AST object due to stack depth limitations in Python’s AST compiler.

which might be problematic?

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.

[BUG] No filename and code hints in traceback
2 participants