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

incalculable-yacht-75851

05/10/2022, 5:54 PM
I'm attempting to pin black to
black==21.12b0
(as was configured by default in pants 2.9) in my pants.toml I have the following
Copy code
[GLOBAL]
pants_version = "2.11.0"

backend_packages.add = [
  "pants.backend.python",
  "pants.backend.python.lint.black",
]

[python]
interpreter_constraints = [">=3.9"]
tailor_requirements_targets = false
enable_resolves = true # for use with lock file
resolves = { python-default = "3rdparty/python/python-default.lock" }
default_resolve = "python-default"
lockfile_generator = "pex"

[coverage-py]
interpreter_constraints = [">=3.9"]

[test]
use_coverage = true

[pytest]
version = "pytest>=6.2.4,<6.3"
extra_requirements.add = [
  "pytest-django>=4,<5",
]
lockfile="3rdparty/python/pytest.lock"

[black]
version = "black==21.12b0"
interpreter_constraints = [">=3.9"]
lockfile="3rdparty/python/black.lock"
1
I'm getting the following error when trying to run lint goal.
Copy code
➜  monorepo git:(developer-tooling/pants-upgrade) ✗ ./pantsv2 lint ::
10:56:30.00 [ERROR] Completed: Lint with Black - black failed (exit code 1).
Traceback (most recent call last):
  File ".cache/pex_root/venvs/c0b86b57995eab6f84dfbd06344b0899b7dc2b2f/80f5c4dc0e77a5b728d2e9547d721df713b9ebc9/pex", line 182, in <module>
    sys.exit(func())
  File "/Users/KHowa8/.cache/pants/named_caches/pex_root/venvs/c0b86b57995eab6f84dfbd06344b0899b7dc2b2f/80f5c4dc0e77a5b728d2e9547d721df713b9ebc9/lib/python3.9/site-packages/black/__init__.py", line 1372, in patched_main
    patch_click()
  File "/Users/KHowa8/.cache/pants/named_caches/pex_root/venvs/c0b86b57995eab6f84dfbd06344b0899b7dc2b2f/80f5c4dc0e77a5b728d2e9547d721df713b9ebc9/lib/python3.9/site-packages/black/__init__.py", line 1358, in patch_click
    from click import _unicodefun
ImportError: cannot import name '_unicodefun' from 'click' (/Users/KHowa8/.cache/pants/named_caches/pex_root/venvs/c0b86b57995eab6f84dfbd06344b0899b7dc2b2f/80f5c4dc0e77a5b728d2e9547d721df713b9ebc9/lib/python3.9/site-packages/click/__init__.py)


✕ black failed.
h

hundreds-father-404

05/10/2022, 5:58 PM
Hm. And to double check, did you
generate-lockfiles
or
generate-lockfiles --resolve=black
?
i

incalculable-yacht-75851

05/10/2022, 5:58 PM
I did. Twice!
h

hundreds-father-404

05/10/2022, 5:59 PM
Okay fishy. Could you please share the contents of
black.lock
?
i

incalculable-yacht-75851

05/10/2022, 6:00 PM
Copy code
// This lockfile was autogenerated by Pants. To regenerate, run:
//
//    ./pantsv2 generate-lockfiles --resolve=black
//
// --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
// {
//   "version": 2,
//   "valid_for_interpreter_constraints": [
//     "CPython>=3.9"
//   ],
//   "generated_with_requirements": [
//     "black==21.12b0",
//     "typing-extensions>=3.10.0.0; python_version < \"3.10\""
//   ]
// }
// --- 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": "a615e69ae185e08fdd73e4715e260e2479c861b5740057fde6e8b4e3b7dd589f",
              "url": "<https://files.pythonhosted.org/packages/9b/27/b2f98b627738b02dcac06ae9e2ab13f14ab906fe6dd6366050c76883d4b5/black-21.12b0-py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "77b80f693a569e2e527958459634f18df9b0ba2625ba4e0c2d5da5be42e6f2b3",
              "url": "<https://files.pythonhosted.org/packages/f7/60/7a9775dc1b81a572eb26836c7e77c92bf454ada00693af4b2d2f2614971a/black-21.12b0.tar.gz>"
            }
          ],
          "project_name": "black",
          "requires_dists": [
            "aiohttp>=3.7.4; extra == \"d\"",
            "click>=7.1.2",
            "colorama>=0.4.3; extra == \"colorama\"",
            "dataclasses>=0.6; python_version < \"3.7\"",
            "ipython>=7.8.0; extra == \"jupyter\"",
            "mypy-extensions>=0.4.3",
            "pathspec<1,>=0.9.0",
            "platformdirs>=2",
            "tokenize-rt>=3.2.0; extra == \"jupyter\"",
            "tomli<2.0.0,>=0.2.6",
            "typed-ast>=1.4.2; python_version < \"3.8\" and implementation_name == \"cpython\"",
            "typed-ast>=1.4.3; extra == \"python2\"",
            "typing-extensions!=3.10.0.1; python_version >= \"3.10\"",
            "typing-extensions>=3.10.0.0",
            "uvloop>=0.15.2; extra == \"uvloop\""
          ],
          "requires_python": ">=3.6.2",
          "version": "21.12b0"
        },
        {
          "artifacts": [
            {
              "algorithm": "sha256",
              "hash": "bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48",
              "url": "<https://files.pythonhosted.org/packages/c2/f1/df59e28c642d583f7dacffb1e0965d0e00b218e0186d7858ac5233dce840/click-8.1.3-py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e",
              "url": "<https://files.pythonhosted.org/packages/59/87/84326af34517fca8c58418d148f2403df25303e02736832403587318e9e8/click-8.1.3.tar.gz>"
            }
          ],
          "project_name": "click",
          "requires_dists": [
            "colorama; platform_system == \"Windows\"",
            "importlib-metadata; python_version < \"3.8\""
          ],
          "requires_python": ">=3.7",
          "version": "8.1.3"
        },
        {
          "artifacts": [
            {
              "algorithm": "sha256",
              "hash": "9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2",
              "url": "<https://files.pythonhosted.org/packages/44/98/5b86278fbbf250d239ae0ecb724f8572af1c91f4a11edf4d36a206189440/colorama-0.4.4-py2.py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b",
              "url": "<https://files.pythonhosted.org/packages/1f/bb/5d3246097ab77fa083a61bd8d3d527b7ae063c7d8e8671b1cf8c4ec10cbe/colorama-0.4.4.tar.gz>"
            }
          ],
          "project_name": "colorama",
          "requires_dists": [],
          "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7",
          "version": "0.4.4"
        },
        {
          "artifacts": [
            {
              "algorithm": "sha256",
              "hash": "090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d",
              "url": "<https://files.pythonhosted.org/packages/5c/eb/975c7c080f3223a5cdaff09612f3a5221e4ba534f7039db34c35d95fa6a5/mypy_extensions-0.4.3-py2.py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8",
              "url": "<https://files.pythonhosted.org/packages/63/60/0582ce2eaced55f65a4406fc97beba256de4b7a95a0034c6576458c6519f/mypy_extensions-0.4.3.tar.gz>"
            }
          ],
          "project_name": "mypy-extensions",
          "requires_dists": [
            "typing>=3.5.3; python_version < \"3.5\""
          ],
          "requires_python": null,
          "version": "0.4.3"
        },
        {
          "artifacts": [
            {
              "algorithm": "sha256",
              "hash": "7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a",
              "url": "<https://files.pythonhosted.org/packages/42/ba/a9d64c7bcbc7e3e8e5f93a52721b377e994c22d16196e2b0f1236774353a/pathspec-0.9.0-py2.py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1",
              "url": "<https://files.pythonhosted.org/packages/f6/33/436c5cb94e9f8902e59d1d544eb298b83c84b9ec37b5b769c5a0ad6edb19/pathspec-0.9.0.tar.gz>"
            }
          ],
          "project_name": "pathspec",
          "requires_dists": [],
          "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7",
          "version": "0.9"
        },
        {
          "artifacts": [
            {
              "algorithm": "sha256",
              "hash": "027d8e83a2d7de06bbac4e5ef7e023c02b863d7ea5d079477e722bb41ab25788",
              "url": "<https://files.pythonhosted.org/packages/ed/22/967181c94c3a4063fe64e15331b4cb366bdd7dfbf46fcb8ad89650026fec/platformdirs-2.5.2-py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "58c8abb07dcb441e6ee4b11d8df0ac856038f944ab98b7be6b27b2a3c7feef19",
              "url": "<https://files.pythonhosted.org/packages/ff/7b/3613df51e6afbf2306fc2465671c03390229b55e3ef3ab9dd3f846a53be6/platformdirs-2.5.2.tar.gz>"
            }
          ],
          "project_name": "platformdirs",
          "requires_dists": [
            "appdirs==1.4.4; extra == \"test\"",
            "furo>=2021.7.5b38; extra == \"docs\"",
            "proselint>=0.10.2; extra == \"docs\"",
            "pytest-cov>=2.7; extra == \"test\"",
            "pytest-mock>=3.6; extra == \"test\"",
            "pytest>=6; extra == \"test\"",
            "sphinx-autodoc-typehints>=1.12; extra == \"docs\"",
            "sphinx>=4; extra == \"docs\""
          ],
          "requires_python": ">=3.7",
          "version": "2.5.2"
        },
        {
          "artifacts": [
            {
              "algorithm": "sha256",
              "hash": "e3069e4be3ead9668e21cb9b074cd948f7b3113fd9c8bba083f48247aab8b11c",
              "url": "<https://files.pythonhosted.org/packages/05/e4/74f9440db36734d7ba83c574c1e7024009ce849208a41f90e94a134dc6d1/tomli-1.2.3-py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "05b6166bff487dc068d322585c7ea4ef78deed501cc124060e0f238e89a9231f",
              "url": "<https://files.pythonhosted.org/packages/fb/2e/d0a8276b0cf9b9e34fd0660c330acc59656f53bb2209adc75af863a3582d/tomli-1.2.3.tar.gz>"
            }
          ],
          "project_name": "tomli",
          "requires_dists": [],
          "requires_python": ">=3.6",
          "version": "1.2.3"
        },
        {
          "artifacts": [
            {
              "algorithm": "sha256",
              "hash": "6657594ee297170d19f67d55c05852a874e7eb634f4f753dbd667855e07c1708",
              "url": "<https://files.pythonhosted.org/packages/75/e1/932e06004039dd670c9d5e1df0cd606bf46e29a28e65d5bb28e894ea29c9/typing_extensions-4.2.0-py3-none-any.whl>"
            },
            {
              "algorithm": "sha256",
              "hash": "f1c24655a0da0d1b67f07e17a5e6b2a105894e6824b92096378bb3668ef02376",
              "url": "<https://files.pythonhosted.org/packages/fe/71/1df93bd59163c8084d812d166c907639646e8aac72886d563851b966bf18/typing_extensions-4.2.0.tar.gz>"
            }
          ],
          "project_name": "typing-extensions",
          "requires_dists": [],
          "requires_python": ">=3.7",
          "version": "4.2"
        }
      ],
      "platform_tag": [
        "cp310",
        "cp310",
        "macosx_12_0_arm64"
      ]
    }
  ],
  "path_mappings": {},
  "pex_version": "2.1.84",
  "prefer_older_binary": false,
  "requirements": [
    "black==21.12b0",
    "typing-extensions>=3.10.0.0; python_version < \"3.10\""
  ],
  "requires_python": [
    ">=3.9"
  ],
  "resolver_version": "pip-2020-resolver",
  "style": "universal",
  "transitive": true,
  "use_pep517": null
}
For now I'm adding "skip_black=True" to BUILD files rather than re-formatting all of the files. It's not ideal, but I'll fast-follow w/ a format commit.
I'd really love to pin the version but apparently, that's not a thing for black today.
h

hundreds-father-404

05/12/2022, 3:34 PM
Sorry for my delay! Trying to reproduce
Excellent, I reproduce. Thanks for the report! I'll look into this
@incalculable-yacht-75851 figured it out. https://stackoverflow.com/questions/71673404/importerror-cannot-import-name-unicodefun-from-click Add this:
Copy code
[black]
# We must pin Click until we can upgrade Black's version. See <https://stackoverflow.com/questions/71673404/importerror-cannot-import-name-unicodefun-from-click>
extra_requirements.add = ["click<8.1"]
Then
./pants generate-lockfiles --resolve=black
(this isn't a pants or pex issue; Black wasn't metadata correctly)
7 Views