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

fix(config): use platform standard directories for all PDM directories #1161

Merged
merged 1 commit into from
Jun 27, 2022
Merged
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
4 changes: 2 additions & 2 deletions docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ The following configuration items can be retrieved and modified by [`pdm config`
| `cache_dir` | The root directory of cached files | The default cache location on OS | No | |
| `check_update` | Check if there is any newer version available | True | No | |
| `global_project.fallback` | Use the global project implicitly if no local project is found | `False` | No | |
| `global_project.path` | The path to the global project | `~/.pdm/global-project` | No | |
| `global_project.user_site` | Whether to install to user site | `False` | No | |
| `global_project.path` | The path to the global project | `<default config location on OS>/global-project` | No | |
| `global_project.user_site` | Whether to install to user site | `False` | No | |
| `install.cache` | Enable caching of wheel installations | False | Yes | |
| `install.cache_method` | Specify how to create links to the caches(`symlink` or `pth`) | `symlink` | Yes | |
| `install.parallel` | Whether to perform installation and uninstallation in parallel | `True` | Yes | `PDM_PARALLEL_INSTALL` |
Expand Down
16 changes: 11 additions & 5 deletions docs/docs/usage/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ Any local configurations will be stored in `.pdm.toml` under the project root di
The configuration files are searched in the following order:

1. `<PROJECT_ROOT>/.pdm.toml` - The project configuration
2. `~/.pdm/config.toml` - The home configuration
2. `<CONFIG_ROOT>/config.toml` - The home configuration

If `-g/--global` option is used, the first item will be replaced by `~/.pdm/global-project/.pdm.toml`.
where `<CONFIG_ROOT>` is:

- `$XDG_CONFIG_HOME/pdm` (`~/.config/pdm` in most cases) on Linux as defined by [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
- `~/Library/Preferences/pdm` on MacOS as defined by [Appli File System Basics](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html)
- `%USERPROFILE%\AppData\Local\pdm` on Windows as defined in [Known folders](https://docs.microsoft.com/en-us/windows/win32/shell/known-folders)

If `-g/--global` option is used, the first item will be replaced by `<CONFIG_ROOT>/global-project/.pdm.toml`.

You can find all available configuration items in [Configuration Page](../configuration.md).

Expand Down Expand Up @@ -122,7 +128,7 @@ See all supported options by typing `pdm publish --help`.

### Configure the repository secrets for upload

When using the [`pdm publish`](cli_reference.md#exec-0--publish) command, it reads the repository secrets from the *global* config file(`~/.pdm/config.toml`). The content of the config is as follows:
When using the [`pdm publish`](cli_reference.md#exec-0--publish) command, it reads the repository secrets from the *global* config file(`<CONFIG_ROOT>/config.toml`). The content of the config is as follows:

```toml
[repository.pypi]
Expand Down Expand Up @@ -169,15 +175,15 @@ The caches are located under `$(pdm config cache_dir)/packages`. One can view th
Sometimes users may want to keep track of the dependencies of global Python interpreter as well.
It is easy to do so with PDM, via `-g/--global` option which is supported by most subcommands.

If the option is passed, `~/.pdm/global-project` will be used as the project directory, which is
If the option is passed, `<CONFIG_ROOT>/global-project` will be used as the project directory, which is
almost the same as normal project except that `pyproject.toml` will be created automatically for you
and it doesn't support build features. The idea is taken from Haskell's [stack](https://docs.haskellstack.org).

However, unlike `stack`, by default, PDM won't use global project automatically if a local project is not found.
Users should pass `-g/--global` explicitly to activate it, since it is not very pleasing if packages go to a wrong place.
But PDM also leave the decision to users, just set the config `global_project.fallback` to `true`.

If you want global project to track another project file other than `~/.pdm/global-project`, you can provide the
If you want global project to track another project file other than `<CONFIG_ROOT>/global-project`, you can provide the
project path via `-p/--project <path>` option.

!!! attention "CAUTION"
Expand Down
1 change: 1 addition & 0 deletions news/1161.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure all app/user path related are computed according to platform standards.
9 changes: 5 additions & 4 deletions pdm/cli/completions/pdm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if ((Test-Path Function:\TabExpansion) -and -not (Test-Path Function:\_pdm_compl

$PDM_PYTHON = "%{python_executable}"
$PDM_PIP_INDEX = (& $PDM_PYTHON -m pdm config pypi.url).Trim()
$CONFIG_DIR = "$env:LOCALAPPDATA\pdm"

class Option {
[string[]] $Opts
Expand Down Expand Up @@ -110,14 +111,14 @@ function getSections() {
}

function _fetchPackageListFromPyPI() {
if (-not (Test-Path -Path "~/.pdm")) {
mkdir "~/.pdm"
if (-not (Test-Path -Path $CONFIG_DIR)) {
mkdir $CONFIG_DIR
}
(Invoke-WebRequest $PDM_PIP_INDEX).Links | ForEach-Object { $_.innerText } | Out-File -FilePath "~/.pdm/.pypiPackages"
(Invoke-WebRequest $PDM_PIP_INDEX).Links | ForEach-Object { $_.innerText } | Out-File -FilePath "$CONFIG_DIR\.pypiPackages"
}

function getPyPIPackages() {
# $cacheFile = "~/.pdm/.pypiPackages"
# $cacheFile = "$CONFIG_DIR\.pypiPackages"
# if (-not (Test-Path -Path $cacheFile) -or (Get-Item $cacheFile).LastWriteTime -lt (Get-Date).AddDays(-28)) {
# _fetchPackageListFromPyPI
# }
Expand Down
2 changes: 1 addition & 1 deletion pdm/project/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Config(MutableMapping[str, str]):
),
"global_project.path": ConfigItem(
"The path to the global project",
os.path.expanduser("~/.pdm/global-project"),
platformdirs.user_config_path("pdm") / "global-project",
True,
),
"global_project.user_site": ConfigItem(
Expand Down
3 changes: 2 additions & 1 deletion pdm/project/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import TYPE_CHECKING, Any, Iterable, Type, cast
from urllib.parse import urlparse

import platformdirs
import tomlkit
from findpython import Finder

Expand Down Expand Up @@ -78,7 +79,7 @@ def __init__(
self.core = core

if global_config is None:
global_config = Path.home() / ".pdm/config.toml"
global_config = platformdirs.user_config_path("pdm") / "config.toml"
self.global_config = Config(Path(global_config), is_global=True)
global_project = Path(self.global_config["global_project.path"])

Expand Down