Skip to content

Pipenv + PyCharm issues #1412

Closed
Closed

Description

@ModischFabrications

I have come across the same problem as @bshibs in #950 .

PyCharm's "push" seems to be outside of the pipenv shell, leading to a whole lot of warnings because execution is outside of the virtual environment. Running git push manually in the integrated terminal is fine, since it activates the pipenv automatically, but this is not really a feasible solution.

I experimented around, but I was simply unable to add some kind of "pipenv shell" setup to my configuration.

Is there something I missed? Seems like either PyCharm needs to respect the pipenv shell or pre-commit needs to have a way to find it's way back into the virtual environment by itself. My initial idea would be be to offer some kind of setup to initialise pipenv shell, but I'm open for some other ideas.

Activity

  1. changed the title [-]Pipenv issues[/-] [+]Pipenv + PyCharm issues[/+] on Apr 24, 2020
  2. asottile commented on Apr 24, 2020

    @asottile
    Member

    do you have a step by step reproduction, it's unclear what bshibs was saying there and I don't know what your issue is and whether it is the same one or ?

  3. ModischFabrications commented on Apr 24, 2020

    @ModischFabrications
    ContributorAuthor

    This is a similar case: pypa/pipenv#2850

    The short version:

    1. create project, using pipenv for dependencies
    2. add pre-commit config calling a python script that depends on the dependencies that pipenv manages
    3. git commit via cli: pipenv shell handles python reference, everything is working
    4. git commit va pycharm push: pipenv did not init shell, the call is done using the system wide python -> missing dependencies
  4. asottile commented on Apr 24, 2020

    @asottile
    Member

    show your configuration?

  5. asottile commented on Apr 24, 2020

    @asottile
    Member

    aka: give me something to copy and paste and run -- "create project, using pipenv for dependencies" doesn't help me because I stay as far away from pipenv as possible

  6. ModischFabrications commented on Apr 24, 2020

    @ModischFabrications
    ContributorAuthor

    Everything related to my problem is contained in https://github.com/ModischFabrications/CutSolver, I have not created a minimal working example yet.

    I know it's a pain to reproduce it, sorry :/

    The following assumes PyCharm and no pytest in your global python installation:

    Check it out and use pipenv install --dev to install every dependency.
    Change and commit any python file (except main.py) to enable the trigger for the pytest hook.

    Push using pycharm's push button:
    <wrong_global_python_install>\python.EXE: No module named pytest

    Open console ((CutSolver) should be prefixed to the path, if not use pipenv shell)
    Push using git push works with run tests..................Passed.

    Don't be alarmed if the created tag is not actually pushed, it's not working right now due to #1411.

  7. ModischFabrications commented on Apr 24, 2020

    @ModischFabrications
    ContributorAuthor

    These are pycharm issues and would fix the root cause:

    1. https://youtrack.jetbrains.com/issue/IDEA-235585
    2. https://youtrack.jetbrains.com/issue/IDEA-227754
    3. https://youtrack.jetbrains.com/issue/PY-12988

    Being able to call pipenv shell in the project directory before executing anything else should have the same result and gives more flexibility.

  8. asottile commented on Apr 24, 2020

    @asottile
    Member

    oh ok I see -- next time you make a bug report please include the necessary information such that we can understand your problem. This usually involves: some way to reproduce the problem, what you're seeing exactly (output, screenshot, command you ran, etc.), and what you expect to see. without that information it is very difficult to guess at what your problem is.

    • so first things first, repo: local is the escape hatch from the "normal way" to use pre-commit tools
    • secondly, language: system is "I don't want pre-commit to manage anything, I promise the tools will be installed globally on my system"
    • pre-commit works best when it manages the tools that it is running (via language: python / language: node / etc.)

    it seems that you're expecting your virtualenv to be globally activated, which it isn't

    if you'd like to continue in unsupported territory, I'd suggest you instead use entry: pipenv run ... or whatever pipenv's way of running things is

    if you'd like to continue in supported territory, I'd suggest you stop using language: system and use language: python instead (perhaps with additional_dependencies as needed) -- this will cause pre-commit to manage an environment to run the tools in

  9. asottile commented on Apr 24, 2020

    @asottile
    Member

    since this is not a pre-commit issue (language: system is outside the supported domain) I'm closing this -- hopefully those pointers above can help you come to a solution which works for you

  10. asottile commented on Apr 24, 2020

    @asottile
    Member
  11. ModischFabrications commented on Apr 24, 2020

    @ModischFabrications
    ContributorAuthor

    Thanks for your help, I get that solving it here might be out of the scope of this tool.

    I am currently trying out both ways. The supported way would need every single dependency listed as [additional dependency] as pytest is calling into the program.

    The unsupported way (prefixing every entry with pipenv run ...) works, I was hoping to be able to extract that, either by aliasing the python command with this prefix or having an initial setup call to activate pipenv shell to do that for me.

    It's still not perfect, but it's a workaround until the core issue is resolved. Thank's again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions