Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Relative imports not working (Django) #110

Closed
ntadej opened this issue Jan 24, 2016 · 8 comments · Fixed by #205
Closed

Relative imports not working (Django) #110

ntadej opened this issue Jan 24, 2016 · 8 comments · Fixed by #205
Labels

Comments

@ntadej
Copy link

ntadej commented Jan 24, 2016

I want to use linter-pylint in atom, but I have some problems with relative imports.
For example, in tests.py I want to import a django model

from .models import Quote

Pylint wants to import tests.models. If I run pylint from command line it works properly.

@jacebrowning
Copy link

I am also experiencing this problem. It doesn't seem specific to Django.

@Alexx-G
Copy link

Alexx-G commented Feb 11, 2016

Same to me. Sadly I can't figure out after which version the problem appeared.
@Arcanemagus Any updates on this? This is really annoying.
It'd be nice to add some logging (enabled by an option as in https://github.com/sadovnychyi/autocomplete-python ) this will help a lot for troubleshooting and bug-reports.

@Arcanemagus
Copy link
Member

If I had to guess this is a problem with the $PYTHONPATH hackery going on, but I have no idea @AtomLinter/linter-pylint any pointers as to how to debug this?

@Alexx-G
Copy link

Alexx-G commented Feb 11, 2016

So, after an investigation seems like the problem depends of pylint version. Since version 1.5.0 all relative imports in my projects are recognized as errors (using this linter).
If I've understood correctly how this linter works, it does the following:

  1. Copies current file to the temporary dir;
  2. Inserts in PYTHONPATH - path to the package and path to the project;
  3. Run pylint on that temporary file;

I've reproduced manually this scenario and with pylint>=1.5.0 I'm receiving import errors.
The following command (which is an alias to yours) also doesn't work

pylint /tmp/pylint-experiments/utils.py --init-hook='import sys; sys.path.append("/path/to/original/package/")'

The problem is that I'm using pylint-django which has some issues with pylint<1.5.0. So, I can't just downgrade pylint.

Are you doing that magic with PYTHONPATH and temporary file to lint on the fly?
If yes, it'd nice to lint without this magic if I've disabled "Lint as you type" option. In this case just lint original file on save.

@Arcanemagus
Copy link
Member

If I remember that stuff was added to enable people to work around not running Atom in the proper virtualenv, but you'd have to ask @SpainTrain on that as I believe he is the author of that bit.

@johnslemmer
Copy link

Ok, I'm still running in to this issue in atom-pylint v1.2.2. And I'm not using Django.

And it has everything to do with the fact that atom-pylint creates a tempFile out of the text that is in the editor and then runs pylint against that new tempFile. And as you would expect with any temp file, it is in a completely different and ambiguous directory. And when pylint inspects this temp file and it comes across a line import .modulename it will actually look in that directory where the new temp file is. And when it can't find it, then it errors.

So, can I propose a fix of maybe making the tempfile that gets written stay in the same directory with the actual file?

@sneakypete81
Copy link

Not specific to Django - please update the issue title. As far as I can see, any relative import of the following form is failing:

from .module import thing

Using https://github.com/Horta/linter-py fixes the issue @horta: any chance of merging your changes back?

@horta
Copy link

horta commented Mar 1, 2017

Hi @sneakypete81
Thanks for using my package =)
I will sort my package out this evening. It needs some update.

Also, it might be possible to solve this problem via linter-pylint itself. I will post here back in a couple of hours!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants