https://pantsbuild.org/ logo
#general
Title
# general
e

echoing-london-29138

03/01/2022, 12:02 PM
Hi Everyone, I’m still trying to write a plugin in order to integrate import linter into pants. I’m almost there, but I’m struggling with the path resolution. So I would like to setup the PYTHONPATH in PexProcess using extra_env parameter. How can I get the list of the my pants roots directory so I can set it up in the environment of my linter ?
Copy code
process_result = await Get(
        FallibleProcessResult,
        PexProcess(
            importlinter_pex,
            argv=[],
            description="Running ImportLinter Playbook...",
            input_digest=merged_digest,
            level=LogLevel.DEBUG,
            extra_env={"PYTHONPATH": ":".join(pythonpath)},
            cache_scope=ProcessCacheScope.PER_RESTART_SUCCESSFUL,
        ),
    )
h

hundreds-father-404

03/01/2022, 3:23 PM
e

echoing-london-29138

03/01/2022, 3:36 PM
I’m using the version 2.9 and it seems a lot of code in order to get the Targets with dependencies, there is no simpler way ?
Or I should try to use the last version of pants ? (Is it recommended for my project to do that ? )
h

hundreds-father-404

03/01/2022, 3:39 PM
Version of Pants shouldn't matter here. Pylint was maybe a bad example because it does fancy stuff with partitioning the input. Pytest is simpler There should be 3 steps: 1. `TransitiveTargets`: https://github.com/pantsbuild/pants/blob/7e97ef6dfd50a8eb0294b6ded5e67dbd7da921df/src/python/pants/backend/python/goals/pytest_runner.py#L164 2.
PythonSourceFiles
to get the source roots + the source files. Use this rather than
SourceFiles
or
HydratedSources
. https://github.com/pantsbuild/pants/blob/7e97ef6dfd50a8eb0294b6ded5e67dbd7da921df/src/python/pants/backend/python/goals/pytest_runner.py#L187 3. The
env={"PEX_EXTRA_SYS_PATH": }
line
e

echoing-london-29138

03/01/2022, 4:45 PM
Done and it works 😄 Thanks a lot
💯 1
❤️ 1