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 the PYTHONPATH environment from manager to the pylint #21891

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

znapy
Copy link

@znapy znapy commented Mar 14, 2024

Description of Changes

Add the PYTHONPATH environment from pythonpath-manager to the pylint plugin to access the root of the project without packages.

Example:

Suppose, you have a project with a single script (for simplicity in a spyder environment):

my-project
| - do_something.py

and you write a test:

my-project
| - do_something.py
| - tests
  | - test_do_something.py

In test_do_something.py you access to import do_something. So if you start Source -> Run code analysis it will show the error Unable to import 'do_something'. But in the IPython console !pytest tests/test_do_something.py doesn't show this error because there is PYTHONPATH environment.

And you should take additional steps to solve this problem, for example, make a packages:

my-project
| - my_project
  | - __init__.py
  | - do_something.py
  | - tests
    | - __init__.py
    | - test_do_something.py

or fix paths in pylintrc or pyproject.toml (section [tool.pylint], value init-hook=...):

my-project
| - do_something.py
| - tests
  | - test_do_something.py
| - pyproject.toml

No hacks are needed with this PR - it works out of the box.

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: @Znapy

@pep8speaks
Copy link

pep8speaks commented Mar 14, 2024

Hello @znapy! 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 2024-04-24 20:22:03 UTC

@znapy znapy force-pushed the pypath4pylint branch 2 times, most recently from 84dc248 to ed7708b Compare March 14, 2024 11:11
@znapy znapy changed the title gPypath4pylint PR: Add the PYTHONPATH environment from pythonpath-manager to the pylint plugin Mar 14, 2024
@znapy znapy changed the title PR: Add the PYTHONPATH environment from pythonpath-manager to the pylint plugin PR: Add the PYTHONPATH environment from manager to the pylint Mar 14, 2024
@znapy znapy force-pushed the pypath4pylint branch 2 times, most recently from c654d8e to 311e53f Compare March 18, 2024 12:02
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.

None yet

2 participants