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

Option for LOCALFOLDER to recognize the top-level module of the current file #1020

Closed
DylanYoung opened this issue Sep 27, 2019 · 5 comments
Closed
Labels
enhancement New feature or request

Comments

@DylanYoung
Copy link

I'd like to see an option to accomplish this:

# LOCAL FOLDER SECTION
from current_module import ...
from . import ...

A possible work-around with some editors would be to use their variables and pass them through to isort. Unfortunately, this doesn't currently work because isort doesn't take a known-localfolder argument on the command line.

Is there a way to accomplish this currently?

@DylanYoung
Copy link
Author

@timothycrosley Before I tackle this, do you have a preference for the syntax used for variables like this?

DylanYoung added a commit to DylanYoung/isort that referenced this issue Oct 28, 2019
@aldanor
Copy link

aldanor commented Nov 12, 2019

@DylanYoung

Here's another use case, if I understand what you want to do correctly: if you have many Python packages all related to the same bigger project. For example:

# FIRSTPARTY (not the current project, but all known-first-party)
from myproject_a.foo import bar
from myproject_b.qwe import ewq
from myproject_c.abc import xyz

# LOCALFOLDER (this is the one we're currently testing, although it's not a relative import)
from myproject_d.module import something

Unless I'm missing something, this can't be done with the current isort?

@DylanYoung
Copy link
Author

@aldanor Precisely. I have a proof of concept working, but it makes a number of assumptions and wouldn't work with namespaced packages currently (though it's questionable whether this is desirable or not... I haven't worked with them much so I'm not 100%). I'll get a PR up in the next week or two.

My use case is pretty much as you say: a bunch of django apps that coexist in a larger web application project.

@aldanor
Copy link

aldanor commented Nov 12, 2019

My use case is exactly with namespaced packages actually 😆 So if you could make it work with them too it would be totally awesome!

@timothycrosley timothycrosley added the enhancement New feature or request label Feb 17, 2020
@timothycrosley
Copy link
Member

starting in isort 5.2.0, isort will now accept a --known-local-folder CLI option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants