diff --git a/docs/docs/index.md b/docs/docs/index.md index 64bb512f6cb..6f12a17d71d 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -59,10 +59,12 @@ python get-poetry.py --uninstall POETRY_UNINSTALL=1 python get-poetry.py ``` -By default, Poetry is installed into the user's platform-specific home directory. If you wish to change this, you may define the `POETRY_HOME` environment variable: +By default, Poetry is installed into the user's platform-specific home directory. If you wish to change this, you may define the `POETRY_HOME` environment variable. In Linux, this variable can also be used with `poetry` command to substitute `XDG_CACHE_HOME`, `XDG_CONFIG_HOME` and `XDG_DATA_HOME` variables. ```bash POETRY_HOME=/etc/poetry python get-poetry.py +POETRY_HOME=/tmp/poetry poetry config --list +POETRY_HOME=/tmp/poetry poetry env info ``` If you want to install prerelease versions, you can do so by passing `--preview` to `get-poetry.py` diff --git a/docs/docs/pyproject.md b/docs/docs/pyproject.md index bdcc6e0bc49..58ff75a7238 100644 --- a/docs/docs/pyproject.md +++ b/docs/docs/pyproject.md @@ -253,10 +253,10 @@ poetry install --extras "mysql pgsql" poetry install -E mysql -E pgsql ``` -When installing or specifying Poetry-built packages, the extras defined in this section can be activated +When installing or specifying Poetry-built packages, the extras defined in this section can be activated as described in [PEP 508](https://www.python.org/dev/peps/pep-0508/#extras). -For example, when installing the package using `pip`, the dependencies required by +For example, when installing the package using `pip`, the dependencies required by the `databases` extra can be installed as shown below. ```bash diff --git a/get-poetry.py b/get-poetry.py index 73b818c7a5c..c2aad2205e4 100644 --- a/get-poetry.py +++ b/get-poetry.py @@ -476,7 +476,7 @@ def _compare_versions(x, y): return version, current_version def customize_install(self): - if not self._accept_all: + if not self._accept_all and self._modify_path: print("Before we start, please answer the following questions.") print("You may simply press the Enter key to leave unchanged.") diff --git a/poetry/utils/appdirs.py b/poetry/utils/appdirs.py index f5592f6b0da..dd52b3581de 100644 --- a/poetry/utils/appdirs.py +++ b/poetry/utils/appdirs.py @@ -37,7 +37,9 @@ def user_cache_dir(appname: str) -> str: Typical user cache directories are: macOS: ~/Library/Caches/ - Unix: ~/.cache/ (XDG default) + Unix: ${POETRY_HOME}/.cache/ or + ${XDG_CACHE_HOME}/ or + ~/.cache/ Windows: C:\Users\\AppData\Local\\Cache On Windows the only suggestion in the MSDN docs is that local settings go @@ -64,7 +66,11 @@ def user_cache_dir(appname: str) -> str: path = os.path.join(path, appname) else: # Get the base path - path = os.getenv("XDG_CACHE_HOME", expanduser("~/.cache")) + path = os.getenv("POETRY_HOME") + if path is not None: + path = os.path.join(path, ".cache") + else: + path = os.getenv("XDG_CACHE_HOME", expanduser("~/.cache")) # Add our app name to it path = os.path.join(path, appname) @@ -87,8 +93,9 @@ def user_data_dir(appname: str, roaming: bool = False) -> str: Typical user data directories are: macOS: ~/Library/Application Support/ - Unix: ~/.local/share/ # or in - $XDG_DATA_HOME, if defined + Unix: ${POETRY_HOME}/.local/share/ or + ${XDG_DATA_HOME}/ or + ~/.local/share/ Win XP (not roaming): C:\Documents and Settings\\ ... ...Application Data\ Win XP (roaming): C:\Documents and Settings\\Local ... @@ -105,9 +112,15 @@ def user_data_dir(appname: str, roaming: bool = False) -> str: elif sys.platform == "darwin": path = os.path.join(expanduser("~/Library/Application Support/"), appname) else: - path = os.path.join( - os.getenv("XDG_DATA_HOME", expanduser("~/.local/share")), appname - ) + # Get the base path + path = os.getenv("POETRY_HOME") + if path is not None: + path = os.path.join(path, ".local/share") + else: + path = os.getenv("XDG_DATA_HOME", expanduser("~/.local/share")) + + # Add our app name to it + path = os.path.join(path, appname) return path @@ -126,7 +139,9 @@ def user_config_dir(appname: str, roaming: bool = True) -> str: Typical user data directories are: macOS: same as user_data_dir - Unix: ~/.config/ + Unix: ${POETRY_HOME}/.config/ or + ${XDG_CONFIG_HOME}/ or + ~/.config/ Win *: same as user_data_dir For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME. @@ -137,7 +152,14 @@ def user_config_dir(appname: str, roaming: bool = True) -> str: elif sys.platform == "darwin": path = user_data_dir(appname) else: - path = os.getenv("XDG_CONFIG_HOME", expanduser("~/.config")) + # Get the base path + path = os.getenv("POETRY_HOME") + if path is not None: + path = os.path.join(path, ".config") + else: + path = os.getenv("XDG_CONFIG_HOME", expanduser("~/.config")) + + # Add our app name to it path = os.path.join(path, appname) return path diff --git a/tests/utils/test_appdirs.py b/tests/utils/test_appdirs.py new file mode 100644 index 00000000000..94b653a4eaf --- /dev/null +++ b/tests/utils/test_appdirs.py @@ -0,0 +1,69 @@ +from os import environ +from os import path +from sys import platform + +from poetry.utils.appdirs import WINDOWS +from poetry.utils.appdirs import expanduser +from poetry.utils.appdirs import user_cache_dir +from poetry.utils.appdirs import user_config_dir +from poetry.utils.appdirs import user_data_dir + + +def test_user_cache_dir(): + if WINDOWS or (platform == "darwin"): + return + + environ["POETRY_HOME"] = "/poetry" + environ["XDG_CACHE_HOME"] = "/xdg/.cache" + appname = "pypoetry" + default_user_cache_dir = path.join(expanduser("~/.cache"), appname) + + assert user_cache_dir(appname) == path.join( + environ["POETRY_HOME"], ".cache", appname + ) + + del environ["POETRY_HOME"] + assert user_cache_dir(appname) == path.join(environ["XDG_CACHE_HOME"], appname) + + del environ["XDG_CACHE_HOME"] + assert user_cache_dir(appname) == default_user_cache_dir + + +def test_user_config_dir(): + if WINDOWS or (platform == "darwin"): + return + + environ["POETRY_HOME"] = "/poetry" + environ["XDG_CONFIG_HOME"] = "/xdg/.config" + appname = "pypoetry" + default_user_config_dir = path.join(expanduser("~/.config"), appname) + + assert user_config_dir(appname) == path.join( + environ["POETRY_HOME"], ".config", appname + ) + + del environ["POETRY_HOME"] + assert user_config_dir(appname) == path.join(environ["XDG_CONFIG_HOME"], appname) + + del environ["XDG_CONFIG_HOME"] + assert user_config_dir(appname) == default_user_config_dir + + +def test_user_data_dir(): + if WINDOWS or (platform == "darwin"): + return + + environ["POETRY_HOME"] = "/poetry" + environ["XDG_DATA_HOME"] = "/xdg/.local/share" + appname = "pypoetry" + default_user_data_dir = path.join(expanduser("~/.local/share"), appname) + + assert user_data_dir(appname) == path.join( + environ["POETRY_HOME"], ".local/share", appname + ) + + del environ["POETRY_HOME"] + assert user_data_dir(appname) == path.join(environ["XDG_DATA_HOME"], appname) + + del environ["XDG_DATA_HOME"] + assert user_data_dir(appname) == default_user_data_dir