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

Add Vox environment manager to xonsh #675

Merged
merged 19 commits into from
Feb 13, 2016
Merged

Add Vox environment manager to xonsh #675

merged 19 commits into from
Feb 13, 2016

Conversation

moigagoo
Copy link
Contributor

  • Registered vox as a default alias.
  • Added the {env_name} prompt variable.
  • Added environment name indication to the default prompt.


print('Creating environment...')

vbuiltins.__xonsh_env__.create(env_path, with_pip=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vbuiltins?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the correction! It's supposed to be venv. When I autoreplaced ENV with builtins.xonsh_env, I totally overlooked this bit :-(

Fixed in moigagoo@b92969e

@scopatz scopatz added this to the v0.3 milestone Feb 12, 2016
@scopatz
Copy link
Member

scopatz commented Feb 12, 2016

Looks like there are conflicts now, probably from the new parser being merged in to master. If you could resolve these that would be awesome!

@scopatz
Copy link
Member

scopatz commented Feb 12, 2016

Also, a fair amount of this seems to be reimplementing what argparse does. We should probably just move to argparse. There are a lot of examples in xonsh that use it already.

@moigagoo
Copy link
Contributor Author

Conflict resolved, ready to merge.

I didn't quite understand your last comment. Do you mean that I reimplemented argparse functionality in Vox? Or are you talking about the new parser?

I can't see how Vox can be rewritten to utilize argparse since xonsh handles argument parsing already. If it were a standalone app, there would be a way to do it, but I'd still use a more high-level library.

def new(name):
"""Create a virtual environment in $VIRTUALENV_HOME with python3's ``venv``.

:param name: virtual environment name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use numpydoc style docstrings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in moigagoo@60daf5e

@scopatz
Copy link
Member

scopatz commented Feb 13, 2016

Thanks for resolving the conflicts, @moigagoo! And thanks for withstanding my many comments. In addition to those, it would be great if you could add in some autodoc hooks in the docs/ dir, since vox.py is a new file. Also, it'd be great if you added an entry to the CHANGELOG. People will want to know about this. :)

I didn't quite understand your last comment. Do you mean that I reimplemented argparse functionality in Vox?

Yes, this.

I can't see how Vox can be rewritten to utilize argparse since xonsh handles argument parsing already. If it were a standalone app, there would be a way to do it,

You could stick an ArgumentParser instance in Vox.__call__(). Argument parsers let you pass in an arglist manually. There are many examples of xonsh aliases that do this:

  1. https://github.com/scopatz/xonsh/blob/master/xonsh/aliases.py#L76
  2. https://github.com/scopatz/xonsh/blob/master/xonsh/aliases.py#L158
  3. https://github.com/scopatz/xonsh/blob/master/xonsh/xonfig.py#L283
  4. https://github.com/scopatz/xonsh/blob/master/xonsh/replay.py#L119
  5. https://github.com/scopatz/xonsh/blob/master/xonsh/history.py#L447

but I'd still use a more high-level library.

Tools like cliar are great. However, we are trying to maintain maximum protablility by relying only on the Python standard library and PLY as required runtime dependencies. (And I have thought about moving a copy of PLY into xonsh so that it could be basically standalone.) I consider vox of core value, so it would be nice if it didn't rely on optional dependencies :)

Also, note, that not using argeparse is not blocking this. It was just a suggestion. We have other many other aliases that don't use argparse, so it is a reasonable choice not to.

@@ -384,6 +387,8 @@ def xonshconfig(env):
default='xonsh.environ.DEFAULT_TITLE'),
'VI_MODE': VarDocs(
"Flag to enable 'vi_mode' in the 'prompt_toolkit' shell."),
'VIRTUAL_ENV': VarDocs(
"Path to the currently active Python environment."),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The should have configurable=False, I would think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

home_path = builtins.__xonsh_env__['USERPROFILE']

elif os.name == 'posix':
home_path = os.path.expanduser('~')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not just this line, but this whole conditional can be replaced with the expanduser(). Rather than having the if-elif-else blocks, you can just have the one line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if that wasn't clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel so stupid right now :-)

moigagoo@17cb4cb

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure this was my bad explanation in the early morning :)

On Sat, Feb 13, 2016 at 1:58 PM Konstantin Molchanov <
notifications@github.com> wrote:

In xonsh/vox.py
#675 (comment):

+import builtins
+
+
+class Vox:

  • """Vox is a virtual environment manager for xonsh."""
  • def init(self):
  •    """Ensure that $VIRTUALENV_HOME is defined and declare the available vox commands"""
    
  •    if not builtins.**xonsh_env**.get('VIRTUALENV_HOME'):
    
  •        if os.name == 'nt':
    
  •            home_path = builtins.**xonsh_env**['USERPROFILE']
    
  •        elif os.name
    

== 'posix':

  •            home_path = os.path.expanduser('~')
    

I feel so stupid right now :-)

moigagoo/xonsh@17cb4cb
moigagoo@17cb4cb


Reply to this email directly or view it on GitHub
https://github.com/scopatz/xonsh/pull/675/files#r52831995.

Asst. Prof. Anthony Scopatz
Nuclear Engineering Program
Mechanical Engineering Dept.
University of South Carolina
Affiliated Professor of the University of Haifa
scopatz@cec.sc.edu
Office: (803) 777-7629
Cell: (512) 827-8239
Check my calendar
https://www.google.com/calendar/embed?src=scopatz%40gmail.com

if os.name == 'nt':
bin_dir = 'Scripts'

elif os.name == 'posix':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably import ON_WINDOWS and ON_POSIX from xonsh.tools and use them here, for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scopatz
Copy link
Member

scopatz commented Feb 13, 2016

OK @moigagoo, let us know when you think that this is ready to go in!

@moigagoo
Copy link
Contributor Author

I fixed all the issues you had reported except for the argparse one. Fingers crossed :-)

First, thanks a lot for investing your time in reviewing and commenting on my commits.

Second, I'd like to comment a bit on the argparse issue. I think it's a bit of an overkill in this case. Argparse has such an overcomplicated API, which, I believe, doesn't really pay off in this task. However, if you think it's the right thing to do, I'm ready to do it—xonsh is your project after all :-)

@moigagoo
Copy link
Contributor Author

🎆

@scopatz
Copy link
Member

scopatz commented Feb 13, 2016

First, thanks a lot for investing your time in reviewing and commenting on my commits.

Thank you for investing your time and effort in making xonsh better! Hopefully, that will continue :)

Second, I'd like to comment a bit on the argparse issue. I think it's a bit of an overkill in this case. Argparse has such an overcomplicated API, which, I believe, doesn't really pay off in this task. However, if you think it's the right thing to do, I'm ready to do it—xonsh is your project after all :-)

This is fine. As I said, I don't think argparse should block this since we have many other core utilities in xonsh that don't use it. Using argpare seems to be about 50%, so I don't think it is a big deal.

If you think it is ready, let me know and I'll merge it in.

@moigagoo
Copy link
Contributor Author

If you think it is ready, let me know and I'll merge it in.

Sure, go ahead.

scopatz added a commit that referenced this pull request Feb 13, 2016
Add Vox environment manager to xonsh
@scopatz scopatz merged commit f82d304 into xonsh:master Feb 13, 2016
@scopatz
Copy link
Member

scopatz commented Feb 13, 2016

Thanks a million, @moigagoo!

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

Successfully merging this pull request may close these issues.

3 participants