From 1dc35a2d1bedadebcc55c5871278fe8cf01ef6a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Baasch=20de=20Souza?= Date: Fri, 29 Jun 2018 05:28:07 -0300 Subject: [PATCH 1/3] Add env command --- poetry/console/application.py | 2 ++ poetry/console/commands/__init__.py | 1 + poetry/console/commands/env.py | 40 +++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 poetry/console/commands/env.py diff --git a/poetry/console/application.py b/poetry/console/application.py index 1973e4b0ef1..9d38c05dcf1 100644 --- a/poetry/console/application.py +++ b/poetry/console/application.py @@ -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 @@ -111,6 +112,7 @@ def get_default_commands(self): # type: () -> list CheckCommand(), ConfigCommand(), DevelopCommand(), + EnvCommand(), InitCommand(), InstallCommand(), LockCommand(), diff --git a/poetry/console/commands/__init__.py b/poetry/console/commands/__init__.py index 74976e1737e..aead01eede2 100644 --- a/poetry/console/commands/__init__.py +++ b/poetry/console/commands/__init__.py @@ -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 diff --git a/poetry/console/commands/env.py b/poetry/console/commands/env.py new file mode 100644 index 00000000000..6d1ebfd719d --- /dev/null +++ b/poetry/console/commands/env.py @@ -0,0 +1,40 @@ +from .venv_command import VenvCommand +from shutil import rmtree + + +class EnvCommand(VenvCommand): + """ + Shows information about the virtual environment. + If it doesn't exist when the command is ran, it will be created. + + 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. } + { --r|remove : Remove the virtual environment. } + """ + + help = """The env command displays information about the virtual environment.""" + + 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("remove"): + self.line("Removing virtual environment at {}".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("Virtualenv path: {}".format(path)) + self.line("Python version: {}".format(version)) + self.line("Implementation: {}".format(impl)) From a1df81d51d8b776e7541eb87b12a7f3fb47aec4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Baasch=20de=20Souza?= Date: Thu, 5 Jul 2018 00:30:30 -0300 Subject: [PATCH 2/3] Fix command name and help --- poetry/console/commands/env.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poetry/console/commands/env.py b/poetry/console/commands/env.py index 6d1ebfd719d..fa3e479f3f2 100644 --- a/poetry/console/commands/env.py +++ b/poetry/console/commands/env.py @@ -5,7 +5,6 @@ class EnvCommand(VenvCommand): """ Shows information about the virtual environment. - If it doesn't exist when the command is ran, it will be created. env { --p|path : Show the path to virtual environment. } @@ -14,7 +13,8 @@ class EnvCommand(VenvCommand): { --r|remove : Remove the virtual environment. } """ - help = """The env command displays information about 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 From 16b048b144090f46fdcbc63dad9f5b7227ef589d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Baasch=20de=20Souza?= Date: Thu, 5 Jul 2018 00:30:50 -0300 Subject: [PATCH 3/3] Change env -r/--remove to env --rm --- poetry/console/commands/env.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poetry/console/commands/env.py b/poetry/console/commands/env.py index fa3e479f3f2..ec92ef2b24e 100644 --- a/poetry/console/commands/env.py +++ b/poetry/console/commands/env.py @@ -10,7 +10,7 @@ class EnvCommand(VenvCommand): { --p|path : Show the path to virtual environment. } { --python : Show the path to the python executable. } { --pip : Show the path to the pip executable. } - { --r|remove : Remove the virtual environment. } + { --rm : Remove the virtual environment. } """ help = """The env command displays information about the virtual environment. @@ -28,7 +28,7 @@ def handle(self): elif self.option("pip"): self.info(self.venv.pip) - elif self.option("remove"): + elif self.option("rm"): self.line("Removing virtual environment at {}".format(path)) rmtree(path, ignore_errors=True)