Better handling for UNIX support (#183)
Co-authored-by: Marcel Telka <marcel@telka.sk>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 815bee1..045ebf4 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -17,7 +17,7 @@
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade
- rev: v3.3.2
+ rev: v3.4.0
hooks:
- id: pyupgrade
args: ["--py37-plus"]
@@ -44,6 +44,11 @@
hooks:
- id: tox-ini-fmt
args: ["-p", "fix"]
+ - repo: https://github.com/tox-dev/pyproject-fmt
+ rev: "0.11.2"
+ hooks:
+ - id: pyproject-fmt
+ additional_dependencies: [tox>=4.5.1]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
@@ -66,14 +71,10 @@
- "@prettier/plugin-xml@2.2"
args: ["--print-width=120", "--prose-wrap=always"]
- repo: https://github.com/igorshubovych/markdownlint-cli
- rev: v0.33.0
+ rev: v0.34.0
hooks:
- id: markdownlint
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- - repo: https://github.com/tox-dev/pyproject-fmt
- rev: "0.10.0"
- hooks:
- - id: pyproject-fmt
diff --git a/pyproject.toml b/pyproject.toml
index c43e7af..684072f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,7 +2,7 @@
build-backend = "hatchling.build"
requires = [
"hatch-vcs>=0.3",
- "hatchling>=1.14",
+ "hatchling>=1.14.1",
]
[project]
@@ -31,13 +31,13 @@
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
- "Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
+ "Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
@@ -51,7 +51,7 @@
optional-dependencies.docs = [
"furo>=2023.3.27",
"proselint>=0.13",
- "sphinx>=6.1.3",
+ "sphinx>=6.2.1",
"sphinx-autodoc-typehints!=1.23.4,>=1.23",
]
optional-dependencies.test = [
diff --git a/src/platformdirs/unix.py b/src/platformdirs/unix.py
index 3813590..04e8655 100644
--- a/src/platformdirs/unix.py
+++ b/src/platformdirs/unix.py
@@ -7,12 +7,13 @@
from .api import PlatformDirsABC
-if sys.platform.startswith("linux"): # pragma: no branch # no op check, only to please the type checker
- from os import getuid
-else:
+if sys.platform == "win32":
def getuid() -> int:
- raise RuntimeError("should only be used on Linux")
+ raise RuntimeError("should only be used on Unix")
+
+else:
+ from os import getuid
class Unix(PlatformDirsABC):
diff --git a/tests/test_comp_with_appdirs.py b/tests/test_comp_with_appdirs.py
index 4f6b69e..89775b4 100644
--- a/tests/test_comp_with_appdirs.py
+++ b/tests/test_comp_with_appdirs.py
@@ -60,12 +60,12 @@
}
if func in msg: # pragma: no cover
pytest.skip(f"`appdirs.{func}` {msg[func]} on macOS") # pragma: no cover
- if sys.platform == "linux":
+ elif sys.platform != "win32":
msg = { # pragma: no cover
"user_log_dir": "Uses XDG_STATE_DIR instead of appdirs.user_data_dir per the XDG spec",
}
if func in msg: # pragma: no cover
- pytest.skip(f"`appdirs.{func}` {msg[func]} on Linux") # pragma: no cover
+ pytest.skip(f"`appdirs.{func}` {msg[func]} on Unix") # pragma: no cover
new = getattr(platformdirs, func)(*params)
old = getattr(appdirs, func)(*params)
diff --git a/tests/test_unix.py b/tests/test_unix.py
index 6d55264..b7dc63b 100644
--- a/tests/test_unix.py
+++ b/tests/test_unix.py
@@ -10,6 +10,7 @@
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock import MockerFixture
+from platformdirs import unix
from platformdirs.unix import Unix
@@ -128,18 +129,16 @@
assert result == "/tmp/custom-dir"
-def test_platform_non_linux(monkeypatch: MonkeyPatch) -> None:
- from platformdirs import unix
-
+def test_platform_on_win32(monkeypatch: MonkeyPatch, mocker: MockerFixture) -> None:
+ monkeypatch.delenv("XDG_RUNTIME_DIR", raising=False)
+ mocker.patch("sys.platform", "win32")
+ prev_unix = unix
+ importlib.reload(unix)
try:
- with monkeypatch.context() as context:
- context.setattr(sys, "platform", "magic")
- monkeypatch.delenv("XDG_RUNTIME_DIR", raising=False)
- importlib.reload(unix)
- with pytest.raises(RuntimeError, match="should only be used on Linux"):
+ with pytest.raises(RuntimeError, match="should only be used on Unix"):
unix.Unix().user_runtime_dir
finally:
- importlib.reload(unix)
+ sys.modules["platformdirs.unix"] = prev_unix
def test_ensure_exists_creates_folder(mocker: MockerFixture, tmp_path: Path) -> None:
diff --git a/tox.ini b/tox.ini
index c3cacb0..dbbde8e 100644
--- a/tox.ini
+++ b/tox.ini
@@ -41,7 +41,7 @@
description = run static analysis and style check using flake8
skip_install = true
deps =
- pre-commit>=3.2.2
+ pre-commit>=3.3.1
pass_env =
HOMEPATH
PROGRAMDATA
@@ -63,7 +63,7 @@
skip_install = true
deps =
covdefaults>=2.3
- coverage[toml]>=7.2.3
+ coverage[toml]>=7.2.5
diff-cover>=7.5
extras =
parallel_show_output = true
diff --git a/whitelist.txt b/whitelist.txt
index 661054e..ac5ecbc 100644
--- a/whitelist.txt
+++ b/whitelist.txt
@@ -25,5 +25,6 @@
shell32
typehints
usefixtures
+win32
winreg
xdg