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

[Documentation, Windows] Pipenv + Cmder Documentation #2150

Closed
gtalarico opened this issue May 7, 2018 · 10 comments
Closed

[Documentation, Windows] Pipenv + Cmder Documentation #2150

gtalarico opened this issue May 7, 2018 · 10 comments
Milestone

Comments

@gtalarico
Copy link
Contributor

There are 2 issues that make Pipenv difficult to use on Windows + Cmder (#2 affects win+cmd.exe as well). I am also assuming these are also applicable for ConEmu.

Cmder/ConEmu is used by a many Windows users so it would be great to improve
support/documentation for it.
(PS: I also use it on Mac, but my transition there was much smoother with no noticeable issues)

Below are the two main issues I encountered, and the solutions I found.
Could we add this to either the Wiki or the Docs?

1 - Pipenv Uses cmder by default when entering into a new shell

We need to pipenv to continue using cmder when entering into a shell, otherwise it will default to cmd.exe

Solution

Set PIPENV_SHELL to cmder's init file
Edit your environment Variables and add:
PIPENV_SHELL=C:\path\to\cmder\vendor\init.bat

Note:
If path to your init.bat contains space it will not work, so you will need to use a copy of cmder that is not in one of those files (issue #2115 )

2 - Pipenv does not show the active env's in the prompt

This works fine out of the box with virtualenv + virtualenvwrapper.
For this feature to work on windows, the PROMPT variable which is normally set to $P$G need to be amended to (envname) $P$G
More details on #2116

Solution (Workaround; needs a PR for proper fix)

Make sure you have a .env file for your project, and in that file add
PROMPT=(envnameYouWant) $P$G

This will force pipenv to overwrite the %PROMPT% variable when a pipenv shell is started

@uranusjr
Copy link
Member

uranusjr commented May 7, 2018

I use Pipenv with Cmder a lot, and don’t seem to have your first issue. This could be a bug.

@gtalarico
Copy link
Contributor Author

Now that you mentioned, it will probably be fixed
When issue #2115 is fixed.
Is your cmder stored on a folder path that contains spaces?

@uranusjr
Copy link
Member

uranusjr commented May 7, 2018

No, mine is in C:\tools\cmder.

@uranusjr
Copy link
Member

uranusjr commented May 7, 2018

BTW I do this to prepend the virtualenv name to prompt during Clink startup. This is registered as a Clink prompt filter during startup. This might be of interest of some people.

local function find_virtualenv_prompt()
    local virtual_env = clink.get_env('VIRTUAL_ENV')
    if virtual_env == nil then
        return nil
    end

    local activate_bat = io.open(virtual_env..'\\Scripts\\activate.bat', 'r')
    if activate_bat == nil then
        return nil
    end
    local content = activate_bat:read('*a')
    activate_bat:close()

    return content:match('set "PROMPT=%((.+)%) %%PROMPT%%"')
end

local function set_prompt_filter()
    local env = find_virtualenv_prompt()
    clink.prompt.value = "format the prompt here..."
end

@gtalarico
Copy link
Contributor Author

Here is what I was describing.
It was def. caused by the space in path to cmder.
As I mentioned, #2115 hopefully fixes this.
pipenv-shell

As for issue #2, did you modify your clink.lua file?

@uranusjr
Copy link
Member

uranusjr commented May 8, 2018

Yes the space problem is a bug. There haven’t been a fix yet (the one I mentioned in #2115 does not work).

For the second issue, yes I modified my clink.lua. This is probably not the best solution, but the most practical to me because BAT is way too limiting for this task. I wish Cmder would support loading a user-space Lua file like user-profile.bat. OMG wait it totally does support Lua init files I’m migrating everything now…

@techalchemy techalchemy added this to the 11.11.0 milestone May 9, 2018
@techalchemy
Copy link
Member

@gtalarico feel free to PR documentation updates or wiki updates at your discretion for this, I am not sure where you would prefer to direct people as you encounter more of this but I'm happy to expedite reviews (and you can find me on slack/irc if you have questions)

@gtalarico
Copy link
Contributor Author

Thanks @techalchemy !

I am going to be optimistic here... I am hoping I can help fix both of those issues instead of documenting my workarounds :)

I have spent some time testing solutions and I have a fix for both issues listed above.
I feel good about #2167, since that's similar to how the issue is handled by virtualenvwrapper.
#2168 feels patchy, but it does fix the error.

#2167
#2168

@techalchemy
Copy link
Member

Both of those seem appropriate and will just need to get worked into whatever the rewrite looks like too. No big deal there. And I always try to make sure we open relevant PRs upstream so the dependencies themselves reap the benefits. Granted I pew still hasn’t accepted my PR to remove psutil so some changes may not apply.

@uranusjr
Copy link
Member

uranusjr commented Jun 6, 2018

This is largely resolved after PROMPT is now modified for subshells on Windows. Do raise additional contributions on documentation and/or better prompt modification if you can provide any!

@uranusjr uranusjr closed this as completed Jun 6, 2018
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

3 participants