Do folks use pants in their pre-commit hooks? I'm ...
# general
s
Do folks use pants in their pre-commit hooks? I'm trying it out for running
black
and
flake8
. My only concern is it feels a little slow (takes like 6+ seconds) where as before it was more or less instant. Any tricks for speeding things up?
w
Running those two calling python directly was instant (let's say... 100ms?), while using
pants fmt lint
takes 6+ seconds? Can you show your pre-commit before/after? I should note, I've moved a lot of my precommit stuff to pre-push, because I don't care what my devs do while they're not pushing. For pants, are you using
--changed-since
? https://github.com/sureshjoshi/pants-plugins/blob/main/build-support/githooks/pre-commit
s
I'm using that script! Thanks for writing it! I guess I forgot to mention I'm also running
update-build-files
.
If I run time I guess it's closer to
0m2.272s
. This still feels like a long time
At one point I think I counted 6 seconds in my head. I'm not sure how to reproduce that though*
w
Possibly you changed something in your pants.toml, and that probably re-initialized some stuff. After "first run" is typically how I measure. 2 seconds still feels like a decent chunk - are you typechecking as well? mypy is notoriously slow
s
I'm not using mypy
I don't think there's anything too odd in
Copy code
[GLOBAL]
pants_version = "2.16.0"

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

[anonymous-telemetry]
enabled = false

[python]
enable_resolves = true
interpreter_constraints = ["CPython==3.10.*"]

[python.resolves]
python-default = "3rdparty/python/default.lock"

[python-repos]
indexes.add = ["https://%(env.FURY_AUTH)s:@pypi.fury.io/amlg/"]

[debugpy]
interpreter_constraints = ["CPython==3.10.*"]
install_from_resolve = "python-default"

[pytest]
install_from_resolve = "python-default"
requirements = [
  "//:reqs-dev#pytest",
  "//:reqs-dev#freezegun",
  "//:reqs-dev#pytest-mock",
  "//:reqs-dev#responses",
  "//:reqs-dev#pytest-cov"
]

[black]
interpreter_constraints = ["CPython==3.10.*"]
install_from_resolve = "python-default"
requirements = ["//:reqs-dev#black"]

[flake8]
install_from_resolve = "python-default"
requirements = ["//:reqs-dev#flake8"]

[repl]
shell = "ipython"

[subprocess-environment]
env_vars = [
  'GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1',
  'GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1',
  'GRPC_BUILD_WITH_BORING_SSL_ASM=',
]
Ah - changining the toml might have caused the slow check.
w
Changing TOML will for sure cause a slow first check, that’s basically a guarantee… However, even still, it shouldn’t be THAT much slower on your run-to-run