RobertCraigie / pyright-python

Python command line wrapper for pyright, a static type checker
https://pypi.org/project/pyright/
MIT License
164 stars 22 forks source link

pre-commit fails inside a docker container: nodeenv returned non-zero exit status 2 #258

Open lexicalunit opened 5 months ago

lexicalunit commented 5 months ago

I've dockerized my project and I want to be able to execute pre-commit hooks within the container. This currently work for everything except pyright.

Here's my .pre-commit-config.yaml file:

repos:
  - repo: local
    hooks:
      - id: pyright
        name: pyright
        entry: scripts/type-check.sh
        language: system
        types: [python]
        pass_filenames: true

Here's my scripts/type-check.sh:

#!/bin/bash -ue

if [[ -n $* ]]; then

    # Don't attempt to source a virtualenv when you're running inside the container.
    # The correct environment is the global environment in that case.
    if ! type -f /.dockerenv >/dev/null 2>&1; then
        echo "Attempting to activate a virtualenv if present..."
        # Active virtual environment (check several possibles places), it helps if the script
        # is executed from PyCharm (e.g. configuring it as an External Tool) or
        # with GitHub Desktop

        # shellcheck disable=SC1090
        test -f venv/bin/activate && source "$_"

        # shellcheck disable=SC1090
        test -f .venv/bin/activate && source "$_"

        # shellcheck disable=SC1090
        test -f env/bin/activate && source "$_"
    else

    pyright "$@"
fi

As you can see, the reason we're using a script is because our developers tend to use a name for their virtualenv that they personally like the best, so we can't use a hook like: repo: https://github.com/RobertCraigie/pyright-python directly because it forces us to hardcode the venv name. However, this setup works fine locally and should in theory be fine in the container too.

Instead we get this error:

Running inside the container, skipping virtualenv activation.
 * Environment already exists: /root/.cache/pyright-python/nodeenv
