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

Provide __file__ #2178

Closed
flavius opened this issue Feb 10, 2017 · 4 comments
Closed

Provide __file__ #2178

flavius opened this issue Feb 10, 2017 · 4 comments
Labels

Comments

@flavius
Copy link

flavius commented Feb 10, 2017

There should be a way to determine the location of the current script, no matter how it's executed:

  1. as a stand-alone script with a xonsh shabang header
  2. as a parameter to xonsh on the command line
  3. via source

There is $XONSH_SOURCE (related #1169), but that one is not defined in case 3.

@scopatz scopatz added the bug label Feb 11, 2017
@scopatz
Copy link
Member

scopatz commented Feb 11, 2017

Hi @flavius, thanks for reporting. It is unclear to me which one of these cases is failing. Can you please give a more detailed example. Thanks!

@flavius
Copy link
Author

flavius commented Feb 11, 2017

@scopatz Complete transcript of my terminal session, showcasing the source and the three cases.

⋊> /tmp cat -n test.xsh                                                                                                                                                                        22:12:51
     1	#!/usr/bin/xonsh
     2	
     3	print(__file__)
⋊> /tmp /tmp/test.xsh                                                                                                                                                                          22:12:57
Traceback (most recent call last):
  File "/usr/bin/xonsh", line 3, in <module>
    main()
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 18676, in main
    _failback_to_other_shells(args, err)
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 18640, in _failback_to_other_shells
    raise err
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 18674, in main
    return main_xonsh(args)
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 18711, in main_xonsh
    loc=None, mode='exec')
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 2165, in run_script_with_cache
    run_compiled_code(ccode, glb, loc, mode)
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 2085, in run_compiled_code
    func(code, glb, loc)
  File "./test.xsh", line 3, in <module>
    print(__file__)
NameError: name '__file__' is not defined
⋊> /tmp xonsh /tmp/test.xsh                                                                                                                                                                    22:13:13
Traceback (most recent call last):
  File "/usr/bin/xonsh", line 3, in <module>
    main()
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 18676, in main
    _failback_to_other_shells(args, err)
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 18640, in _failback_to_other_shells
    raise err
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 18674, in main
    return main_xonsh(args)
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 18711, in main_xonsh
    loc=None, mode='exec')
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 2165, in run_script_with_cache
    run_compiled_code(ccode, glb, loc, mode)
  File "/usr/lib/python3.6/site-packages/xonsh/__amalgam__.py", line 2085, in run_compiled_code
    func(code, glb, loc)
  File "./test.xsh", line 3, in <module>
    print(__file__)
NameError: name '__file__' is not defined
⋊> /tmp xonsh                                                                                                                                                                                  22:13:26
flav@localhost /tmp $ source /tmp/test.xsh 
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
NameError: name '__file__' is not defined

@scopatz
Copy link
Member

scopatz commented Feb 11, 2017

Thanks @flavius. There is an initial implementation in #2181

@scopatz
Copy link
Member

scopatz commented Feb 13, 2017

Closing this since #2181 has been merged. Please feel free to reopen if you continue to have issues.

@scopatz scopatz closed this as completed Feb 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants