I’m trying to set up debugging (for the test and r...
# general
r
I’m trying to set up debugging (for the test and run goals) in VSCode but I’m hitting a problem that google isn’t helping with and I can’t find an issue related to. I’m running pants 2.14 on an M1 mac with Python 3.9. When I try to run
./pants test --debug-adapter <path to test file>
I get the following error:
Copy code
15:06:23.64 [INFO] Completed: Building pytest_runner.pex
15:06:23.64 [ERROR] 1 Exception encountered:

  ProcessExecutionFailure: Process 'Building pytest_runner.pex' failed with exit code 1.
stdout:

stderr:
A distribution for debugpy could not be resolved for ~/.pyenv/versions/3.9.15/bin/python3.9.
Found 1 distribution for debugpy that do not apply:
1.) The wheel tags for debugpy 1.6.0 are cp38-cp38-macosx_10_15_x86_64 which do not match the supported tags of ~/.pyenv/versions/3.9.15/bin/python3.9:
cp39-cp39-macosx_13_0_arm64
... 409 more ...
It seems that debugpy is a requirement of pants itself, pinned at 1.6.0 but there does seem to be py3.9 wheels available for it. I tried adding debugpy to my own 3rd party requirements but that didn’t seem to help. Any ideas on how to get around this. Not being able to debug in VSCode is a bit of a pain.
👀 1
b
You should be able to bump debugpy's version by setting https://www.pantsbuild.org/docs/reference-debugpy#version Additionally, we can (and should) bump the version Pants references. Mind filing an issue?
r
I’ve given this a go and it doesn’t solve the issue, the same error occurs (just replace 1.6.0 with 1.6.3 in the message). Looking here https://pypi.org/project/debugpy/#files I think it means there aren’t any wheels for the arm architecture (I’m on an M1 mac). Is there a way to get pants to build it locally rather than trying to download a prebuilt wheel?
👀 1
b
Ah I glossed over the PyPI page originally, didn't notice the Mac arm binaries weren't there 😕
r
Neither did I initially
b
The Python packaging ecosystem is such a mess 😮‍💨 Not sure about the binary vs source thing. PEX should allow it but I'm staring at the hierarchy of code
I don't think there's an "easy" way though 😐
Techincally I think https://github.com/pantsbuild/pants/issues/12449 would solve this. Mind commenting there with your use case (debugpy)? I think this is the first time we've seen debugpy needing this solution. And I really wanna drum up support 🙂
1
Might be worth a ping on https://github.com/microsoft/debugpy/issues/184 as well (I added mine)
1
Ohhh whoops. Try setting the version as well as https://www.pantsbuild.org/docs/reference-debugpy#lockfile, then running
./pants generate-lockfiles --reolve=debugpy
on your machine. That will make a new lockfile you check into your repo and I suspect if you run that on a mac, it'll work 🤞
r
That is what I did the first time with no luck I’m afraid
b
Hmm whats the lockfile look like?
r
Copy code
// This lockfile was autogenerated by Pants. To regenerate, run:
//
//    ./pants generate-lockfiles --resolve=debugpy
//
// --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
// {
//   "version": 3,
//   "valid_for_interpreter_constraints": [
//     "CPython<3.11,>=3.7"
//   ],
//   "generated_with_requirements": [
//     "debugpy==1.6.3",
//     "importlib_metadata==1.4.0"
//   ],
//   "manylinux": "manylinux2014",
//   "requirement_constraints": [],
//   "only_binary": [],
//   "no_binary": []
// }
// --- END PANTS LOCKFILE METADATA ---

{
  "allow_builds": true,
  "allow_prereleases": false,
  "allow_wheels": true,
  "build_isolation": true,
  "constraints": [],
  "locked_resolves": [
    {
      "locked_requirements": [
        {
          "artifacts": [
            {
              "algorithm": "sha256",
              "hash": "84c39940a0cac410bf6aa4db00ba174f973eef521fbe9dd058e26bcabad89c4f",
              "url": "<https://files.pythonhosted.org/packages/e4/d6/ed74635ad235293a77f65ccaa17ac3c6012839126f0512a5a53c7cbf82ff/debugpy-1.6.3-py2.py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "d5c814596a170a0a58fa6fad74947e30bfd7e192a5d2d7bd6a12156c2899e13a",
              "url": "<https://files.pythonhosted.org/packages/3e/00/9616d339b132f80d0772c28e1119cec24a54d0b3a13a63468af23729253f/debugpy-1.6.3-cp37-cp37m-macosx_10_15_x86_64.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "b8deaeb779699350deeed835322730a3efec170b88927debc9ba07a1a38e2585",
              "url": "<https://files.pythonhosted.org/packages/5a/e6/476865a057fe515b2048d9a01b6b270a9eccbd40ec6da7dc3061476faec4/debugpy-1.6.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "e8922090514a890eec99cfb991bab872dd2e353ebb793164d5f01c362b9a40bf",
              "url": "<https://files.pythonhosted.org/packages/8f/23/8dd369ef3a92bf5fdb4bf0cb84b721efbec43ae81b4f3694f6214b20d6d6/debugpy-1.6.3.zip>"
            },
            {
              "algorithm": "sha256",
              "hash": "c4b2bd5c245eeb49824bf7e539f95fb17f9a756186e51c3e513e32999d8846f3",
              "url": "<https://files.pythonhosted.org/packages/92/ec/65a8c523e87a75c2dbe044196a8f171870ad6be8ec820d2364e701feb8c7/debugpy-1.6.3-cp310-cp310-macosx_10_15_x86_64.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "4e255982552b0edfe3a6264438dbd62d404baa6556a81a88f9420d3ed79b06ae",
              "url": "<https://files.pythonhosted.org/packages/ad/2a/eaeb7a147a7e978d3e8c591771058862edb18af69431039933d833bc3d33/debugpy-1.6.3-cp39-cp39-macosx_10_15_x86_64.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "adcfea5ea06d55d505375995e150c06445e2b20cd12885bcae566148c076636b",
              "url": "<https://files.pythonhosted.org/packages/ae/9c/a3e68bab0a3b5395b623dec6b0d4caf2cbc8001e6943187873e1869e5a03/debugpy-1.6.3-cp38-cp38-macosx_10_15_x86_64.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "daadab4403427abd090eccb38d8901afd8b393e01fd243048fab3f1d7132abb4",
              "url": "<https://files.pythonhosted.org/packages/d2/e3/d0531ee73216d553d717bf4ac51dff297f89054619fa69db61eef028a07f/debugpy-1.6.3-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "c4cd6f37e3c168080d61d698390dfe2cd9e74ebf80b448069822a15dadcda57d",
              "url": "<https://files.pythonhosted.org/packages/e4/fc/555a80da24d0608660f69aad6da45cce890f1b2d055d4d4cd6ed9cf0ea20/debugpy-1.6.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "cca23cb6161ac89698d629d892520327dd1be9321c0960e610bbcb807232b45d",
              "url": "<https://files.pythonhosted.org/packages/e6/bb/614cfb27df644883e8db05dc4f47e9f3919303a8b125127933262a157847/debugpy-1.6.3-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl>"
            }
          ],
          "project_name": "debugpy",
          "requires_dists": [],
          "requires_python": ">=3.7",
          "version": "1.6.3"
        },
        {
          "artifacts": [
            {
              "algorithm": "sha256",
              "hash": "bdd9b7c397c273bcc9a11d6629a38487cd07154fa255a467bf704cd2c258e359",
              "url": "<https://files.pythonhosted.org/packages/d7/31/74dcb59a601b95fce3b0334e8fc9db758f78e43075f22aeb3677dfb19f4c/importlib_metadata-1.4.0-py2.py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "f17c015735e1a88296994c0697ecea7e11db24290941983b08c9feb30921e6d8",
              "url": "<https://files.pythonhosted.org/packages/8c/0e/10e247f40c89ba72b7f2a2104ccf1b65de18f79562ffe11bfb837b711acf/importlib_metadata-1.4.0.tar.gz>"
            }
          ],
          "project_name": "importlib-metadata",
          "requires_dists": [
            "configparser>=3.5; python_version < \"3\"",
            "contextlib2; python_version < \"3\"",
            "importlib-resources; python_version < \"3.7\" and extra == \"testing\"",
            "packaging; extra == \"testing\"",
            "pathlib2; python_version < \"3\"",
            "rst.linker; extra == \"docs\"",
            "sphinx; extra == \"docs\"",
            "zipp>=0.5"
          ],
          "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7",
          "version": "1.4"
        },
        {
          "artifacts": [
            {
              "algorithm": "sha256",
              "hash": "83a28fcb75844b5c0cdaf5aa4003c2d728c77e05f5aeabe8e95e56727005fbaa",
              "url": "<https://files.pythonhosted.org/packages/d8/20/256eb3f3f437c575fb1a2efdce5e801a5ce3162ea8117da96c43e6ee97d8/zipp-3.11.0-py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "a7a22e05929290a67401440b39690ae6563279bced5f314609d9d03798f56766",
              "url": "<https://files.pythonhosted.org/packages/8e/b3/8b16a007184714f71157b1a71bbe632c5d66dd43bc8152b3c799b13881e1/zipp-3.11.0.tar.gz>"
            }
          ],
          "project_name": "zipp",
          "requires_dists": [
            "flake8<5; extra == \"testing\"",
            "func-timeout; extra == \"testing\"",
            "furo; extra == \"docs\"",
            "jaraco.functools; extra == \"testing\"",
            "jaraco.itertools; extra == \"testing\"",
            "jaraco.packaging>=9; extra == \"docs\"",
            "jaraco.tidelift>=1.4; extra == \"docs\"",
            "more-itertools; extra == \"testing\"",
            "pytest-black>=0.3.7; platform_python_implementation != \"PyPy\" and extra == \"testing\"",
            "pytest-checkdocs>=2.4; extra == \"testing\"",
            "pytest-cov; extra == \"testing\"",
            "pytest-enabler>=1.3; extra == \"testing\"",
            "pytest-flake8; python_version < \"3.12\" and extra == \"testing\"",
            "pytest-mypy>=0.9.1; platform_python_implementation != \"PyPy\" and extra == \"testing\"",
            "pytest>=6; extra == \"testing\"",
            "rst.linker>=1.9; extra == \"docs\"",
            "sphinx>=3.5; extra == \"docs\""
          ],
          "requires_python": ">=3.7",
          "version": "3.11"
        }
      ],
      "platform_tag": null
    }
  ],
  "path_mappings": {},
  "pex_version": "2.1.108",
  "pip_version": "20.3.4-patched",
  "prefer_older_binary": false,
  "requirements": [
    "debugpy==1.6.3",
    "importlib_metadata==1.4.0"
  ],
  "requires_python": [
    "<3.11,>=3.7"
  ],
  "resolver_version": "pip-2020-resolver",
  "style": "universal",
  "target_systems": [
    "linux",
    "mac"
  ],
  "transitive": true,
  "use_pep517": null
}
b
One of the artifacts IS the zip 🤔
Copy code
debugpy-1.6.3.zip"
OK we're out of my area of expertise, unfortunately
Do you set any other relevant options? Anything for https://www.pantsbuild.org/docs/reference-pex-cli?
r
Nothing set for pex-cli
😢 1
Looks like https://github.com/pantsbuild/pex/issues/1384 might be the same issue
b
Ahhhhh good find
r
Not sure how it helps me solve the issue though. I’ve tried uninstalling the two x86 python versions I has installed but to no avail
b
oh duh, theres a workaround if you wanna try it, its not quite the same. • add debugpy to your reqs and re-lock (if needed based on your pants config) • somewhere high up add
Copy code
import debugpy
debugpy.listen(("localhost", 5678))
• run
./pants test --debug ...
oh and maybe ``wait_for_client()`
r
as in add that import somewhere high up in my test code for the specific test I want to test?
b
Yup. Or an
__init__
. Or a high-level pytest plugin, or a
conftest.py
. Basically anywhere it'll get executed "early"
That was the "old" way before I added invoking
-m debugpy
directly from pants
r
awesome thanks, I’ll have to give that a go tomorrow now but I’ll report back on my progress
b
👍
e
Perhaps its not clear, but this message:
Copy code
15:06:23.64 [INFO] Completed: Building pytest_runner.pex
15:06:23.64 [ERROR] 1 Exception encountered:

  ProcessExecutionFailure: Process 'Building pytest_runner.pex' failed with exit code 1.
stdout:

stderr:
A distribution for debugpy could not be resolved for ~/.pyenv/versions/3.9.15/bin/python3.9.
Found 1 distribution for debugpy that do not apply:
1.) The wheel tags for debugpy 1.6.0 are cp38-cp38-macosx_10_15_x86_64 which do not match the supported tags of ~/.pyenv/versions/3.9.15/bin/python3.9:
cp39-cp39-macosx_13_0_arm64
... 409 more ...
Refers not to resolving dependencies from the internet, but resolving them from a built PEX. In other words, the PEX file contains only Python 3.8 debugpy, but the PEX was launched with Python 3.9; so no dice. Towards that end, from a quick read of code, it looks like the debugpy subsystem, although it supports ICs, is requested without them: https://github.com/pantsbuild/pants/blob/8fd8960ccb014f0e0bade811db970d513aedcef2/src/python/pants/backend/python/goals/pytest_runner.py#L543 I think that means maybe the ambient interpreter running Pants (3.9 in your case?), is what gets used to build that Pex. And that does not match the test batch in question which uses 3.8. Just a guess.
I may have reversed 3.8's and 3.9's there, but same bug idea seems ~rightish.
b
🥲
I'll fix this tomorrow and cherry pick.
@ripe-scooter-10665 or @enough-analyst-54434 feel free to file an issue
e
I'll let you have at it. This was just a guess. The pex issue pointed to is fixed if read more closely, I just never followed up to ask Chris to re-test and close. So got me looking and reading.
r
b
I'm glad more people are starting to use this feature. I'm really proud of it and I think the experience of turnkey debugging is admirable