Navigation Menu

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

Passing filename / extension when using stdin to support .pyi files w/ black #1596

Closed
sbdchd opened this issue Nov 12, 2020 · 1 comment
Closed
Labels
enhancement New feature or request integration
Milestone

Comments

@sbdchd
Copy link

sbdchd commented Nov 12, 2020

With the black profile, not sure about others, formatting is dependent on the extension.

When using stdin to format a file the extension information isn't passed along,
so there isn't a way to format .pyi files the same as when passing the file path.

Example

example file main.pyi:

from typing import Any

class Bar:
    def foo(self, arg: Any) -> bytes: ...
./.venv/bin/isort --profile=black main.pyi --diff

No changes necessary.

and via stdin

❯ cat main.pyi | ./.venv/bin/isort --profile=black - --diff
--- :before	2020-11-11 22:48:00.874612
+++ :after	2020-11-11 22:48:00.874650
@@ -1,4 +1,5 @@
 from typing import Any
+
 
 class Bar:
     def foo(self, arg: Any) -> bytes: ...

conclusion

I think one solution is to specify the extension manually, or give isort a fake
filename to use.

cat main.pyi | ./.venv/bin/isort --profile=black --extension=.pyi - --diff
# or 
cat main.pyi | ./.venv/bin/isort --profile=black --filename=main.pyi - --diff

rel: #942
rel: microsoft/vscode-python#14702

@timothycrosley timothycrosley added enhancement New feature or request integration labels Nov 13, 2020
@timothycrosley timothycrosley added this to the 5.7.0 milestone Nov 13, 2020
timothycrosley added a commit that referenced this issue Nov 13, 2020
…hs to be specified when using streaming input from CLI.
timothycrosley added a commit that referenced this issue Nov 13, 2020
Implemented #1596: Provide ways for extension formatting and file pat…
@timothycrosley
Copy link
Member

timothycrosley commented Nov 13, 2020

Thanks for this well thought out issue! I've always meant for isort to support this, and indeed it already does for API based usage, but until now this functionality was not exposed to the CLI.

In develop, to be released with 5.7.0 some time this month, both features (specifying the filename and specifying the extension formatting to use) are now available:

echo -e "import b\nimport a\ndef x():\n   pass" | isort - --filename actual_disk_location.pyi
echo -e "import b\nimport a\ndef x():\n   pass" | isort - --ext-format pyi

Thanks!

~Timothy

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

No branches or pull requests

2 participants