Skip to content

Commit

Permalink
Refactor access to Poetry home location
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Dec 19, 2021
1 parent ad3678e commit 27c8e4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
9 changes: 2 additions & 7 deletions src/poetry/console/commands/plugin/add.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from cleo.helpers import argument
from cleo.helpers import option

Expand Down Expand Up @@ -46,13 +44,12 @@ class PluginAddCommand(InitCommand, PluginCommandMixin):
"""

def handle(self) -> int:
from pathlib import Path

import tomlkit

from poetry.core.semver.helpers import parse_constraint

from poetry.factory import Factory
from poetry.locations import home_dir
from poetry.utils.env import EnvManager
from poetry.utils.helpers import canonicalize_name

Expand All @@ -61,9 +58,7 @@ def handle(self) -> int:
# Plugins should be installed in the system env to be globally available
system_env = EnvManager.get_system_env(naive=True)

env_dir = Path(
os.getenv("POETRY_HOME") if os.getenv("POETRY_HOME") else system_env.path
)
env_dir = home_dir()

existing_plugins = {}
if env_dir.joinpath("plugins.toml").exists():
Expand Down
9 changes: 2 additions & 7 deletions src/poetry/console/commands/plugin/remove.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os

from cleo.helpers import argument
from cleo.helpers import option

from poetry.console.commands.command import Command
from poetry.console.commands.plugin.plugin_command_mixin import PluginCommandMixin
from poetry.locations import home_dir


class PluginRemoveCommand(Command, PluginCommandMixin):
Expand All @@ -26,8 +25,6 @@ class PluginRemoveCommand(Command, PluginCommandMixin):
]

def handle(self) -> int:
from pathlib import Path

import tomlkit

from poetry.utils.env import EnvManager
Expand All @@ -36,9 +33,7 @@ def handle(self) -> int:
plugins = self.argument("plugins")

system_env = EnvManager.get_system_env(naive=True)
env_dir = Path(
os.getenv("POETRY_HOME") if os.getenv("POETRY_HOME") else system_env.path
)
env_dir = home_dir()

existing_plugins = {}
if env_dir.joinpath("plugins.toml").exists():
Expand Down
10 changes: 10 additions & 0 deletions src/poetry/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ def data_dir() -> Path:
return Path(poetry_home).expanduser()

return Path(user_data_dir("pypoetry", roaming=True))


def home_dir() -> Path:
poetry_home = os.getenv("POETRY_HOME")
if poetry_home:
return Path(poetry_home).expanduser()

from poetry.utils.env import EnvManager

return EnvManager.get_system_env(True).path

0 comments on commit 27c8e4c

Please sign in to comment.