chilly-tailor-75063
12/09/2022, 3:02 PM./pants fmt ::
with success. I also use ./pants lint ::
, but with mixed results. It helps me find various code issues, but I get this: “E0401: Unable to import ‘<some required module>’ (import-error)” for all my required modules. My project is setup with a remote Python interpreter (Python 3.10.8) in a Docker container. I’m also using Poetry to manage the dependencies. I’m not sure what to do to resolve this, other than tell pylint to stop reporting on E0401 errors.enough-analyst-54434
12/09/2022, 3:16 PM./pants roots
source roots match what you'd expect? https://www.pantsbuild.org/docs/source-roots
Pants needs to be able to differentiate Python package directories from the directories they are nested under. Basically you need to tell Pants your 1st party PYTHONPATH
.enough-analyst-54434
12/09/2022, 3:18 PMchilly-tailor-75063
12/09/2022, 4:31 PMmy_repo_name
└── project
├── __init__.py
├── app # bulk of code in dir
├── __init__.py
├── pyproject.toml
└── Dockerfile
I’ve tried all kinds of variations recommended in the link you sent and I’m still getting “Unable to import”, along with a ton of “ambiguity” messages prior to pylint’s output.chilly-tailor-75063
12/09/2022, 4:42 PM[source]
root_patterns = [
"project/app",
"tests",
]
in my pants.toml file removes all the ambiguity messages, but pylint is still generating “Unable to import” messages.enough-analyst-54434
12/09/2022, 4:43 PM<http://project.app|project.app>
be importable? Your __init__.py
in that tree imply it.enough-analyst-54434
12/09/2022, 4:44 PMproject/__init__.py
file spurious?enough-analyst-54434
12/09/2022, 4:45 PMenough-analyst-54434
12/09/2022, 4:47 PMenough-analyst-54434
12/09/2022, 4:48 PMchilly-tailor-75063
12/09/2022, 5:18 PMproject/app/endpoints/schedules/v1/crud.py:7:0: E0401: Unable to import 'fastapi' (import-error)
project/app/endpoints/schedules/v1/crud.py:8:0: E0401: Unable to import 'sqlmodel' (import-error)
project/app/endpoints/schedules/v1/crud.py:9:0: E0401: Unable to import 'sqlmodel.ext.asyncio.session' (import-error)
pylint is having no problem finding/importing the modules I’ve built for the project. It’s only choking on 3rd party modules, like fastapi above.enough-analyst-54434
12/09/2022, 5:20 PMpants.toml
in it's entirety? Do you have a poetry_requirements
target in a BUILD file somewhere and have you used ./pants tailor
or not?chilly-tailor-75063
12/09/2022, 5:22 PM[GLOBAL]
pants_version = "2.14.0"
backend_packages = [
# "pants.backend.docker",
# "pants.backend.docker.lint.hadolint",
"pants.backend.python",
"pants.backend.build_files.fmt.black",
"pants.backend.python.lint.black",
"pants.backend.python.lint.isort",
"pants.backend.python.lint.pylint",
"pants.backend.python.typecheck.mypy",
]
[python]
tailor_pex_binary_targets = false
interpreter_constraints = ["CPython==3.9.*"]
[source]
root_patterns = [
"project/app",
"tests",
]
[anonymous-telemetry]
enabled = false
[pylint]
config = "config/.pylintrc"
[test]
output = "all"
[pytest]
extra_requirements.add = []
I don’t have a poetry_requirements
in there, but I have run ./pants tailor
pretty regularlyenough-analyst-54434
12/09/2022, 5:22 PMenough-analyst-54434
12/09/2022, 5:23 PMenough-analyst-54434
12/09/2022, 5:25 PMenough-analyst-54434
12/09/2022, 5:27 PMchilly-tailor-75063
12/09/2022, 5:30 PMpants.toml
file.enough-analyst-54434
12/09/2022, 5:30 PMpoetry_requirements()
That is all.chilly-tailor-75063
12/09/2022, 5:32 PMenough-analyst-54434
12/09/2022, 5:32 PMenough-analyst-54434
12/09/2022, 5:32 PMenough-analyst-54434
12/09/2022, 5:33 PMenough-analyst-54434
12/09/2022, 5:34 PMchilly-tailor-75063
12/09/2022, 5:39 PMpyproject.toml
poetry_requirements(name="poetry")
poetry_requirements(
name="dynaconf", overrides={"dynaconf": {"dependencies": [":setuptools"]}}
)
poetry_requirements(
name="fastapi", overrides={"fastapi": {"dependencies": [":requests"]}}
)
When I run ./pants lint ::
it generates the “unable to import errors”
If I edit the BUILD to this:
poetry_requirements(name="poetry")
And run ./pants lint ::
the imports work and I’m down to issues in my code. 😉chilly-tailor-75063
12/09/2022, 5:40 PMenough-analyst-54434
12/09/2022, 5:40 PMenough-analyst-54434
12/09/2022, 5:40 PMpoetry_requirements
target.enough-analyst-54434
12/09/2022, 5:40 PMpoetry_requirements
targetschilly-tailor-75063
12/09/2022, 5:41 PMenough-analyst-54434
12/09/2022, 5:42 PM__init__.py
look strange.chilly-tailor-75063
12/09/2022, 5:45 PMpoetry_requirements(…
poetry_requirements(
name="poetry",
name="dynaconf", overrides={"dynaconf": {"dependencies": [":setuptools"]}},
name="fastapi", overrides={"fastapi": {"dependencies": [":requests"]}}
)
but it didn’t like this because of the duplicate “name”. Can you give me a hint how I should approach this?enough-analyst-54434
12/09/2022, 5:45 PMchilly-tailor-75063
12/09/2022, 5:46 PMenough-analyst-54434
12/09/2022, 5:46 PMpoetry_requirements(
name="poetry",
overrides={
"dynaconf": {"dependencies": [":setuptools"]},
"fastapi": {"dependencies": [":requests"]}
}
)
chilly-tailor-75063
12/09/2022, 5:50 PM./pants lint ::
12:47:44.45 [INFO] Completed: Format with isort - isort made no changes.
12:47:44.45 [WARN] Completed: Format with Black - black made changes.
project/app/endpoints/schedules/v1/crud.py
project/app/endpoints/schedules/v1/routes.py
project/app/endpoints/users/v1/crud.py
project/app/endpoints/users/v1/routes.py
project/app/models.py
project/app/server.py
12:47:44.47 [WARN] Pants cannot infer owners for the following imports in the target project/app/endpoints/services/v1/transactions/routes.py:
* project.app.common.tools.get_common_parameters (line: 7)
* project.app.endpoints.auth.routes.authenticate (line: 8)
If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/v2.14/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
12:47:44.48 [ERROR] 1 Exception encountered:
ResolveError: The address project:requests from the `dependencies` field of the target project:poetry#fastapi does not exist.
The target name ':requests' is not defined in the directory project. Did you mean one of these target names?
* :poetry
enough-analyst-54434
12/09/2022, 5:51 PMenough-analyst-54434
12/09/2022, 5:51 PMproject/BUILD
?enough-analyst-54434
12/09/2022, 5:52 PMrequests
?chilly-tailor-75063
12/09/2022, 5:52 PMproject/BUILD
chilly-tailor-75063
12/09/2022, 5:52 PMenough-analyst-54434
12/09/2022, 5:52 PMenough-analyst-54434
12/09/2022, 5:53 PMenough-analyst-54434
12/09/2022, 5:53 PMchilly-tailor-75063
12/09/2022, 5:54 PMenough-analyst-54434
12/09/2022, 5:54 PMenough-analyst-54434
12/09/2022, 5:54 PMchilly-tailor-75063
12/09/2022, 5:55 PMrequests
line in my pyproject.toml file. I must have done that when I was trying to figure this out a while back.enough-analyst-54434
12/09/2022, 5:55 PM...
python_requirement(name="requests", requirements=["requests==1.2.3"])
enough-analyst-54434
12/09/2022, 5:56 PMenough-analyst-54434
12/09/2022, 5:56 PMenough-analyst-54434
12/09/2022, 5:56 PMenough-analyst-54434
12/09/2022, 5:56 PMchilly-tailor-75063
12/09/2022, 5:56 PM[tool.poetry]
name = "recurring-payment"
version = "0.1.0"
description = "Service to provide a REST API to create, manage and access recurring payments to bridgepay"
license = "MIT"
authors = ["dfarrell <dfarrell@rectanglehealth.com>"]
readme = "README.md"
homepage = "<https://github.com/rectanglehealth/recurring-payment>"
repository = "<https://github.com/rectanglehealth/recurring-payment>"
packages = [{include = "recurring_payment"}]
[tool.poetry.dependencies]
python = "^3.10.8"
structlog = "^22.1.0"
uvicorn = "^0.19.0"
python-dotenv = "^0.21.0"
boto3 = "^1.20.0"
python-multipart = "^0.0.5"
pyjwt = {extras = ["crypto"], version = "^2.6.0"}
python-jose = {extras = ["cryptography"], version = "^3.3.0"}
toml = "^0.10.2"
dynaconf = "^3.1.11"
fastapi = "^0.86.0"
requests = "^2.28.1"
rocketry = "^2.4.1"
sqlmodel = "^0.0.8"
asyncmy = "^0.2.5"
[tool.poetry.group.dev.dependencies]
pytest-fastapi = "^0.1.0"
pytest-cov = "^4.0.0"
pytest = "^7.2.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.scripts]
recurring-payment = "app:main"
[tool.isort]
profile = "black"
line_length = 100
skip_glob = "tests"
[tool.black]
line-length = 100
extend-exclude = "tests"
[tool.pylint."MASTER"]
extension-pkg-whitelist=[
"pydantic",
"pydantic.typing"
]
[tool.pytest.ini_options]
addopts = [
"--import-mode=importlib",
]
enough-analyst-54434
12/09/2022, 5:57 PM:poetry#requests
not :requests
enough-analyst-54434
12/09/2022, 5:57 PM:poetry
target, you address with #
enough-analyst-54434
12/09/2022, 5:59 PM:<target generator>#<subtarget>
enough-analyst-54434
12/09/2022, 6:00 PMenough-analyst-54434
12/09/2022, 6:01 PMchilly-tailor-75063
12/09/2022, 6:02 PMBUILD
file:
poetry_requirements(
name="poetry",
overrides={
"fastapi": {"dependencies": [":poetry#requests"]},
}
)
Which looks like it works when I run ./pants lint ::
enough-analyst-54434
12/09/2022, 6:04 PMenough-analyst-54434
12/09/2022, 6:04 PM./pants list project ::
the address syntax would've come to the fore.chilly-tailor-75063
12/09/2022, 6:05 PMenough-analyst-54434
12/09/2022, 6:05 PMchilly-tailor-75063
12/09/2022, 6:05 PMchilly-tailor-75063
12/09/2022, 6:06 PMenough-analyst-54434
12/09/2022, 6:07 PMdependencies
and filedeps
.chilly-tailor-75063
12/09/2022, 6:07 PMenough-analyst-54434
12/09/2022, 6:08 PMenough-analyst-54434
12/09/2022, 6:08 PMchilly-tailor-75063
12/09/2022, 6:09 PMenough-analyst-54434
12/09/2022, 6:09 PMchilly-tailor-75063
12/09/2022, 6:09 PM