Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different Python Paths for Local and Github Actions #203

Open
r0f1 opened this issue Aug 14, 2023 · 5 comments
Open

Different Python Paths for Local and Github Actions #203

r0f1 opened this issue Aug 14, 2023 · 5 comments

Comments

@r0f1
Copy link

r0f1 commented Aug 14, 2023

Hi everybody,

My .pre-commit-config.yaml looks like this:

- repo: https://github.com/RobertCraigie/pyright-python
  rev: v1.1.322
  hooks:
  - id: pyright
    args: ["--pythonpath", ".venv/Scripts/python.exe"]

and this all works fine as long as I execute it locally. As soon as I push it to Github, and Github Actions kicks in,, it does no longer work because pyright cannot find any of the installed packages (=for every single import statement there is a reportMissingImports error thrown). So I thought I change the config file to this:

- repo: https://github.com/RobertCraigie/pyright-python
  rev: v1.1.322
  hooks:
  - id: pyright
     args: ["--pythonpath", ".venv/bin/python"]

This would work on Github, but does no longer work locally.
I was looking through the documentation and could not find a mention of the --pythonpath argument.

How can I specify the pythonpath such that pyright works both locally and on Github?

@jobh
Copy link

jobh commented Sep 5, 2023

I don't know if this helps, or if it's anywhere close to intended usage, but I was struggling with a similar issue (wanting different pythonpaths) and ended up with this beauty:

- repo: https://github.com/RobertCraigie/pyright-python
  rev: v1.1.325
  hooks:
  - id: pyright
    entry: bash -c 'pyright --pythonpath $(python -c "import os,sys; print(os.path.realpath(sys.executable))") "$@"' -

@ryanpeach
Copy link

Dup #214

@921kiyo
Copy link

921kiyo commented Sep 15, 2024

@jobh Thank you for sharing the above entry bash example, that works for me and saved my time!

@copdips
Copy link

copdips commented Sep 23, 2024

pyright --pythonpath

Hi @jobh

Thanks for the tips, and I wondering why use os.path.realpath instead of sys.executable only, from my test, sys.executable reflects the Python in venv path.

$ which python
/home/xiang/git/test/.venv/bin/python

$ python
Python 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys

>>> sys.executable
'/home/xiang/git/test/.venv/bin/python'

>>> os.path.realpath(sys.executable)
'/usr/bin/python3.12'
>>> 

@jobh
Copy link

jobh commented Sep 23, 2024

pyright --pythonpath

Hi @jobh

Thanks for the tips, and I wondering why use os.path.realpath instead of sys.executable only, from my test, sys.executable reflects the Python in venv path.

I don't remember why exactly, it may well be unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants