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

Setting __file__ in eval_file #1300

Closed
jeandet opened this issue Feb 27, 2018 · 1 comment · Fixed by #3233
Closed

Setting __file__ in eval_file #1300

jeandet opened this issue Feb 27, 2018 · 1 comment · Fixed by #3233
Labels

Comments

@jeandet
Copy link

jeandet commented Feb 27, 2018

Hi,
I wonder if it wouldn't make sense to set file global variable by default inside pybind11::eval_file executed scripts might want to use it.
A kind of recurring pattern in python is:

import os
script_path = os.path.realpath(__file__)
EricCousineau-TRI added a commit to EricCousineau-TRI/pybind11 that referenced this issue Mar 17, 2018
@EricCousineau-TRI
Copy link
Collaborator

Seconded. Nominally, if you try and use trace in a file executed via py::eval_file without having set __file__, you won't see any commands for that file. An example usage (albeit a hacky motivation - for debugging in CLion):
Python code
C++ code

@Skylion007 Skylion007 added the bug label Sep 1, 2021
Skylion007 added a commit that referenced this issue Sep 9, 2021
* Set __file__ constant when using eval_file

* Use const ref

* Use a move instead

* Revert

* Improve test

* Guard test with Python version

* Fix tests

* Dont support Python2 API

* Drop Python2 eval __file__ support

* Hack

* Semisupport Python2

* Take2

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

Successfully merging a pull request may close this issue.

3 participants