Skip to content

Commit 1858ee4

Browse files
authored
Allow drivers requiring extended attributes to use any xattr implementation (#194)
There are two reasonably popular implementations of "xattr" on PyPI: - xattr - pyxattr They both provide the same importable name, "import xattr", but provide different APIs once you do import it. There can only be one installed to any given python environment. Detect which one is available and utilize its API, rather than assume that the one preferred by this package's install_requires is the one actually installed in the current environment. This aids people in manually crafting environments containing a mix of packages if any of them require pyxattr specifically. Unfortunately PyPA metadata standards do not support boolean "OR" dependency operators, so this is primarily useful to people installing software using a non-python package manager (such as a linux distro package manager). Signed-off-by: Eli Schwartz <[email protected]>
1 parent 8f652b2 commit 1858ee4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pifpaf/drivers/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ def _ensure_xattr_support(self):
7575
xattr_supported = False
7676
if xattr is not None:
7777
try:
78-
x = xattr.xattr(testfile)
79-
x[b"user.test"] = b"test"
78+
# PyPI: xattr
79+
if hasattr(xattr, 'xattr'):
80+
x = xattr.xattr(testfile)
81+
x[b"user.test"] = b"test"
82+
# PyPI: pyxattr
83+
else:
84+
xattr.setxattr(testfile, 'user.test', 'test')
8085
except (OSError, IOError) as e:
8186
if e.errno != 95:
8287
raise

0 commit comments

Comments
 (0)