bitter-ability-32190
05/09/2022, 3:27 PMCycleException
(only if I use explicit python_source
though).
a.py depends on b.py depends (for type-checking) on a.py
BUILD.pants
# no error
python_sources()
# Error
python_source(name="a", source="a.py")
python_source(name="b", source="b.py")
# Also no error
python_sources(name="a", sources=["a.py"])
python_sources(name="b", sources=["b.py"])
This seems... unexpectedfast-nail-55400
05/09/2022, 3:36 PMfast-nail-55400
05/09/2022, 3:37 PMCoarsenedTarget
. But JVM compilers can handle cycles when given all of the files in the cycle.bitter-ability-32190
05/09/2022, 3:37 PMif TYPE_CHECKING
, which in this case it is. (or any other dynamic/delayed importing)fast-nail-55400
05/09/2022, 3:38 PMif
clauses.fast-nail-55400
05/09/2022, 3:38 PMpython_sources
case?bitter-ability-32190
05/09/2022, 3:39 PMimport
statements at any level in any part of the code.
I think you're missing the forest for the trees though. How come when I use a generator there's no error but when not it errors. Seems like an annoying gotcha.fast-nail-55400
05/09/2022, 3:40 PMWhat does dependency inference do in theUsing a generator doesn’t imply that the generated targets have dependencies on each other unless the backend opts in to that behavior.case?python_sources
fast-nail-55400
05/09/2022, 3:41 PMbitter-ability-32190
05/09/2022, 3:44 PM./pants peek a.py b.py
[
{
"address": "dirname/a.py:dirname",
"target_type": "python_source",
"dependencies": [
"dirname/b.py:dirname"
],
"dependencies_raw": null,
"description": null,
"interpreter_constraints": null,
"resolve": null,
"skip_black": false,
"skip_flake8": false,
"skip_isort": false,
"skip_mypy": false,
"skip_pylint": false,
"source_raw": "a.py",
"sources": [
"dirname/a.py"
],
"tags": null
},
{
"address": "dirname/b.py:dirname",
"target_type": "python_source",
"dependencies": [
"dirname/a.py:dirname"
],
"dependencies_raw": null,
"description": null,
"interpreter_constraints": null,
"resolve": null,
"skip_black": false,
"skip_flake8": false,
"skip_isort": false,
"skip_mypy": false,
"skip_pylint": false,
"source_raw": "b.py",
"sources": [
"dirname/b.py"
],
"tags": null
}
]
fast-nail-55400
05/09/2022, 3:44 PMbitter-ability-32190
05/09/2022, 3:45 PMmypy
doesn't complain on missing import.
But for organizational reasons I have to switch to non-generator targets. So this is surprising.bitter-ability-32190
05/09/2022, 3:46 PMfast-nail-55400
05/09/2022, 3:48 PMfast-nail-55400
05/09/2022, 3:49 PMfast-nail-55400
05/09/2022, 3:49 PM./pants peek
?bitter-ability-32190
05/09/2022, 3:49 PMlint
, which I assume is where Pants starts grabbing transitive deps.bitter-ability-32190
05/09/2022, 3:50 PMpeek
as well)fast-nail-55400
05/09/2022, 3:51 PMlint
rule should use CoarsenedTarget
?bitter-ability-32190
05/09/2022, 3:51 PMfast-nail-55400
05/09/2022, 3:51 PMfast-nail-55400
05/09/2022, 3:52 PMsources
or `source`: https://github.com/pantsbuild/pants/blob/2572c5063af96c3268e58b1e78e99cdd55650150/src/python/pants/core/goals/lint.py#L320fast-nail-55400
05/09/2022, 3:53 PMbitter-ability-32190
05/09/2022, 3:56 PMlint
might be a red herring herebitter-ability-32190
05/09/2022, 3:58 PMpeek
works 😮bitter-ability-32190
05/09/2022, 4:00 PMpeek
might not care about cycles. It just reports what's there.bitter-ability-32190
05/09/2022, 4:01 PMtest
errors as well. lint
is a red herring 🟥 🐟bitter-ability-32190
05/09/2022, 4:07 PMis_file_target
here:
https://github.com/pantsbuild/pants/blob/8dd95105ad5aa917034786cbf8146b5715431a45/src/python/pants/engine/internals/graph.py#L400bitter-ability-32190
05/09/2022, 4:09 PMpython_sources
is_file_target
is False
, but with python_source
its True
witty-crayon-22786
05/09/2022, 4:26 PMbitter-ability-32190
05/09/2022, 4:29 PMbitter-ability-32190
05/09/2022, 4:29 PMpython_source
equivalent target which acts like it was "generated"?witty-crayon-22786
05/09/2022, 4:30 PMpython_sources
=Pbitter-ability-32190
05/09/2022, 4:30 PMbitter-ability-32190
05/09/2022, 4:32 PMpython_sources
with one source still makes the target address include the filename which isn't ideal in my constrained ecosystem.witty-crayon-22786
05/09/2022, 4:32 PMbitter-ability-32190
05/09/2022, 4:32 PMbitter-ability-32190
05/09/2022, 4:32 PMwitty-crayon-22786
05/09/2022, 4:33 PMthe target address include the filenamethe
Address
type is what triggers the behavior, so you probably can’t get both the cycle behavior and address the way you want.witty-crayon-22786
05/09/2022, 4:35 PMbitter-ability-32190
05/09/2022, 4:39 PMhundreds-father-404
05/09/2022, 4:45 PMwitty-crayon-22786
05/09/2022, 4:46 PMhundreds-father-404
05/09/2022, 4:46 PM