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

pants fmt, isort does not follow PEP8 #20386

Closed
silverwestK opened this issue Jan 10, 2024 · 5 comments
Closed

pants fmt, isort does not follow PEP8 #20386

silverwestK opened this issue Jan 10, 2024 · 5 comments
Labels

Comments

@silverwestK
Copy link

Describe the bug
When running the pants fmt command, the formatting results of isort do not adhere to PEP8 standards.
With IDE isort extensions, from VScode and PyCharm, are working well that I expected.

How to solve this problem?

Pants version

  • 2.16

OS

  • Linux Ubuntu 22.04.3 LTS

Additional info

  • isort version: 5.12.0

When formatting..

  • Expected result
import argparse
import datetime
import logging
import os
import time
from http import HTTPStatus
from typing import Callable

import tensorflow as tf
import uvicorn
from fastapi import FastAPI, Request
from fastapi.responses import Response

from lib.logging import set_logger_from_config  << here
from ... < 1st parties
  • Unexpected result (w/ pants fmt)
import argparse
import datetime
import logging
import os
import time
from http import HTTPStatus
from typing import Callable

import tensorflow as tf
import uvicorn
from fastapi import FastAPI, Request
from fastapi.responses import Response
from lib.logging import set_logger_from_config << here

from ... < 1st parties
@benjyw
Copy link
Sponsor Contributor

benjyw commented Jan 10, 2024

Have you tried configuring isort to following the formatting you want?

@silverwestK
Copy link
Author

Have you tried configuring isort to following the formatting you want?

Configuring with pyproject.toml like this, it works well.

[tool.isort]
profile = "black"
line_length = 125
known_first_party = ["lib"]

Apart from that, the peculiar thing is that the other first party imports locate the proper positions. (without configuring option of known_first_party)

For instance, if a project hierarcy like as follows,

.
├── project_A
├── project_B
└── lib

pants fmt works like this.

import os
import time

from fastapi import FastAPI, Request
from lib.logging import set_logger_from_config << 1st party

from project_A.foo.bar << 1st party
from project_B.bar.foo << 1st party

It means that project_A, project_B are recogized the first party libraries, but lib is not.

There could be some differences between IDE and pants settings.. but I'm not sure..

@jsirois
Copy link
Contributor

jsirois commented Jan 10, 2024

This appears to be well known (#15069), but too expensive to fix currently (#19869).

@benjyw
Copy link
Sponsor Contributor

benjyw commented Jan 10, 2024

Yeah, the current workaround is to manually set known_first_party.

@benjyw
Copy link
Sponsor Contributor

benjyw commented Jan 10, 2024

@eunseo0u0 I will close this assuming that workaround works for you. Feel free to reopen if not.

@benjyw benjyw closed this as completed Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants