wide-midnight-78598
02/02/2022, 6:11 AMpython_distribution
to add imports to the setup.py?
in setup_py.py
we have the following:
SETUP_BOILERPLATE = """
# DO NOT EDIT THIS FILE -- AUTOGENERATED BY PANTS
# Target: {target_address_spec}
from setuptools import setup
setup(**{setup_kwargs_str})
"""
but if I need another import in there, can that be added via the BUILD file? Or do I just need to use a custom setup.py/auto-generate my ownwide-midnight-78598
02/02/2022, 3:36 PMpython_distribution
target)
from setuptools import setup
from mypyc.build import mypycify
setup(
name="hellofib",
packages=["hellofib"],
ext_modules=mypycify(
[
"hellofib/__init__.py",
"hellofib/main.py",
]
),
)
When I have that setup.py in my root folder, it can't find mypy, which makes sense in the packaging workflow. As we don't have a compile workflow, leaving this under the python_distribution seems reasonable.
So, my plugin was going to add mypy to this target, and then ideally just change the SetupKwargs to stay as DRY as possible.
But, it's looking like I'll need to be able to add my own generate_setup_py
method. Does that exist natively? Or would that extension need to be added?wide-midnight-78598
02/02/2022, 3:37 PM@rule
async def generate_setup_py(request: GenerateSetupPyRequest) -> GeneratedSetupPy:
as that seems like the correct appraochwide-midnight-78598
02/02/2022, 6:28 PMwide-midnight-78598
02/02/2022, 7:23 PMbitter-ability-32190
02/02/2022, 7:38 PMsetup.py
file?bitter-ability-32190
02/02/2022, 7:39 PMwide-midnight-78598
02/02/2022, 7:40 PMbitter-ability-32190
02/02/2022, 7:41 PMsetup
callbitter-ability-32190
02/02/2022, 7:41 PM./pants_from_sources
😉wide-midnight-78598
02/02/2022, 7:43 PMbitter-ability-32190
02/02/2022, 7:47 PMbitter-ability-32190
02/02/2022, 7:49 PMbitter-ability-32190
02/02/2022, 7:49 PMI've been editing my cached pantsThat's dangerous, you won't have the ability to back up, and changes could get overblown accidentally 😉
wide-midnight-78598
02/02/2022, 7:50 PM@unions
to and logging - so nothing I'll forget about or anything worthwhile.bitter-ability-32190
02/02/2022, 7:51 PMbitter-ability-32190
02/02/2022, 7:52 PMwide-midnight-78598
02/02/2022, 7:53 PMValueError: Encountered 1 rule graph error:
Too many sources of dependency Get(GeneratedSetupPy, GenerateSetupPyRequest) for @rule(pants.backend.python.goals.setup_py:481:generate_chroot(DistBuildChrootRequest, SetupPyGeneration) -> DistBuildChroot, gets=[Get(DistBuildSources, DistBuildChrootRequest), Get(GeneratedSetupPy, GenerateSetupPyRequest), Get(PyDigest, PyMergeDigests), Get(StrippedSourceFileNames, SourcesPaths)]): [
"@rule(experimental.mypyc.rules:56:generate_setup_py(GenerateSetupPyRequest) -> GeneratedSetupPy, gets=[Get(FinalizedSetupKwargs, GenerateSetupPyRequest), Get(PyDigest, CreateDigest)]) (for GenerateSetupPyRequest)",
"@rule(pants.backend.python.goals.setup_py:518:generate_setup_py(GenerateSetupPyRequest) -> GeneratedSetupPy, gets=[Get(FinalizedSetupKwargs, GenerateSetupPyRequest), Get(PyDigest, CreateDigest)]) (for GenerateSetupPyRequest)",
]
That's a perfectly clear error to me.wide-midnight-78598
02/02/2022, 7:53 PMwide-midnight-78598
02/02/2022, 7:54 PMclass MyPycGenerateSetupPyRequest(GenerateSetupPyRequest):
pass
@rule(level=LogLevel.DEBUG)
async def generate_setup_py(request: MyPycGenerateSetupPyRequest) -> GeneratedSetupPy:
# Generate the setup script.
<http://logger.info|logger.info>("Inside the custom generate_setup_py function")
finalized_setup_kwargs = await Get(
FinalizedSetupKwargs, MyPycGenerateSetupPyRequest, request
bitter-ability-32190
02/02/2022, 7:54 PMbitter-ability-32190
02/02/2022, 7:55 PMwide-midnight-78598
02/02/2022, 7:56 PMwide-midnight-78598
02/02/2022, 7:56 PMValueError: Encountered 6 rule graph errors:
No installed rules return the type GenerateSetupPyRequest, and it was not provided by potential callers of @rule(pants.backend.python.goals.setup_py:518:generate_setup_py(GenerateSetupPyRequest) -> GeneratedSetupPy, gets=[Get(PyDigest, CreateDigest)]).
If that type should be computed by a rule, ensure that that rule is installed.
If it should be provided by a caller, ensure that it is included in any relevant Query or Get.
No installed rules return the type GenerateSetupPyRequest, and it was not provided by potential callers of @rule(pants.backend.python.goals.setup_py:534:generate_setup_py_kwargs(GenerateSetupPyRequest) -> FinalizedSetupKwargs, gets=[Get(ExportedTargetRequirements, DependencyOwner), Get(SetupKwargs, ExportedTarget), Get(ResolvedPythonDistributionEntryPoints, ResolvePythonDistributionEntryPointsRequest)]).
If that type should be computed by a rule, ensure that that rule is installed.
If it should be provided by a caller, ensure that it is included in any relevant Query or Get.
No source of dependency Get(ExportedTargetRequirements, DependencyOwner) for @rule(pants.backend.python.goals.setup_py:534:generate_setup_py_kwargs(GenerateSetupPyRequest) -> FinalizedSetupKwargs, gets=[Get(ExportedTargetRequirements, DependencyOwner), Get(SetupKwargs, ExportedTarget), Get(ResolvedPythonDistributionEntryPoints, ResolvePythonDistributionEntryPointsRequest)]). All potential sources were eliminated: []
No source of dependency Get(PyDigest, CreateDigest) for @rule(pants.backend.python.goals.setup_py:518:generate_setup_py(GenerateSetupPyRequest) -> GeneratedSetupPy, gets=[Get(PyDigest, CreateDigest)]). All potential sources were eliminated: []
No source of dependency Get(ResolvedPythonDistributionEntryPoints, ResolvePythonDistributionEntryPointsRequest) for @rule(pants.backend.python.goals.setup_py:534:generate_setup_py_kwargs(GenerateSetupPyRequest) -> FinalizedSetupKwargs, gets=[Get(ExportedTargetRequirements, DependencyOwner), Get(SetupKwargs, ExportedTarget), Get(ResolvedPythonDistributionEntryPoints, ResolvePythonDistributionEntryPointsRequest)]). All potential sources were eliminated: []
No source of dependency Get(SetupKwargs, ExportedTarget) for @rule(pants.backend.python.goals.setup_py:534:generate_setup_py_kwargs(GenerateSetupPyRequest) -> FinalizedSetupKwargs, gets=[Get(ExportedTargetRequirements, DependencyOwner), Get(SetupKwargs, ExportedTarget), Get(ResolvedPythonDistributionEntryPoints, ResolvePythonDistributionEntryPointsRequest)]). All potential sources were eliminated: []
wide-midnight-78598
02/02/2022, 7:58 PMbitter-ability-32190
02/02/2022, 7:58 PMbitter-ability-32190
02/02/2022, 7:58 PMwide-midnight-78598
02/02/2022, 8:00 PMbitter-ability-32190
02/02/2022, 8:26 PMbitter-ability-32190
02/02/2022, 8:27 PMbitter-ability-32190
02/02/2022, 8:34 PMbitter-ability-32190
02/02/2022, 8:38 PMmypyc
to be there it needs to be a (transitive) dependency in the target. I think your custom plugin code should be able to slip that inwide-midnight-78598
02/02/2022, 8:53 PMpython_distribution
renamed to mypyc_python_distribution
- so we get all the fields already for making a wheel, including ext_modules which already exists. To gather the source files, I use transitive dependencies to see what we have and add that to the mypycify function. I guess the interesting question is whether what I'm trying to achieve can be done strictly via a plugin - without touching mainline pants code. I have my doubts, but it's interesting to try to make it happen!bitter-ability-32190
02/02/2022, 8:57 PMbitter-ability-32190
02/02/2022, 8:58 PM__import__
shenanigans 🤮happy-kitchen-89482
02/02/2022, 10:38 PMhappy-kitchen-89482
02/02/2022, 10:38 PMhappy-kitchen-89482
02/02/2022, 10:38 PMhappy-kitchen-89482
02/02/2022, 10:38 PMhappy-kitchen-89482
02/02/2022, 10:40 PMhappy-kitchen-89482
02/02/2022, 10:40 PMhappy-kitchen-89482
02/02/2022, 10:40 PMhundreds-father-404
02/02/2022, 10:50 PMsetup()
function call itselfbitter-ability-32190
02/02/2022, 11:07 PMwide-midnight-78598
02/03/2022, 12:35 AMgenerate_setup_py
function. I was also looking at this for a cython project I have. Since it's so few files, I hand create the setup.py, not a big deal - but thinking bigger picture, it would be cool to have the option to pass in all my files, or a subset (situationally)wide-midnight-78598
02/03/2022, 12:37 AMhappy-kitchen-89482
02/03/2022, 1:07 AMhappy-kitchen-89482
02/03/2022, 1:08 AMwide-midnight-78598
02/03/2022, 1:14 AMwide-midnight-78598
02/03/2022, 1:14 AMhappy-kitchen-89482
02/03/2022, 1:28 AMwide-midnight-78598
02/03/2022, 1:32 AMdetermine_generate_setup_request
, everything looks good - but the place where I get stuck is the Rule, or Union, or mechanism that allows overriding the original generate_setup_py functionwide-midnight-78598
02/03/2022, 1:33 AMNo installed rules return the type GenerateSetupPyRequest, and it was not provided by potential callers of @rule(pants.backend.python.goals.setup_py:518:generate_setup_py(GenerateSetupPyRequest) -> GeneratedSetupPy, gets=[Get(PyDigest, CreateDigest)]).
If that type should be computed by a rule, ensure that that rule is installed.
If it should be provided by a caller, ensure that it is included in any relevant Query or Get.
wide-midnight-78598
02/03/2022, 1:34 AMdetermine_setup_kwargs
hundreds-father-404
02/03/2022, 2:52 AMwide-midnight-78598
02/03/2022, 2:54 AMhundreds-father-404
02/03/2022, 2:56 AMwide-midnight-78598
02/03/2022, 2:57 AMhundreds-father-404
02/03/2022, 2:59 AMwide-midnight-78598
02/03/2022, 4:38 AMwide-midnight-78598
02/03/2022, 2:59 PMpants_from_sources
isn't running correctly yet, so I need to debug that a little - but this setup was running when I was editing the cached pants 2.9.0 on my system. Thanks for all the help @hundreds-father-404!bitter-ability-32190
02/03/2022, 3:15 PMmypyc
expected to come from? Provided by the backend or in the user's reqs?bitter-ability-32190
02/03/2022, 3:17 PMpants.toml
[setuptools
🙌wide-midnight-78598
02/03/2022, 3:20 PMbitter-ability-32190
02/03/2022, 3:21 PMbitter-ability-32190
02/03/2022, 3:23 PMbitter-ability-32190
02/03/2022, 3:25 PMmypyc
wide-midnight-78598
02/03/2022, 3:25 PMbitter-ability-32190
02/03/2022, 3:25 PMbitter-ability-32190
02/03/2022, 3:30 PMpython_distribution
I see the same behaviorbitter-ability-32190
02/03/2022, 3:31 PMbitter-ability-32190
02/03/2022, 3:38 PM__init__.py
files to make mypy
happybitter-ability-32190
02/03/2022, 3:43 PMerror: Library stubs not installed for
🙂wide-midnight-78598
02/03/2022, 3:46 PMwide-midnight-78598
02/03/2022, 3:46 PMbitter-ability-32190
02/03/2022, 3:57 PMbitter-ability-32190
02/03/2022, 3:58 PMmypyc
, mypy
isn't being run an environment that has those installedwide-midnight-78598
02/03/2022, 4:08 PMwide-midnight-78598
02/03/2022, 4:09 PMwide-midnight-78598
02/03/2022, 4:09 PMbitter-ability-32190
02/03/2022, 4:20 PMwide-midnight-78598
02/03/2022, 4:22 PMbitter-ability-32190
02/03/2022, 4:27 PMpants/backend/python/pip_requirement.py:13: AssertionError:
With no output FFSwide-midnight-78598
02/03/2022, 4:28 PMbitter-ability-32190
02/03/2022, 4:28 PMmain
wide-midnight-78598
02/03/2022, 4:28 PMbitter-ability-32190
02/03/2022, 4:32 PMmypyc
assertions.bitter-ability-32190
02/03/2022, 4:32 PMbitter-ability-32190
02/03/2022, 4:32 PMmypy
on pants in a more strict mode to catch these earlywide-midnight-78598
02/03/2022, 4:33 PMbitter-ability-32190
02/03/2022, 4:33 PMpyright
)wide-midnight-78598
02/03/2022, 4:33 PMwide-midnight-78598
02/03/2022, 4:34 PMbitter-ability-32190
02/03/2022, 4:34 PMmypy
config, but not a pyright
onebitter-ability-32190
02/03/2022, 4:35 PMenv
file which clues VS Code into Pants' repo structure. SO pyright
worksbitter-ability-32190
02/03/2022, 4:35 PMFound 1369 errors in 503 files (checked 916 source files)
oh shitbitter-ability-32190
02/03/2022, 4:38 PMbitter-ability-32190
02/03/2022, 4:39 PMmypy
that's just goofy:
@property
def message_path(self):
return f"{self.path_str}.lock_message"
You really can't deduce the return type?wide-midnight-78598
02/03/2022, 4:41 PMwide-midnight-78598
02/03/2022, 4:41 PMbitter-ability-32190
02/03/2022, 4:45 PMbitter-ability-32190
02/03/2022, 5:03 PMwide-midnight-78598
02/03/2022, 5:13 PMbitter-ability-32190
02/03/2022, 5:18 PMmypy 0.930
issues, I still hit the same assert as on 0.910
There went an hour for nothing 😠bitter-ability-32190
02/03/2022, 5:19 PMmypy
0.930
now 🙄wide-midnight-78598
02/03/2022, 5:21 PMhundreds-father-404
02/03/2022, 5:26 PMI suppose I could make a PR to upgrade Pants' repo to mypy 0.930 nowYes please! I wanted to upgrade last week but reverted it because all the issues
bitter-ability-32190
02/03/2022, 5:27 PMwide-midnight-78598
02/03/2022, 5:43 PMwide-midnight-78598
02/03/2022, 5:44 PMbitter-ability-32190
02/03/2022, 5:50 PMinstall_requires
, but not necessarily be packaged with them?wide-midnight-78598
02/03/2022, 5:50 PMbitter-ability-32190
02/03/2022, 5:51 PMFile "mypy/nodes.py", line 2678, in __getitem__
pants/init/logging.py:111: KeyError: 'trace'
bitter-ability-32190
02/03/2022, 5:51 PMmypyc
doesn't care about #type: ignore[attr-defined]
wide-midnight-78598
02/03/2022, 5:51 PMwide-midnight-78598
02/03/2022, 5:52 PMbitter-ability-32190
02/03/2022, 5:52 PMbitter-ability-32190
02/03/2022, 5:54 PMFile "mypyc/irbuild/context.py", line 128, in curr_env_reg
pants/core/goals/lint.py:92: AssertionError:
wide-midnight-78598
02/03/2022, 5:55 PMbitter-ability-32190
02/03/2022, 5:58 PMbitter-ability-32190
02/03/2022, 5:58 PMbitter-ability-32190
02/03/2022, 5:58 PMpants/backend/python/lint/bandit/rules.py:23: KeyError: "'BanditRequest' has no attribute 'prior_formatter_result'"
bitter-ability-32190
02/03/2022, 5:58 PMbitter-ability-32190
02/03/2022, 6:00 PM--disallow-untyped-defs
that seems the easier route, lolbitter-ability-32190
02/03/2022, 6:00 PMpyannotate
? 🤔bitter-ability-32190
02/03/2022, 6:01 PMwide-midnight-78598
02/03/2022, 6:01 PMhundreds-father-404
02/03/2022, 6:02 PMOK you reeeealy need to set --disallow-untyped-defs that seems the easier route, lolI am ALL for making MyPy stricter in Pants. I'd love to do that. I only first started adding MyPy in 2020 iirc, so we still have some untyped code
how well-received would a PR to the pants repo be with a type-blastWell, but encouraged to do in several smaller PRs to make it easier to review
wide-midnight-78598
02/03/2022, 6:02 PMbitter-ability-32190
02/03/2022, 6:10 PMmypyc
doesn't like functions returning instances of inner-classeswide-midnight-78598
02/03/2022, 6:20 PMbitter-ability-32190
02/03/2022, 6:21 PMbitter-ability-32190
02/03/2022, 6:22 PM