Traceback (most recent call last):
  File "/usr/local/bin/pyright", line 8, in <module>
    sys.exit(entrypoint())
  File "/usr/local/lib/python3.8/site-packages/pyright/cli.py", line 34, in entrypoint
    sys.exit(main(sys.argv[1:]))
  File "/usr/local/lib/python3.8/site-packages/pyright/cli.py", line 19, in main
    return run(*args, **kwargs).returncode
  File "/usr/local/lib/python3.8/site-packages/pyright/cli.py", line 25, in run
    pkg_dir = install_pyright(args, quiet=None)
  File "/usr/local/lib/python3.8/site-packages/pyright/_utils.py", line 64, in install_pyright
    node.run(
  File "/usr/local/lib/python3.8/site-packages/pyright/node.py", line 105, in run
    binary = _ensure_available(target)
  File "/usr/local/lib/python3.8/site-packages/pyright/node.py", line 38, in _ensure_available
    return Binary(path=_ensure_node_env(target), strategy=Strategy.NODEENV)
  File "/usr/local/lib/python3.8/site-packages/pyright/node.py", line 65, in _ensure_node_env
    _install_node_env()
  File "/usr/local/lib/python3.8/site-packages/pyright/node.py", line 98, in _install_node_env
    subprocess.run(args, check=True)
  File "/usr/local/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/local/bin/python', '-m', 'nodeenv', '/root/.cache/pyright-python/nodeenv']' returned non-zero exit status 2.

For reference, here's what's installed in the container:

$ pip freeze
aiohttp @ file:///wheels/aiohttp-3.9.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
aiosignal @ file:///wheels/aiosignal-1.3.1-py3-none-any.whl
aniso8601 @ file:///wheels/aniso8601-7.0.0-py2.py3-none-any.whl
annotated-types @ file:///wheels/annotated_types-0.6.0-py3-none-any.whl
anyio @ file:///wheels/anyio-4.2.0-py3-none-any.whl
asgiref @ file:///wheels/asgiref-3.6.0-py3-none-any.whl
astroid @ file:///wheels/astroid-2.11.7-py3-none-any.whl
async-timeout @ file:///wheels/async_timeout-4.0.2-py3-none-any.whl
attrs @ file:///wheels/attrs-22.2.0-py3-none-any.whl
awslambdaric @ file:///wheels/awslambdaric-2.0.7-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
backports.zoneinfo @ file:///wheels/backports.zoneinfo-0.2.1-cp38-cp38-linux_aarch64.whl
boto3 @ file:///wheels/boto3-1.28.85-py3-none-any.whl
botocore @ file:///wheels/botocore-1.31.85-py3-none-any.whl
bytecode @ file:///wheels/bytecode-0.14.0-py3-none-any.whl
cachetools @ file:///wheels/cachetools-5.0.0-py3-none-any.whl
cattrs @ file:///wheels/cattrs-22.2.0-py3-none-any.whl
Cerberus @ file:///wheels/Cerberus-1.3.4-py3-none-any.whl
certifi @ file:///wheels/certifi-2023.7.22-py3-none-any.whl
cffi @ file:///wheels/cffi-1.15.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
cfgv @ file:///wheels/cfgv-3.3.1-py2.py3-none-any.whl
charset-normalizer @ file:///wheels/charset_normalizer-2.1.1-py3-none-any.whl
click @ file:///wheels/click-8.1.7-py3-none-any.whl
codeguru-profiler-agent @ file:///wheels/codeguru_profiler_agent-1.2.4-py3-none-any.whl
coverage @ file:///wheels/coverage-7.0.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
croniter @ file:///wheels/croniter-1.3.5-py2.py3-none-any.whl
cryptography @ file:///wheels/cryptography-42.0.5-cp37-abi3-manylinux_2_28_aarch64.whl
dataclasses-json @ file:///wheels/dataclasses_json-0.6.1-py3-none-any.whl
datadog @ file:///wheels/datadog-0.47.0-py2.py3-none-any.whl
datadog-lambda @ file:///wheels/datadog_lambda-5.87.0-py3-none-any.whl
ddsketch @ file:///wheels/ddsketch-2.0.4-py3-none-any.whl
ddtrace @ file:///wheels/ddtrace-2.7.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
decorator @ file:///wheels/decorator-5.1.1-py3-none-any.whl
defusedxml @ file:///wheels/defusedxml-0.7.1-py2.py3-none-any.whl
Deprecated @ file:///wheels/Deprecated-1.2.13-py2.py3-none-any.whl
dill @ file:///wheels/dill-0.3.6-py3-none-any.whl
distlib @ file:///wheels/distlib-0.3.6-py2.py3-none-any.whl
distro @ file:///wheels/distro-1.9.0-py3-none-any.whl
Django @ file:///wheels/Django-4.2.10-py3-none-any.whl
django-auditlog @ file:///wheels/django_auditlog-2.7.0-py3-none-any.whl
django-cors-headers @ file:///wheels/django_cors_headers-3.14.0-py3-none-any.whl
django-csp @ file:///wheels/django_csp-3.7-py2.py3-none-any.whl
django-database-view @ file:///wheels/django_database_view-0.3.0-py3-none-any.whl
django-extensions @ file:///wheels/django_extensions-3.2.3-py3-none-any.whl
django-filter @ file:///wheels/django_filter-23.2-py3-none-any.whl
django-ipware @ file:///wheels/django_ipware-5.0.2-py2.py3-none-any.whl
django-polymorphic @ file:///wheels/django_polymorphic-3.1.0-py3-none-any.whl
django-postgres-extra @ file:///wheels/django_postgres_extra-2.0.8-py3-none-any.whl
django-test-migrations @ file:///wheels/django_test_migrations-1.2.0-py3-none-any.whl
django-thread @ file:///wheels/django_thread-0.0.1-py3-none-any.whl
django-types @ file:///wheels/django_types-0.19.1-py3-none-any.whl
djangorestframework @ file:///wheels/djangorestframework-3.14.0-py3-none-any.whl
ElasticMock @ file:///wheels/ElasticMock-1.10.0-py3-none-any.whl
elasticsearch @ file:///wheels/elasticsearch-7.13.0-py2.py3-none-any.whl
elasticsearch-dsl @ file:///wheels/elasticsearch_dsl-7.3.0-py2.py3-none-any.whl
emoji @ file:///wheels/emoji-2.8.0-py2.py3-none-any.whl
envier @ file:///wheels/envier-0.4.0-py3-none-any.whl
exceptiongroup @ file:///wheels/exceptiongroup-1.1.0-py3-none-any.whl
execnet @ file:///wheels/execnet-1.9.0-py2.py3-none-any.whl
expiringdict @ file:///wheels/expiringdict-1.1.4-py3-none-any.whl
fakeredis @ file:///wheels/fakeredis-2.19.0-py3-none-any.whl
filelock @ file:///wheels/filelock-3.9.0-py3-none-any.whl
freezegun @ file:///wheels/freezegun-1.4.0-py3-none-any.whl
frozenlist @ file:///wheels/frozenlist-1.3.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
future @ file:///wheels/future-0.18.3-py3-none-any.whl
google-auth @ file:///wheels/google_auth-2.25.2-py2.py3-none-any.whl
google-auth-httplib2 @ file:///wheels/google_auth_httplib2-0.2.0-py2.py3-none-any.whl
google-auth-oauthlib @ file:///wheels/google_auth_oauthlib-1.2.0-py2.py3-none-any.whl
gprof2dot @ file:///wheels/gprof2dot-2022.7.29-py2.py3-none-any.whl
graphene @ file:///wheels/graphene-2.1.9-py2.py3-none-any.whl
graphene-django @ file:///wheels/graphene_django-2.16.0-py2.py3-none-any.whl
graphene-file-upload @ file:///wheels/graphene_file_upload-1.2.2-py3-none-any.whl
graphql-core @ file:///wheels/graphql_core-2.3.2-py2.py3-none-any.whl
graphql-relay @ file:///wheels/graphql_relay-2.0.1-py3-none-any.whl
gunicorn @ file:///wheels/gunicorn-20.0.4-py2.py3-none-any.whl
h11 @ file:///wheels/h11-0.14.0-py3-none-any.whl
httpcore @ file:///wheels/httpcore-1.0.2-py3-none-any.whl
httplib2 @ file:///wheels/httplib2-0.21.0-py3-none-any.whl
httpx @ file:///wheels/httpx-0.26.0-py3-none-any.whl
hupper @ file:///wheels/hupper-1.12.1-py3-none-any.whl
hvac @ file:///wheels/hvac-0.11.2-py2.py3-none-any.whl
identify @ file:///wheels/identify-2.5.13-py2.py3-none-any.whl
idna @ file:///wheels/idna-3.4-py3-none-any.whl
importlib-metadata @ file:///wheels/importlib_metadata-6.8.0-py3-none-any.whl
importlib-resources @ file:///wheels/importlib_resources-6.0.0-py3-none-any.whl
iniconfig @ file:///wheels/iniconfig-2.0.0-py3-none-any.whl
isort @ file:///wheels/isort-5.11.4-py3-none-any.whl
Jinja2 @ file:///wheels/Jinja2-3.1.3-py3-none-any.whl
jira @ file:///wheels/jira-3.4.1-py3-none-any.whl
jmespath @ file:///wheels/jmespath-0.10.0-py2.py3-none-any.whl
jsonschema @ file:///wheels/jsonschema-4.16.0-py3-none-any.whl
launchdarkly-server-sdk @ file:///wheels/launchdarkly_server_sdk-8.1.4-py3-none-any.whl
lazy-object-proxy @ file:///wheels/lazy_object_proxy-1.9.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
limits @ file:///wheels/limits-3.5.0-py3-none-any.whl
luqum @ file:///wheels/luqum-0.11.0-py3-none-any.whl
MarkupSafe @ file:///wheels/MarkupSafe-2.1.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
marshmallow @ file:///wheels/marshmallow-3.19.0-py3-none-any.whl
mccabe @ file:///wheels/mccabe-0.7.0-py2.py3-none-any.whl
mixpanel @ file:///wheels/mixpanel-4.9.0-py2.py3-none-any.whl
mock @ file:///wheels/mock-4.0.3-py3-none-any.whl
moto @ file:///wheels/moto-4.2.13-py2.py3-none-any.whl
multidict @ file:///wheels/multidict-6.0.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
mypy-extensions @ file:///wheels/mypy_extensions-1.0.0-py3-none-any.whl
neo4j @ file:///wheels/neo4j-5.0.1-py3-none-any.whl
nodeenv @ file:///wheels/nodeenv-1.7.0-py2.py3-none-any.whl
numpy @ file:///wheels/numpy-1.24.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
oauthlib @ file:///wheels/oauthlib-3.2.2-py3-none-any.whl
openai @ file:///wheels/openai-1.13.3-py3-none-any.whl
opentelemetry-api @ file:///wheels/opentelemetry_api-1.20.0-py3-none-any.whl
packaging @ file:///wheels/packaging-23.0-py3-none-any.whl
pandas @ file:///wheels/pandas-2.0.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
parameterized @ file:///wheels/parameterized-0.7.4-py2.py3-none-any.whl
pkgutil_resolve_name @ file:///wheels/pkgutil_resolve_name-1.3.10-py3-none-any.whl
platformdirs @ file:///wheels/platformdirs-2.6.2-py3-none-any.whl
pluggy @ file:///wheels/pluggy-1.0.0-py2.py3-none-any.whl
ply @ file:///wheels/ply-3.11-py2.py3-none-any.whl
pre-commit @ file:///wheels/pre_commit-2.20.0-py2.py3-none-any.whl
promise @ file:///wheels/promise-2.3-py3-none-any.whl
protobuf @ file:///wheels/protobuf-4.21.12-cp37-abi3-manylinux2014_aarch64.whl
psycopg2-binary==2.9.9
py @ file:///wheels/py-1.11.0-py2.py3-none-any.whl
pyasn1 @ file:///wheels/pyasn1-0.4.8-py2.py3-none-any.whl
pyasn1-modules @ file:///wheels/pyasn1_modules-0.2.8-py2.py3-none-any.whl
pycarlo @ file:///wheels/pycarlo-0.8.14-py3-none-any.whl
pycparser @ file:///wheels/pycparser-2.21-py2.py3-none-any.whl
pydantic @ file:///wheels/pydantic-2.6.3-py3-none-any.whl
pydantic_core @ file:///wheels/pydantic_core-2.16.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
PyGithub @ file:///wheels/PyGithub-2.1.1-py3-none-any.whl
PyJWT @ file:///wheels/PyJWT-2.6.0-py3-none-any.whl
pylint @ file:///wheels/pylint-2.13.9-py3-none-any.whl
PyNaCl @ file:///wheels/PyNaCl-1.5.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl
pynamodb @ file:///wheels/pynamodb-5.4.0-py3-none-any.whl
pyparsing @ file:///wheels/pyparsing-3.0.9-py3-none-any.whl
pyRFC3339 @ file:///wheels/pyRFC3339-1.1-py2.py3-none-any.whl
pyright @ file:///wheels/pyright-1.1.356-py3-none-any.whl
pyrsistent @ file:///wheels/pyrsistent-0.19.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
pytest @ file:///wheels/pytest-7.1.2-py3-none-any.whl
pytest-cov @ file:///wheels/pytest_cov-3.0.0-py3-none-any.whl
pytest-datadir @ file:///wheels/pytest_datadir-1.4.1-py3-none-any.whl
pytest-django @ file:///wheels/pytest_django-4.5.2-py3-none-any.whl
pytest-env @ file:///wheels/pytest_env-0.6.2-py3-none-any.whl
pytest-freezegun @ file:///wheels/pytest_freezegun-0.4.2-py2.py3-none-any.whl
pytest-profiling @ file:///wheels/pytest_profiling-1.7.0-py2.py3-none-any.whl
pytest-regressions @ file:///wheels/pytest_regressions-2.4.2-py3-none-any.whl
pytest-unordered @ file:///wheels/pytest_unordered-0.5.2-py3-none-any.whl
pytest-xdist @ file:///wheels/pytest_xdist-3.1.0-py3-none-any.whl
python-box @ file:///wheels/python_box-7.0.1-py3-none-any.whl
python-dateutil @ file:///wheels/python_dateutil-2.8.2-py2.py3-none-any.whl
python-snappy @ file:///wheels/python_snappy-0.6.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
pytz @ file:///wheels/pytz-2022.7-py2.py3-none-any.whl
PyYAML @ file:///wheels/PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
redis @ file:///wheels/redis-4.5.4-py3-none-any.whl
regex @ file:///wheels/regex-2023.10.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
requests @ file:///wheels/requests-2.31.0-py3-none-any.whl
requests-aws4auth @ file:///wheels/requests_aws4auth-1.2.3-py2.py3-none-any.whl
requests-oauthlib @ file:///wheels/requests_oauthlib-1.3.1-py2.py3-none-any.whl
requests-toolbelt @ file:///wheels/requests_toolbelt-0.10.1-py2.py3-none-any.whl
responses @ file:///wheels/responses-0.22.0-py3-none-any.whl
retry @ file:///wheels/retry-0.9.2-py2.py3-none-any.whl
rsa @ file:///wheels/rsa-4.9-py3-none-any.whl
ruff @ file:///wheels/ruff-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Rx @ file:///wheels/Rx-1.6.3-py2.py3-none-any.whl
s3transfer @ file:///wheels/s3transfer-0.7.0-py3-none-any.whl
semver @ file:///wheels/semver-2.13.0-py2.py3-none-any.whl
sentry-sdk @ file:///wheels/sentry_sdk-1.14.0-py2.py3-none-any.whl
setproctitle @ file:///wheels/setproctitle-1.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
sgqlc @ file:///wheels/sgqlc-16.0-py3-none-any.whl
simplejson @ file:///wheels/simplejson-3.17.2-cp38-cp38-manylinux2014_aarch64.whl
singledispatch @ file:///wheels/singledispatch-4.0.0-py2.py3-none-any.whl
six @ file:///wheels/six-1.16.0-py2.py3-none-any.whl
slack-bolt @ file:///wheels/slack_bolt-1.9.2-py2.py3-none-any.whl
slack-sdk @ file:///wheels/slack_sdk-3.19.5-py2.py3-none-any.whl
slackclient @ file:///wheels/slackclient-2.9.4-py2.py3-none-any.whl
sniffio @ file:///wheels/sniffio-1.3.0-py3-none-any.whl
sortedcontainers @ file:///wheels/sortedcontainers-2.4.0-py2.py3-none-any.whl
sqlglot @ file:///wheels/sqlglot-20.11.0-py3-none-any.whl
sqlparse @ file:///wheels/sqlparse-0.4.4-py3-none-any.whl
text-unidecode @ file:///wheels/text_unidecode-1.3-py2.py3-none-any.whl
tiktoken @ file:///wheels/tiktoken-0.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
toml @ file:///wheels/toml-0.10.2-py2.py3-none-any.whl
tomli @ file:///wheels/tomli-2.0.1-py3-none-any.whl
tqdm @ file:///wheels/tqdm-4.65.0-py3-none-any.whl
types-psycopg2 @ file:///wheels/types_psycopg2-2.9.21.14-py3-none-any.whl
types-python-dateutil @ file:///wheels/types_python_dateutil-2.8.19.13-py3-none-any.whl
types-toml @ file:///wheels/types_toml-0.10.8.1-py3-none-any.whl
typing-inspect @ file:///wheels/typing_inspect-0.8.0-py3-none-any.whl
typing_extensions @ file:///wheels/typing_extensions-4.9.0-py3-none-any.whl
tzdata @ file:///wheels/tzdata-2023.3-py2.py3-none-any.whl
uritemplate @ file:///wheels/uritemplate-4.1.1-py2.py3-none-any.whl
urllib3 @ file:///wheels/urllib3-1.26.18-py2.py3-none-any.whl
virtualenv @ file:///wheels/virtualenv-20.17.1-py3-none-any.whl
watchdog @ file:///wheels/watchdog-2.2.1-py3-none-manylinux2014_aarch64.whl
watchtower @ file:///wheels/watchtower-0.7.3-py2.py3-none-any.whl
webexteamssdk @ file:///wheels/webexteamssdk-1.6.1-py3-none-any.whl
Werkzeug @ file:///wheels/werkzeug-3.0.1-py3-none-any.whl
whitenoise @ file:///wheels/whitenoise-6.4.0-py3-none-any.whl
wrapt @ file:///wheels/wrapt-1.15.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
xmltodict @ file:///wheels/xmltodict-0.13.0-py2.py3-none-any.whl
yarl @ file:///wheels/yarl-1.8.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
zipp @ file:///wheels/zipp-3.16.2-py3-none-any.whl