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 env command #278

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .commands import CheckCommand
from .commands import ConfigCommand
from .commands import DevelopCommand
from .commands import EnvCommand
from .commands import InitCommand
from .commands import InstallCommand
from .commands import LockCommand
Expand Down Expand Up @@ -111,6 +112,7 @@ def get_default_commands(self): # type: () -> list
CheckCommand(),
ConfigCommand(),
DevelopCommand(),
EnvCommand(),
InitCommand(),
InstallCommand(),
LockCommand(),
Expand Down
1 change: 1 addition & 0 deletions poetry/console/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .check import CheckCommand
from .config import ConfigCommand
from .develop import DevelopCommand
from .env import EnvCommand
from .init import InitCommand
from .install import InstallCommand
from .lock import LockCommand
Expand Down
40 changes: 40 additions & 0 deletions poetry/console/commands/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from .venv_command import VenvCommand
from shutil import rmtree


class EnvCommand(VenvCommand):
"""
Shows information about the virtual environment.

env
{ --p|path : Show the path to virtual environment. }
{ --python : Show the path to the python executable. }
{ --pip : Show the path to the pip executable. }
{ --rm : Remove the virtual environment. }
"""

help = """The env command displays information about the virtual environment.
If it doesn't exist when the command is ran, it will be created."""

def handle(self):
path = self.venv.venv

if self.option("path"):
self.info(path)

elif self.option("python"):
self.info(self.venv.python)

elif self.option("pip"):
self.info(self.venv.pip)

elif self.option("rm"):
self.line("Removing virtual environment at <info>{}</>".format(path))
rmtree(path, ignore_errors=True)

else:
version = ".".join(str(s) for s in self.venv.version_info[:3])
impl = self.venv.python_implementation
self.line("<info>Virtualenv path</>: <comment>{}</>".format(path))
self.line("<info>Python version</>: <comment>{}</>".format(version))
self.line("<info>Implementation</>: <comment>{}</>".format(impl))