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

PR: Add options to include user's local PYTHONPATH and environment variables #14918

Closed
wants to merge 23 commits into from

Conversation

mrclary
Copy link
Contributor

@mrclary mrclary commented Mar 12, 2021

Description of Changes

  • Wrote at least one-line docstrings (for any new functions)
  • Included a screenshot or animation (if affecting the UI, see Licecap)

Added preference to the Python Interpreter section allowing all platforms and launch methods to select whether a user's system PYTHONPATH and environment variables are used for Consoles.

Spyder's PYTHONPATH Manager list behavior is unchanged.

Fixes #14843

Screen Shot 2021-05-31 at 4 02 16 PM

New Behavior

  • If "Use system PYTHONPATH" is deselected: paths in PYTHONPATH Manager are appended to the Console's sys.path
  • If "Use system PYTHONPATH" is selected: in addition to the above, the paths in the user's local PYTHONPATH environment variable are appended to the Console's sys.path. On macOS and Linux, the user's local PYTHONPATH is determined by /etc/profile, ~/.bash_profile, ~/.bash_login, and ~/.profile. On Windows, the user's local PYTHONPATH is extracted from the registry query reg query HKEY_CURRENT_USER\Environment.
  • If "Use system environment variables" is deselected: only the following variables are passed to the Console's os.environ.
    • PATH and HOME on macOS
    • PATH, HOME, DISPLAY and XAUTHORITY on Linux
    • 'PATH', 'SYSTEMROOT', 'SYSTEMDRIVE', and 'USERPROFILE' on Windows
  • If "Use system environment variables" is selected, all of the user's local environment variables, except PYTHONPATH, are passed to the Console's os.environ. On macOS and Linux, these are determined by /etc/profile, ~/.bash_profile, ~/.bash_login, and ~/.profile. On Windows these are determined by the registry query reg query HKEY_CURRENT_USER\Environment

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct:
@mrclary

@mrclary
Copy link
Contributor Author

mrclary commented Mar 12, 2021

This PR and #14853 are mutually exclusive.

@pep8speaks
Copy link

pep8speaks commented Apr 20, 2021

Hello @mrclary! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-06-19 19:51:18 UTC

@mrclary mrclary force-pushed the pythonpath2 branch 2 times, most recently from b49c829 to 209be48 Compare May 11, 2021 23:08
@mrclary mrclary changed the title WIP: PR: Add Preference to Include User's Local PYTHONPATH and Environment Variables in Standalone Applications PR: Add Preference to Include User's Local PYTHONPATH and Environment Variables in Standalone Applications May 27, 2021
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mrclary for your work on this! I left an initial review for you.

spyder/utils/programs.py Outdated Show resolved Hide resolved
spyder/utils/programs.py Outdated Show resolved Hide resolved
spyder/plugins/maininterpreter/confpage.py Show resolved Hide resolved
spyder/plugins/maininterpreter/confpage.py Outdated Show resolved Hide resolved
@ccordoba12 ccordoba12 added this to the v5.1.0 milestone May 27, 2021
@ccordoba12 ccordoba12 changed the title PR: Add Preference to Include User's Local PYTHONPATH and Environment Variables in Standalone Applications PR: Add options to include user's local PYTHONPATH and environment variables May 27, 2021
@mrclary mrclary force-pushed the pythonpath2 branch 8 times, most recently from e5c494e to 45872af Compare May 29, 2021 22:39
@mrclary
Copy link
Contributor Author

mrclary commented May 30, 2021

I can't for the life of me figure out how to fix this problem...
I've gotten all tests to pass except for slow tests on Linux.
I've got the environment setup on my Ubuntu VM as close to identical to the Github test environment as possible, compared all the conda package versions, and cannot reproduce the error locally. The tests pass locally.

Failed test_run_cython_code
=================================== FAILURES ===================================
_____________________________ test_run_cython_code _____________________________

main_window = <spyder.app.mainwindow.MainWindow object at 0x7f5ddcb26f50>
qtbot = <pytestqt.qtbot.QtBot object at 0x7f5ddc049c50>

    @pytest.mark.slow
    @flaky(max_runs=3)
    @pytest.mark.skipif(
        (os.name == 'nt' or sys.platform == 'darwin' or
         parse_version(ipy_release.version) == parse_version('7.11.0')),
        reason="Hard to test on Windows and macOS and fails for IPython 7.11.0")
    def test_run_cython_code(main_window, qtbot):
        """Test all the different ways we have to run Cython code"""
        # ---- Setup ----
        # Get a reference to the code editor widget
        code_editor = main_window.editor.get_focus_widget()
    
        # ---- Run pyx file ----
        # Load test file
        main_window.editor.load(osp.join(LOCATION, 'pyx_script.pyx'))
    
        # Run file
        qtbot.keyClick(code_editor, Qt.Key_F5)
    
        # Get a reference to the namespace browser widget
        nsb = main_window.variableexplorer.current_widget()
    
        # Wait until an object appears
        qtbot.waitUntil(lambda: nsb.editor.source_model.rowCount() == 1,
>                       timeout=COMPILE_AND_EVAL_TIMEOUT)
E       AssertionError: waitUntil timed out in 30000 miliseconds
E       assert not True
E        +  where True = <function QtBot.waitUntil.<locals>.timed_out at 0x7f5dd3f1e4d0>()

/home/runner/work/spyder/spyder/spyder/app/tests/test_mainwindow.py:1104: AssertionError
----------------------------- Captured Qt messages -----------------------------
    QtWarningMsg: Scenegraph already initialized, setBackend() request ignored
--------------------------- Captured stdout teardown ---------------------------

In [1]: runfile('/home/runner/work/spyder/spyder/spyder/app/tests/pyx_script.pyx', wdir='/home/runner/work/spyder/spyder/spyder/app/tests')
gcc: fatal error: cannot executecc1’: execvp: No such file or directory
compilation terminated.

In [2]: 
---------------------------- Captured stderr setup -----------------------------
<class 'spyder.app.tests.spyder_boilerplate.spyder.plugin.SpyderBoilerplate'>: A plugin with section "spyder_boilerplate" already exists!
Traceback (most recent call last):
  File "/home/runner/work/spyder/spyder/spyder/app/mainwindow.py", line 917, in setup
    self.register_plugin(plugin_instance, external=True)
  File "/home/runner/work/spyder/spyder/spyder/app/mainwindow.py", line 237, in register_plugin
    plugin._register()
  File "/home/runner/work/spyder/spyder/spyder/api/plugins.py", line 884, in _register
    self._conf.register_plugin(self)
  File "/home/runner/work/spyder/spyder/spyder/config/manager.py", line 119, in register_plugin
    'exists!'.format(conf_section))
RuntimeError: A plugin with section "spyder_boilerplate" already exists!

test_move_to_first_breakpoint for pip slow linux has the same stderr setup error: RuntimeError: A plugin with section "spyder_boilerplate" already exists!

I just can't get these tests to fail locally, so I can't figure out what is going on.
@spyder-ide/core-developers , can you provide any insight or recommendations?

@dalthviz
Copy link
Member

@mrclary I think this is related with the fake plugin I added and the reuse of the mainwindow instance in the tests. I will check 👍 (probably we need to add some sort of condition/validation so the addition of the fake plugin entrypoint is only done once)

@mrclary
Copy link
Contributor Author

mrclary commented May 31, 2021

@dalthviz, thanks for looking into the fake plugin, perhaps that is the issue. However, I am curious why that doesn't manifest in the mac and windows tests also, or on my local linux tests.

@mrclary
Copy link
Contributor Author

mrclary commented Aug 12, 2021

From conversation in #16200, remember to consider how sys.path is applied when using "Execute in an external systerm terminal" run option.

@mrclary mrclary changed the base branch from master to 5.x September 16, 2021 01:36
@mrclary mrclary marked this pull request as draft September 16, 2021 01:36
@mrclary
Copy link
Contributor Author

mrclary commented Sep 16, 2021

Closing in favor of #16429

@mrclary mrclary closed this Sep 16, 2021
@ccordoba12 ccordoba12 removed this from the v5.2.0 milestone Sep 16, 2021
@mrclary mrclary deleted the pythonpath2 branch September 28, 2021 14:15
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.

Ability to use PYTHONPATH from user bash_profile in macOS application
4 participants