[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/

2024-04-08 Thread Arthur Zamarin
commit: 936902901eb8df408a2bc708b327cf7e1325da16
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Mon Apr  8 19:32:45 2024 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Mon Apr  8 19:32:45 2024 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=93690290

arghparse: fix handling with python 3.11.9

In commit [0], the private function changes the tuple size it returns.
By using `*_` in the middle, we can support both extracted versions (3
and 4) of the function.

This investigation was done by ajak, thank you.

[0] 
https://github.com/python/cpython/commit/c02b7ae4dd367444aa6822d5fb73b61e8f5a4ff9

Resolves: https://github.com/pkgcore/pkgcheck/issues/676
Resolves: https://github.com/pkgcore/pkgdev/issues/184
Investigated-by: John Helmert III  gentoo.org>
Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/cli/arghparse.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index ab458c8f..80443b7a 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -774,7 +774,7 @@ class OptionalsParser(argparse.ArgumentParser):
 def consume_optional(start_index):
 # get the optional identified at this index
 option_tuple = option_string_indices[start_index]
-action, option_string, explicit_arg = option_tuple
+action, option_string, *_, explicit_arg = option_tuple
 
 # identify additional optionals in the same arg string
 # (e.g. -xyz is the same as -x -y -z if no args are required)



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/

2024-01-26 Thread Arthur Zamarin
commit: 08d724940a92c06e183d112a0377ef32c911a7c3
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Jan 26 20:14:15 2024 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Jan 26 20:14:15 2024 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=08d72494

start work on 0.10.8

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/snakeoil/__init__.py b/src/snakeoil/__init__.py
index 08fa7208..895309fd 100644
--- a/src/snakeoil/__init__.py
+++ b/src/snakeoil/__init__.py
@@ -11,4 +11,4 @@ This library is a bit of a grabbag of the following:
 """
 
 __title__ = "snakeoil"
-__version__ = "0.10.7"
+__version__ = "0.10.8"



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/dist/

2024-01-26 Thread Arthur Zamarin
commit: 0751928445518f9883eb2329af71d91b0aa5
Author: Brian Harring  gmail  com>
AuthorDate: Fri Jan 26 04:59:26 2024 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Jan 26 19:17:27 2024 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=07519289

fix(sphinx_ext): email is optional.

It's not obvious, but both name and email are optional for
authors.  NFC what one does with an author field lacking both,
but that's for the PEP authors to resolve.

We have authors in the pkgcore project that don't have email
listed, which now breaks html generation.  Thus this change.

The only hanky point here is that if it's just email, we output
that w/out the usual `<{email}>` brackets per standards.

Signed-off-by: Brian Harring  gmail.com>
Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/dist/sphinxext.py | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/snakeoil/dist/sphinxext.py b/src/snakeoil/dist/sphinxext.py
index 7d04c49d..36d63e23 100644
--- a/src/snakeoil/dist/sphinxext.py
+++ b/src/snakeoil/dist/sphinxext.py
@@ -30,9 +30,19 @@ def prepare_scripts_man(repo_dir: Path, man_pages: 
list[tuple]):
 with open(repo_dir / 'pyproject.toml', 'rb') as file:
 pyproj = tomllib.load(file)
 
-authors_list = [
-f'{author["name"]} <{author["email"]}>' for author in 
pyproj['project']['authors']
-]
+authors_list: list[str] = []
+for author in pyproj['project']['authors']:
+name, email = author.get('name'), author.get('email')
+if name:
+if email:
+authors_list.append(f'{name} <{email}>')
+else:
+authors_list.append(name)
+elif email:
+authors_list.append(email)
+else:
+# no name or contact info, so ignore it.
+continue
 
 for i, man_page in enumerate(man_pages):
 if man_page[3] is None:



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/osutils/, tests/cli/, src/snakeoil/, tests/

2024-01-26 Thread Arthur Zamarin
commit: 21b0291a014d17bc4681ae66b0d900c96279fc53
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Jan 26 09:03:13 2024 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Jan 26 09:03:13 2024 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=21b0291a

reformat with black 24

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/constraints.py|  6 +++---
 src/snakeoil/containers.py |  3 ---
 src/snakeoil/data_source.py|  3 ---
 src/snakeoil/demandload.py |  1 -
 src/snakeoil/fileutils.py  |  1 -
 src/snakeoil/obj.py|  1 -
 src/snakeoil/osutils/native_readdir.py |  1 -
 src/snakeoil/stringio.py   |  6 ++
 src/snakeoil/struct_compat.py  |  1 -
 src/snakeoil/tar.py|  1 -
 tests/cli/test_arghparse.py|  7 ---
 tests/test_osutils.py  |  7 ---
 tests/test_version.py  | 21 -
 13 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/src/snakeoil/constraints.py b/src/snakeoil/constraints.py
index c239727c..5fe46ec1 100644
--- a/src/snakeoil/constraints.py
+++ b/src/snakeoil/constraints.py
@@ -80,9 +80,9 @@ class Problem:
 def __init__(self):
 self.variables: dict[str, _Domain] = {}
 self.constraints: list[tuple[Constraint, frozenset[str]]] = []
-self.vconstraints: dict[
-str, list[tuple[Constraint, frozenset[str]]]
-] = defaultdict(list)
+self.vconstraints: dict[str, list[tuple[Constraint, frozenset[str 
= (
+defaultdict(list)
+)
 
 def add_variable(self, domain: Iterable[Any], *variables: str):
 """Add variables to the problem, which use the specified domain.

diff --git a/src/snakeoil/containers.py b/src/snakeoil/containers.py
index ebfc1b39..ee14baf6 100644
--- a/src/snakeoil/containers.py
+++ b/src/snakeoil/containers.py
@@ -18,7 +18,6 @@ from .klass import steal_docs
 
 
 class InvertedContains(set):
-
 """Set that inverts all contains lookup results.
 
 Essentially, it's a set class usable for blacklist containment testing.
@@ -97,7 +96,6 @@ class SetMixin:
 
 
 class LimitedChangeSet(SetMixin):
-
 """
 Set used to limit the number of times a key can be removed/added.
 
@@ -263,7 +261,6 @@ class ProtectedSet(SetMixin):
 
 
 class RefCountingSet(dict):
-
 """
 Set implementation that implements refcounting for add/remove, removing 
the key only when its refcount is 0.
 

diff --git a/src/snakeoil/data_source.py b/src/snakeoil/data_source.py
index 3b0ccb16..bb265d9f 100644
--- a/src/snakeoil/data_source.py
+++ b/src/snakeoil/data_source.py
@@ -190,7 +190,6 @@ class base:
 
 
 class local_source(base):
-
 """locally accessible data source
 
 Literally a file on disk.
@@ -289,7 +288,6 @@ class bz2_source(base):
 
 
 class data_source(base):
-
 """
 base class encapsulating a purely virtual data source lacking an on disk 
location.
 
@@ -389,7 +387,6 @@ class bytes_data_source(data_source):
 
 
 class invokable_data_source(data_source):
-
 """
 data source that takes a callable instead of the actual data item
 

diff --git a/src/snakeoil/demandload.py b/src/snakeoil/demandload.py
index bfa6dce7..1fc6b63f 100644
--- a/src/snakeoil/demandload.py
+++ b/src/snakeoil/demandload.py
@@ -131,7 +131,6 @@ else:
 
 
 class Placeholder:
-
 """Object that knows how to replace itself when first accessed.
 
 See the module docstring for common problems with its use.

diff --git a/src/snakeoil/fileutils.py b/src/snakeoil/fileutils.py
index 02355a87..fdd0f23e 100644
--- a/src/snakeoil/fileutils.py
+++ b/src/snakeoil/fileutils.py
@@ -52,7 +52,6 @@ def mmap_or_open_for_read(path: str):
 
 
 class AtomicWriteFile_mixin:
-
 """File class that stores the changes in a tempfile.
 
 Upon invocation of the close method, this class will use

diff --git a/src/snakeoil/obj.py b/src/snakeoil/obj.py
index a8598bfb..6239b207 100644
--- a/src/snakeoil/obj.py
+++ b/src/snakeoil/obj.py
@@ -73,7 +73,6 @@ If that doesn't make sense to the reader, it's probably best 
that the reader not
 try to proxy builtin objects like tuples, lists, dicts, sets, etc.
 """
 
-
 __all__ = ("DelayedInstantiation", "DelayedInstantiation_kls", "make_kls", 
"popattr")
 
 from . import klass

diff --git a/src/snakeoil/osutils/native_readdir.py 
b/src/snakeoil/osutils/native_readdir.py
index 6600a719..d13e1ae1 100644
--- a/src/snakeoil/osutils/native_readdir.py
+++ b/src/snakeoil/osutils/native_readdir.py
@@ -1,6 +1,5 @@
 """Wrapper for readdir which grabs file type from d_type."""
 
-
 import errno
 import os
 from stat import (

diff --git a/src/snakeoil/stringio.py b/src/snakeoil/stringio.py
index 1a392eb4..339ec970 100644
--- a/src/snakeoil/stringio.py
+++ b/src/snakeoil/stringio.py
@@ -44,9 +44,7 @@ class _make_ro_cls(type):
 return x
 
 
-class 

[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/

2024-01-18 Thread Arthur Zamarin
commit: c6280c1c86b158b1becbefd5c1debc07f5a9d188
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Thu Jan 18 17:13:35 2024 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Thu Jan 18 17:13:42 2024 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=c6280c1c

start work on 0.10.7

This release might deprecate a lot of functionality which should be
unused. Most likely next release would be 0.11.0

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/snakeoil/__init__.py b/src/snakeoil/__init__.py
index 17aa8de2..08fa7208 100644
--- a/src/snakeoil/__init__.py
+++ b/src/snakeoil/__init__.py
@@ -11,4 +11,4 @@ This library is a bit of a grabbag of the following:
 """
 
 __title__ = "snakeoil"
-__version__ = "0.10.6"
+__version__ = "0.10.7"



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/

2024-01-17 Thread Arthur Zamarin
commit: d84df20569840532fb915aa0b6090ee6c7a62af3
Author: Brian Harring  gmail  com>
AuthorDate: Tue Jan 16 04:58:43 2024 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Tue Jan 16 05:00:58 2024 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=d84df205

Add missing DirProxy/GetAttrProxy to klass.__all__

These are public symbols and were supposed to be marked
as such.

Signed-off-by: Brian Harring  gmail.com>

 src/snakeoil/klass.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/snakeoil/klass.py b/src/snakeoil/klass.py
index 23d6d3c5..08daaab2 100644
--- a/src/snakeoil/klass.py
+++ b/src/snakeoil/klass.py
@@ -28,6 +28,8 @@ __all__ = (
 "alias",
 "patch",
 "SlotsPicklingMixin",
+"DirProxy",
+"GetAttrProxy",
 )
 
 import inspect



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/

2023-09-08 Thread Arthur Zamarin
commit: 379bf7a6cd7fb7b7c3684c834e20b8d4fe1170ae
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Wed Aug 30 04:20:08 2023 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Wed Aug 30 04:20:08 2023 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=379bf7a6

mappings: small refactor

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/mappings.py | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/snakeoil/mappings.py b/src/snakeoil/mappings.py
index d4ac221d..f3663571 100644
--- a/src/snakeoil/mappings.py
+++ b/src/snakeoil/mappings.py
@@ -298,7 +298,7 @@ class ProtectedDict(DictMixin):
 raise KeyError(key)
 
 def keys(self):
-for k in self.new.keys():
+for k in self.new:
 yield k
 for k in self.orig.keys():
 if k not in self.blacklist and k not in self.new:
@@ -320,14 +320,14 @@ class ImmutableDict(Mapping):
 elif isinstance(data, Mapping):
 mapping = data
 elif isinstance(data, DictMixin):
-mapping = {k: v for k, v in data.items()}
+mapping = dict(data.items())
 elif data is None:
 mapping = {}
 else:
 try:
-mapping = {k: v for k, v in data}
-except TypeError as e:
-raise TypeError(f"unsupported data format: {e}")
+mapping = dict(data)
+except TypeError as exc:
+raise TypeError(f"unsupported data format: {exc}")
 object.__setattr__(self, "_dict", mapping)
 
 def __getitem__(self, key):
@@ -362,8 +362,8 @@ class OrderedFrozenSet(Set):
 def __init__(self, iterable=()):
 try:
 self._dict = ImmutableDict({x: None for x in iterable})
-except TypeError as e:
-raise TypeError("not iterable") from e
+except TypeError as exc:
+raise TypeError("not iterable") from exc
 
 def __contains__(self, key):
 return key in self._dict
@@ -419,8 +419,8 @@ class OrderedSet(OrderedFrozenSet, MutableSet):
 def __init__(self, iterable=()):
 try:
 self._dict = {x: None for x in iterable}
-except TypeError as e:
-raise TypeError("not iterable") from e
+except TypeError as exc:
+raise TypeError("not iterable") from exc
 
 def add(self, value):
 self._dict[value] = None



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/dist/

2023-03-24 Thread Arthur Zamarin
commit: 5033316f416e6ff829f6c04a3d1f78d5733e93dd
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Mar 24 11:07:43 2023 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Mar 24 11:07:43 2023 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=5033316f

remove deprecated distutils_extensions

Resolves: https://github.com/pkgcore/snakeoil/issues/77
Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/dist/distutils_extensions.py | 1049 -
 1 file changed, 1049 deletions(-)

diff --git a/src/snakeoil/dist/distutils_extensions.py 
b/src/snakeoil/dist/distutils_extensions.py
deleted file mode 100644
index 10a77ed5..
--- a/src/snakeoil/dist/distutils_extensions.py
+++ /dev/null
@@ -1,1049 +0,0 @@
-"""
-A collection of distutils extensions adding things like automatic 2to3
-translation, a test runner, and working around broken stdlib extensions CFLAG
-passing in distutils.
-
-Specifically, this module is only meant to be imported in setup.py scripts.
-"""
-
-import copy
-import errno
-import inspect
-import operator
-import os
-import re
-import shlex
-import shutil
-import subprocess
-import sys
-import textwrap
-import warnings
-from contextlib import ExitStack, contextmanager, redirect_stderr, 
redirect_stdout
-from multiprocessing import cpu_count
-
-from setuptools import find_packages
-from setuptools.command import build_py as dst_build_py
-from setuptools.command import install as dst_install
-from setuptools.dist import Distribution
-from distutils import log
-from distutils.command import build as dst_build
-from distutils.command import build_ext as dst_build_ext
-from distutils.command import build_scripts as dst_build_scripts
-from distutils.command import config as dst_config
-from distutils.command import sdist as dst_sdist
-from distutils.core import Command, Extension
-from distutils.errors import DistutilsError, DistutilsExecError
-
-from ..contexts import syspath
-from ..version import get_git_version
-from .generate_docs import generate_html, generate_man
-
-warnings.warn("the distutils_extensions module is deprecated", 
DeprecationWarning, stacklevel=2)
-
-# forcibly disable lazy module loading
-os.environ['SNAKEOIL_DEMANDIMPORT'] = 'false'
-
-# top level repo/tarball directory
-REPODIR = os.environ.get('PKGDIST_REPODIR')
-if REPODIR is None:
-# hack to verify we're running under a setup.py script and grab its info
-for _frameinfo in reversed(inspect.stack(0)):
-_filename = _frameinfo[1]
-if os.path.basename(_filename) == 'setup.py':
-REPODIR = os.path.dirname(os.path.abspath(_filename))
-break
-_filename_dir = os.path.dirname(os.path.abspath(_filename))
-if os.path.exists(os.path.join(_filename_dir, 'setup.py')):
-REPODIR = _filename_dir
-break
-else:
-REPODIR = os.getcwd() # try CWD
-if not os.path.exists(os.path.join(REPODIR, 'setup.py')):
-raise ImportError('this module is only meant to be imported in 
setup.py scripts')
-
-# running under pip
-PIP = os.path.basename(os.environ.get('_', '')) == 'pip' or 
any(part.startswith('pip-') for part in REPODIR.split(os.sep))
-
-# executable scripts directory
-SCRIPTS_DIR = os.path.join(REPODIR, 'bin')
-
-
-def find_moduledir(searchdir=REPODIR):
-"""Determine a module's directory path.
-
-Based on the assumption that the project is only distributing one main
-module.
-"""
-modules = []
-moduledir = None
-searchdir_depth = len(searchdir.split('/'))
-# allow modules to be found inside a top-level dir, e.g. 'src'
-searchdir_depth += 1
-
-# look for a top-level module
-for root, dirs, files in os.walk(searchdir):
-# only descend to a specified level
-if len(root.split('/')) > searchdir_depth + 1:
-continue
-if '__init__.py' in files:
-# only match modules with __title__ defined in the main module
-with open(os.path.join(root, '__init__.py'), encoding='utf-8') as 
f:
-try:
-if re.search(r'^__title__\s*=\s*[\'"]([^\'"]*)[\'"]',
- f.read(), re.MULTILINE):
-modules.append(root)
-except AttributeError:
-continue
-
-if len(modules) == 1:
-moduledir = modules[0]
-elif len(modules) > 1:
-raise ValueError(
-'Multiple main modules found in %r: %s' % (
-searchdir, ', '.join(os.path.basename(x) for x in modules)))
-
-if moduledir is None:
-raise ValueError('No main module found')
-
-return moduledir
-
-
-# determine the main module we're being used to package
-MODULEDIR = find_moduledir()
-PACKAGEDIR = os.path.dirname(MODULEDIR)
-MODULE_NAME = os.path.basename(MODULEDIR)
-
-# running against git/unreleased version
-GIT = not 

[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/

2023-01-19 Thread Arthur Zamarin
commit: 9f1bd128877bc2c316473d34aa4e2cdaec431331
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Jan 20 07:36:47 2023 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Jan 20 07:36:47 2023 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=9f1bd128

start work on 0.10.6

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/snakeoil/__init__.py b/src/snakeoil/__init__.py
index 2009d305..17aa8de2 100644
--- a/src/snakeoil/__init__.py
+++ b/src/snakeoil/__init__.py
@@ -11,4 +11,4 @@ This library is a bit of a grabbag of the following:
 """
 
 __title__ = "snakeoil"
-__version__ = "0.10.5"
+__version__ = "0.10.6"



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: /, src/snakeoil/

2023-01-19 Thread Arthur Zamarin
commit: c0ca221cd9c6e3970a2baaa732289f65afdaca7c
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Jan 20 07:30:57 2023 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Jan 20 07:30:57 2023 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=c0ca221c

new release 0.10.5

Signed-off-by: Arthur Zamarin  gentoo.org>

 NEWS.rst | 10 ++
 src/snakeoil/__init__.py |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/NEWS.rst b/NEWS.rst
index 6a654017..482b2856 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -2,6 +2,16 @@
 Release Notes
 =
 
+snakeoil 0.10.5 (2023-01-20)
+
+
+- cli.arghparse: improve _format_args for Delayed (Arthur Zamarin)
+  https://github.com/pkgcore/pkgcheck/issues/520
+
+- compression: prefer gtar over tar if available (Sam James, #93)
+
+- format code with ``black`` (Brian Harring, Arthur Zamarin, #95)
+
 snakeoil 0.10.4 (2022-12-09)
 
 

diff --git a/src/snakeoil/__init__.py b/src/snakeoil/__init__.py
index a1c1f205..2009d305 100644
--- a/src/snakeoil/__init__.py
+++ b/src/snakeoil/__init__.py
@@ -11,4 +11,4 @@ This library is a bit of a grabbag of the following:
 """
 
 __title__ = "snakeoil"
-__version__ = "0.10.4"
+__version__ = "0.10.5"



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/

2023-01-19 Thread Arthur Zamarin
commit: c3024463f81783169aba78ad93bfc0a0502f1daf
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Jan 20 07:24:18 2023 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Jan 20 07:24:18 2023 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=c3024463

cli.arghparse: add missing comma in help metavar text

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/cli/arghparse.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index 375ffe42..a1d1c0b1 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -519,8 +519,7 @@ class _SubParser(argparse._SubParsersAction):
 Reverts the broken upstream change made in issue #9351 which causes
 issue #23058. This can be dropped when the problem is fixed upstream.
 """
-parser_name = values[0]
-arg_strings = values[1:]
+parser_name, *arg_strings = values
 
 # set the parser name if requested
 if self.dest is not argparse.SUPPRESS:
@@ -555,7 +554,7 @@ class CsvHelpFormatter(argparse.HelpFormatter):
 ):
 result = "%s[,-%s,...]" % get_metavar(2)
 elif isinstance(action, (CommaSeparatedElements, 
CommaSeparatedElementsAppend)):
-result = "%s[,-%s,+%s...]" % get_metavar(3)
+result = "%s[,-%s,+%s,...]" % get_metavar(3)
 elif isinstance(action, Delayed):
 result = self._format_args(action.target, default_metavar)
 else:



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/

2023-01-17 Thread Arthur Zamarin
commit: 34f1962cde1d4ef5e5737048bee2a88abdba804a
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Tue Jan 17 20:38:12 2023 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Tue Jan 17 20:38:12 2023 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=34f1962c

formatters: add typing annotations

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/formatters.py | 48 +++---
 1 file changed, 33 insertions(+), 15 deletions(-)

diff --git a/src/snakeoil/formatters.py b/src/snakeoil/formatters.py
index 3faf661a..151778c6 100644
--- a/src/snakeoil/formatters.py
+++ b/src/snakeoil/formatters.py
@@ -4,6 +4,7 @@ import errno
 import io
 import locale
 import os
+import typing
 from functools import partial
 
 from .klass import GetAttrProxy, steal_docs
@@ -49,7 +50,11 @@ class Formatter:
 self.autoline = True
 self.wrap = False
 
-def write(self, *args, **kwargs):
+def write(
+self,
+*args: typing.Union[None, str, typing.Callable[["Formatter"], None]],
+**kwargs,
+):
 """Write something to the stream.
 
 Acceptable arguments are:
@@ -80,7 +85,7 @@ class Formatter:
 to write.
 """
 
-def fg(self, color=None):
+def fg(self, color: typing.Optional[str] = None) -> str:
 """Change foreground color.
 
 :param color: color to change to. A default is used if omitted.
@@ -89,7 +94,7 @@ class Formatter:
 color, if possible for this formatter.
 """
 
-def bg(self, color=None):
+def bg(self, color: typing.Optional[str] = None) -> str:
 """Change background color.
 
 :param color: color to change to. A default is used if omitted.
@@ -98,15 +103,21 @@ class Formatter:
 color, if possible for this formatter.
 """
 
-def error(self, message):
+def error(
+self, message: typing.Union[None, str, typing.Callable[["Formatter"], 
None]]
+):
 """Format a string as an error message."""
 self.write(message, prefixes=(self.fg("red"), self.bold, "!!! ", 
self.reset))
 
-def warn(self, message):
+def warn(
+self, message: typing.Union[None, str, typing.Callable[["Formatter"], 
None]]
+):
 """Format a string as a warning message."""
 self.write(message, prefixes=(self.fg("yellow"), self.bold, "*** ", 
self.reset))
 
-def title(self, string):
+def title(
+self, string: typing.Union[None, str, typing.Callable[["Formatter"], 
None]]
+):
 """Set the title to string"""
 
 def flush(self):
@@ -125,7 +136,9 @@ class PlainTextFormatter(Formatter):
 
 bold = underline = reset = ""
 
-def __init__(self, stream, width=79, encoding=None):
+def __init__(
+self, stream: typing.IO, width: int = 79, encoding: 
typing.Optional[str] = None
+):
 """Initialize.
 
 :type stream: file-like object.
@@ -321,7 +334,7 @@ class _BogusTerminfo(ValueError):
 class TerminfoUnsupported(Exception):
 """Raised if our terminal type is unsupported."""
 
-def __init__(self, term):
+def __init__(self, term: str):
 self.term = term
 
 def __str__(self):
@@ -345,11 +358,11 @@ else:
 
 __slots__ = ("mode", "color", "__weakref__")
 
-def __init__(self, mode, color):
+def __init__(self, mode: int, color: str):
 object.__setattr__(self, "mode", mode)
 object.__setattr__(self, "color", color)
 
-def __call__(self, formatter):
+def __call__(self, formatter: "TerminfoFormatter"):
 if self.color is None:
 formatter._current_colors[self.mode] = None
 res = formatter._color_reset
@@ -398,7 +411,7 @@ else:
 __doc__ = TerminfoCode.__doc__
 __slots__ = ()
 
-def __call__(self, formatter):
+def __call__(self, formatter: "TerminfoFormatter"):
 formatter._modes.add(self)
 formatter.stream.write(self.value)
 
@@ -407,7 +420,7 @@ else:
 __doc__ = TerminfoCode.__doc__
 __slots__ = ()
 
-def __call__(self, formatter):
+def __call__(self, formatter: "TerminfoFormatter"):
 formatter._modes.clear()
 formatter.stream.write(self.value)
 
@@ -425,7 +438,12 @@ else:
 white=curses.COLOR_WHITE,
 )
 
-def __init__(self, stream, term=None, encoding=None):
+def __init__(
+self,
+stream: typing.IO,
+term: typing.Optional[str] = None,
+encoding: typing.Optional[str] = None,
+):
 """Initialize.
 
 :type stream: file-like object.
@@ -521,7 +539,7 @@ class ObserverFormatter:
 fileno_excepts = (AttributeError, io.UnsupportedOperation)
 
 
-def get_formatter(stream, force_color=False):
+def get_formatter(stream: typing.IO, force_color: bool = False):
 

[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/

2023-01-16 Thread Arthur Zamarin
commit: 8addc22ed18f84e1047be4ca71084832bdb1cdd8
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Mon Jan 16 20:55:36 2023 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Mon Jan 16 20:55:36 2023 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=8addc22e

cli.arghparse: improve _format_args for Delayed

Resolves: https://github.com/pkgcore/pkgcheck/issues/520
Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/cli/arghparse.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index 09eaed36..375ffe42 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -556,6 +556,8 @@ class CsvHelpFormatter(argparse.HelpFormatter):
 result = "%s[,-%s,...]" % get_metavar(2)
 elif isinstance(action, (CommaSeparatedElements, 
CommaSeparatedElementsAppend)):
 result = "%s[,-%s,+%s...]" % get_metavar(3)
+elif isinstance(action, Delayed):
+result = self._format_args(action.target, default_metavar)
 else:
 result = super()._format_args(action, default_metavar)
 return result



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/process/, src/snakeoil/cli/

2022-12-31 Thread Arthur Zamarin
commit: dc37e84e60f65d5ee710408c8c65a34d94ccba07
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Sat Dec 31 13:43:22 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Sat Dec 31 13:43:22 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=dc37e84e

process.spawn: add type annotations

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/cli/arghparse.py |  2 +-
 src/snakeoil/process/spawn.py | 86 ++-
 2 files changed, 45 insertions(+), 43 deletions(-)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index a1209092..09eaed36 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -1309,7 +1309,7 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
 self.error(str(exc))
 
 # run final arg validation
-for check in set(args.__dict__.keys()):
+for check in tuple(args.__dict__.keys()):
 if check.startswith("__final_check__"):
 functor = args.pop(check)
 functor(self, args)

diff --git a/src/snakeoil/process/spawn.py b/src/snakeoil/process/spawn.py
index ce8fe58a..27095988 100644
--- a/src/snakeoil/process/spawn.py
+++ b/src/snakeoil/process/spawn.py
@@ -16,6 +16,7 @@ import itertools
 import os
 import signal
 import sys
+from typing import Iterable, Optional, Sequence, Union
 
 from ..mappings import ProtectedDict
 from ..osutils import access
@@ -27,12 +28,12 @@ SANDBOX_BINARY = find_binary("sandbox", 
fallback="/usr/bin/sandbox")
 try:
 import resource
 
-max_fd_limit = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
+max_fd_limit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)
 except ImportError:
 max_fd_limit = 256
 
 
-def bash_version(force=False):
+def bash_version(force: bool = False):
 """Get the system bash version of the form major.minor.patch."""
 if not force:
 try:
@@ -41,13 +42,13 @@ def bash_version(force=False):
 pass
 try:
 ret, ver = spawn_get_output(
-[
+(
 BASH_BINARY,
 "--norc",
 "--noprofile",
 "-c",
 "printf 
${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}.${BASH_VERSINFO[2]}",
-]
+)
 )
 if ret == 0:
 try:
@@ -62,7 +63,9 @@ def bash_version(force=False):
 return ver
 
 
-def spawn_bash(mycommand, debug=False, name=None, **kwds):
+def spawn_bash(
+mycommand: Union[str, Iterable[str]], debug: bool = False, name: str = 
None, **kwds
+):
 """spawn the command via bash -c"""
 
 args = [BASH_BINARY, "--norc", "--noprofile"]
@@ -79,7 +82,7 @@ def spawn_bash(mycommand, debug=False, name=None, **kwds):
 return spawn(args, name=name, **kwds)
 
 
-def spawn_sandbox(mycommand, name=None, **kwds):
+def spawn_sandbox(mycommand: Union[str, Iterable[str]], name: str = None, 
**kwds):
 """spawn the command under sandboxed"""
 
 if not is_sandbox_capable():
@@ -134,10 +137,9 @@ atexit.register(run_exitfuncs)
 spawned_pids = []
 
 
-def cleanup_pids(pids=None):
+def cleanup_pids(pids: Iterable[int] = None):
 """reap list of pids if specified, else all children"""
 
-global spawned_pids
 if pids is None:
 pids = spawned_pids
 elif pids is not spawned_pids:
@@ -162,17 +164,17 @@ def cleanup_pids(pids=None):
 
 
 def spawn(
-mycommand,
-env=None,
-name=None,
-fd_pipes=None,
-returnpid=False,
-uid=None,
-gid=None,
-groups=None,
-umask=None,
-cwd=None,
-pgid=None,
+mycommand: Union[str, Sequence[str]],
+env: Optional[dict[str, str]] = None,
+name: Optional[str] = None,
+fd_pipes: Optional[dict[int, int]] = None,
+returnpid: bool = False,
+uid: Optional[int] = None,
+gid: Optional[int] = None,
+groups: Optional[Sequence[int]] = None,
+umask: Optional[int] = None,
+cwd: Optional[str] = None,
+pgid: Optional[int] = None,
 ):
 
 """wrapper around execve
@@ -216,11 +218,11 @@ def spawn(
 cwd,
 pgid,
 )
-except Exception as e:
+except Exception as exc:
 # We need to catch _any_ exception so that it doesn't
-# propogate out of this function and cause exiting
+# propagate out of this function and cause exiting
 # with anything other than os._exit()
-sys.stderr.write("%s:\n   %s\n" % (e, " ".join(mycommand)))
+sys.stderr.write(f"{exc}:\n   {' '.join(mycommand)}\n")
 os._exit(1)
 
 # Add the pid to our local and the global pid lists.
@@ -266,17 +268,17 @@ def spawn(
 
 
 def _exec(
-binary,
-mycommand,
-name=None,
-fd_pipes=None,
-env=None,
-gid=None,
-groups=None,
-uid=None,
-umask=None,
-cwd=None,
-pgid=None,
+binary: str,
+mycommand: 

[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/

2022-12-30 Thread Arthur Zamarin
commit: 103472541ea9df637e52bf01af707df831e872a3
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Sat Dec 31 07:35:40 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Sat Dec 31 07:35:40 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=10347254

cli.arghparse: fix bind_final_check

Follows: 47d21307c44cad87641e20f50f57b3f5d218c0f4
Closes: https://github.com/pkgcore/pkgdev/issues/112
Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/cli/arghparse.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index a7a29826..a1209092 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -1309,7 +1309,7 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
 self.error(str(exc))
 
 # run final arg validation
-for check in set(vars(args).keys()):
+for check in set(args.__dict__.keys()):
 if check.startswith("__final_check__"):
 functor = args.pop(check)
 functor(self, args)



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/cli/

2022-12-30 Thread Arthur Zamarin
commit: 47d21307c44cad87641e20f50f57b3f5d218c0f4
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Dec 30 19:03:36 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Dec 30 19:03:36 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=47d21307

little modernization of snakeoil.cli

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/cli/arghparse.py | 48 +--
 src/snakeoil/cli/input.py |  5 ++---
 src/snakeoil/cli/tool.py  |  2 +-
 3 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index 774699ed..a7a29826 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -148,13 +148,13 @@ class CommaSeparatedValues(argparse._AppendAction):
 """Split comma-separated values into a list."""
 
 def parse_values(self, values):
-items = []
 if isinstance(values, str):
-items.extend(x for x in values.split(",") if x)
+return list(filter(None, values.split(",")))
 else:
+items = []
 for value in values:
 items.extend(x for x in value.split(",") if x)
-return items
+return items
 
 def __call__(self, parser, namespace, values, option_string=None):
 items = self.parse_values(values)
@@ -188,9 +188,9 @@ class CommaSeparatedNegations(argparse._AppendAction):
 values = [values]
 for value in values:
 try:
-neg, pos = split_negations(x for x in value.split(",") if x)
-except ValueError as e:
-raise argparse.ArgumentTypeError(e)
+neg, pos = split_negations(filter(None, value.split(",")))
+except ValueError as exc:
+raise argparse.ArgumentTypeError(exc)
 disabled.extend(neg)
 enabled.extend(pos)
 
@@ -236,9 +236,9 @@ class CommaSeparatedElements(argparse._AppendAction):
 values = [values]
 for value in values:
 try:
-neg, neu, pos = split_elements(x for x in value.split(",") if 
x)
-except ValueError as e:
-raise argparse.ArgumentTypeError(e)
+neg, neu, pos = split_elements(filter(None, value.split(",")))
+except ValueError as exc:
+raise argparse.ArgumentTypeError(exc)
 disabled.extend(neg)
 neutral.extend(neu)
 enabled.extend(pos)
@@ -323,7 +323,7 @@ class StoreBool(argparse._StoreAction):
 return True
 elif value in ("n", "no", "false", "0"):
 return False
-raise ValueError("value %r must be [y|yes|true|1|n|no|false|0]" % 
(value,))
+raise ValueError(f"value {value!r} must be 
[y|yes|true|1|n|no|false|0]")
 
 
 class EnableDebug(argparse._StoreTrueAction):
@@ -469,7 +469,7 @@ class Expansion(argparse.Action):
 args = [x % dvals for x in args]
 if not action:
 raise ValueError(
-"unable to find option %r for %r" % (option, 
self.option_strings)
+f"unable to find option {option!r} for 
{self.option_strings!r}"
 )
 if action.type is not None:
 args = list(map(action.type, args))
@@ -1137,7 +1137,7 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
 help="enable/disable color support",
 docs="""
 Toggle colored output support. This can be used to 
forcibly
-enable color support when piping output or other 
sitations
+enable color support when piping output or other 
situations
 where stdout is not a tty.
 """,
 )
@@ -1273,7 +1273,7 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
 namespace.main_func = subcmd_parser.__main_func
 
 if unknown_args:
-self.error("unrecognized arguments: %s" % " ".join(unknown_args))
+self.error(f"unrecognized arguments: {' '.join(unknown_args)}")
 
 # Two runs are required; first, handle any suppression defaults
 # introduced. Subparsers defaults cannot override the parent parser, as
@@ -1302,19 +1302,17 @@ class ArgumentParser(OptionalsParser, CsvActionsParser):
 try:
 for attr, delayed in sorted(i, key=lambda val: val[1].priority):
 delayed(args, attr)
-except (TypeError, ValueError) as e:
-raise TypeError("failed loading/parsing '%s': %s" % (attr, 
str(e))) from e
+except (TypeError, ValueError) as exc:
+raise TypeError(f"failed loading/parsing {attr!r}: {exc}") from exc
 except argparse.ArgumentError:
-e = sys.exc_info()[1]
-

[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/osutils/

2022-12-25 Thread Arthur Zamarin
commit: fff34f3c83e8f61b99b09c4b08b8fb72fb68e9e8
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Sun Dec 25 18:30:16 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Sun Dec 25 18:30:16 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=fff34f3c

fix after removal of osutils.native_readdir.listdir

Follows: 2e4f73760dcbf1fb15bea4c6a89e4a65012ef74d
Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/osutils/native_readdir.py | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/snakeoil/osutils/native_readdir.py 
b/src/snakeoil/osutils/native_readdir.py
index d7c2fd91..6600a719 100644
--- a/src/snakeoil/osutils/native_readdir.py
+++ b/src/snakeoil/osutils/native_readdir.py
@@ -99,8 +99,7 @@ def readdir(path):
 :param path: path of a directory to scan
 :return: list of (filename, filetype)
 """
-pjf = pjoin
-things = listdir(path)
-lstat = os.lstat
-dt = d_type_mapping
-return [(name, dt[S_IFMT(lstat(pjf(path, name)).st_mode)]) for name in 
things]
+return [
+(name, d_type_mapping[S_IFMT(os.lstat(pjoin(path, name)).st_mode)])
+for name in os.listdir(path)
+]



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/osutils/, tests/

2022-12-25 Thread Arthur Zamarin
commit: 2e4f73760dcbf1fb15bea4c6a89e4a65012ef74d
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Dec 23 21:37:47 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Sun Dec 25 18:26:37 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=2e4f7376

remove osutils.native_readdir.listdir

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/osutils/__init__.py   | 2 +-
 src/snakeoil/osutils/native_readdir.py | 2 --
 tests/test_osutils.py  | 8 +---
 3 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/src/snakeoil/osutils/__init__.py b/src/snakeoil/osutils/__init__.py
index 036a78df..1910859b 100644
--- a/src/snakeoil/osutils/__init__.py
+++ b/src/snakeoil/osutils/__init__.py
@@ -59,7 +59,7 @@ from . import native_readdir as module
 # force utf8 codepaths yet.
 from ..klass import steal_docs
 
-listdir = module.listdir
+listdir = os.listdir
 listdir_dirs = module.listdir_dirs
 listdir_files = module.listdir_files
 readdir = module.readdir

diff --git a/src/snakeoil/osutils/native_readdir.py 
b/src/snakeoil/osutils/native_readdir.py
index b129a9bf..d7c2fd91 100644
--- a/src/snakeoil/osutils/native_readdir.py
+++ b/src/snakeoil/osutils/native_readdir.py
@@ -18,8 +18,6 @@ from stat import (
 
 from ..mappings import ProtectedDict
 
-listdir = os.listdir
-
 # we can still use the cpy pjoin here, just need to do something about the
 # import cycle.
 pjoin = os.path.join

diff --git a/tests/test_osutils.py b/tests/test_osutils.py
index 264d670d..fac98532 100644
--- a/tests/test_osutils.py
+++ b/tests/test_osutils.py
@@ -18,8 +18,7 @@ from snakeoil.osutils.mount import MNT_DETACH, MS_BIND, 
mount, umount
 class ReaddirCommon:
 @pytest.fixture
 def subdir(self, tmp_path):
-subdir = tmp_path / "dir"
-subdir.mkdir()
+(subdir := tmp_path / "dir").mkdir()
 (tmp_path / "file").touch()
 os.mkfifo((tmp_path / "fifo"))
 return subdir
@@ -30,10 +29,6 @@ class ReaddirCommon:
 
 
 class TestNativeListDir(ReaddirCommon):
-def test_listdir(self, tmp_path, subdir):
-assert set(native_readdir.listdir(tmp_path)) == {"dir", "fifo", "file"}
-assert native_readdir.listdir(subdir) == []
-
 def test_listdir_dirs(self, tmp_path, subdir):
 assert native_readdir.listdir_dirs(tmp_path) == ["dir"]
 assert native_readdir.listdir_dirs(subdir) == []
@@ -46,7 +41,6 @@ class TestNativeListDir(ReaddirCommon):
 return self._test_missing(
 tmp_path,
 (
-native_readdir.listdir,
 native_readdir.listdir_dirs,
 native_readdir.listdir_files,
 ),



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/process/

2022-12-25 Thread Arthur Zamarin
commit: 39ae1e0de19462d3953a0680dcc32aa4b3e613f9
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Sun Dec 25 18:24:33 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Sun Dec 25 18:24:33 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=39ae1e0d

remove proces.closerange

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/process/__init__.py | 3 ---
 src/snakeoil/process/spawn.py| 6 +++---
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/snakeoil/process/__init__.py b/src/snakeoil/process/__init__.py
index 8966fd65..63c605d5 100644
--- a/src/snakeoil/process/__init__.py
+++ b/src/snakeoil/process/__init__.py
@@ -92,6 +92,3 @@ class CommandNotFound(Exception):
 class ProcessNotFound(Exception):
 def __init__(self, pid):
 super().__init__(f"nonexistent process: {pid}")
-
-
-closerange = os.closerange

diff --git a/src/snakeoil/process/spawn.py b/src/snakeoil/process/spawn.py
index 48b60b1a..ce8fe58a 100644
--- a/src/snakeoil/process/spawn.py
+++ b/src/snakeoil/process/spawn.py
@@ -19,7 +19,7 @@ import sys
 
 from ..mappings import ProtectedDict
 from ..osutils import access
-from . import CommandNotFound, closerange, find_binary
+from . import find_binary
 
 BASH_BINARY = find_binary("bash", fallback="/bin/bash")
 SANDBOX_BINARY = find_binary("sandbox", fallback="/usr/bin/sandbox")
@@ -336,10 +336,10 @@ def _exec(
 last = 0
 for fd in sorted(fd_pipes):
 if fd != last:
-closerange(last, fd)
+os.closerange(last, fd)
 last = fd + 1
 
-closerange(last, max_fd_limit)
+os.closerange(last, max_fd_limit)
 
 if cwd is not None:
 os.chdir(cwd)



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/

2022-12-25 Thread Arthur Zamarin
commit: fc6842fea1d87995b97c80b99c97686939d9c388
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Sun Dec 25 18:22:29 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Sun Dec 25 18:22:29 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=fc6842fe

fix small boolean values typo

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/demandimport.py | 3 ++-
 src/snakeoil/demandload.py   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/snakeoil/demandimport.py b/src/snakeoil/demandimport.py
index 0a24ccc5..d95f515e 100644
--- a/src/snakeoil/demandimport.py
+++ b/src/snakeoil/demandimport.py
@@ -56,7 +56,8 @@ def enable():
 """Enable lazy loading for all future module imports."""
 if os.environ.get("SNAKEOIL_DEMANDIMPORT", "y").lower() not in (
 "n",
-"no" "0",
+"no",
+"0",
 "false",
 ):
 sys.path_hooks.insert(0, _filefinder)

diff --git a/src/snakeoil/demandload.py b/src/snakeoil/demandload.py
index 3800622f..bfa6dce7 100644
--- a/src/snakeoil/demandload.py
+++ b/src/snakeoil/demandload.py
@@ -313,7 +313,8 @@ def disabled_demand_compile_regexp(name, *args, **kwargs):
 
 if os.environ.get("SNAKEOIL_DEMANDLOAD_DISABLED", "n").lower() in (
 "y",
-"yes" "1",
+"yes",
+"1",
 "true",
 ):
 demandload = disabled_demandload



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/compression/

2022-12-22 Thread Arthur Zamarin
commit: daf56c11e302c253368906ba468e4c368d611d4e
Author: Sam James  gentoo  org>
AuthorDate: Thu Dec 22 03:39:39 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Thu Dec 22 09:17:58 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=daf56c11

compression: prefer gtar over tar if available

Prefer 'gtar' over 'tar' if available, as we need GNU tar for
--use-compress-program.

With libarchive's tar, we get an 'unrecognized archive' error.

Signed-off-by: Sam James  gentoo.org>
Closes: https://github.com/pkgcore/snakeoil/pull/93
Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/compression/__init__.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/snakeoil/compression/__init__.py 
b/src/snakeoil/compression/__init__.py
index 580a70a2..77c0631b 100644
--- a/src/snakeoil/compression/__init__.py
+++ b/src/snakeoil/compression/__init__.py
@@ -145,7 +145,7 @@ class _CompressedStdin:
 class _Tar(_Archive, ArComp):
 
 exts = frozenset(['.tar'])
-binary = ('tar',)
+binary = ('gtar', 'tar',)
 compress_binary = None
 default_unpack_cmd = '{binary} xf "{path}"'
 
@@ -156,6 +156,7 @@ class _Tar(_Archive, ArComp):
 for b in self.compress_binary:
 try:
 process.find_binary(b[0])
+# FIXME: This is a gnuism, needs gnu tar.
 cmd += f' --use-compress-program="{" ".join(b)}"'
 break
 except process.CommandNotFound:



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/dist/

2022-12-09 Thread Arthur Zamarin
commit: 3e9c92ef1ea53b15974c730e5709ccb08a309dea
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Dec  9 13:30:32 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Dec  9 13:30:32 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=3e9c92ef

generate_man_rsts: better formatting for options

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/dist/generate_man_rsts.py | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/snakeoil/dist/generate_man_rsts.py 
b/src/snakeoil/dist/generate_man_rsts.py
index 6c482211..ca20b360 100644
--- a/src/snakeoil/dist/generate_man_rsts.py
+++ b/src/snakeoil/dist/generate_man_rsts.py
@@ -34,6 +34,10 @@ class RawTextFormatter(argparse.RawTextHelpFormatter):
 action.help = '\n' + action.help.strip()
 return super()._format_action(action)
 
+def _format_action_invocation(self, action):
+text = super()._format_action_invocation(action)
+return f':option:`{text}`'
+
 
 class ManConverter:
 """Convert argparse help docs into rST man pages."""



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/dist/

2022-12-09 Thread Arthur Zamarin
commit: 25cca84e6c6959164257fb2ba3fedb95815b45e0
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Dec  9 13:29:11 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Dec  9 13:29:11 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=25cca84e

generate_man_rsts: improve sub sectioning for sub commands

Improve tree structure for sub commands.

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/dist/generate_man_rsts.py | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/snakeoil/dist/generate_man_rsts.py 
b/src/snakeoil/dist/generate_man_rsts.py
index 6ba095f4..6c482211 100644
--- a/src/snakeoil/dist/generate_man_rsts.py
+++ b/src/snakeoil/dist/generate_man_rsts.py
@@ -80,8 +80,8 @@ class ManConverter:
 cur_time = max([cur_time, script_time])
 try:
 trg_time = int(os.stat(out_path).st_mtime)
-except EnvironmentError as e:
-if e.errno != errno.ENOENT:
+except EnvironmentError as exc:
+if exc.errno != errno.ENOENT:
 raise
 trg_time = None
 
@@ -103,7 +103,7 @@ class ManConverter:
 self.mtime = mtime
 self.replace_cmd = replace_cmd
 
-header_chars = headers if headers else ('=', '-', '~', '#', '*', '^')
+header_chars = headers or ('=', '-', '~', '#', '*', '^')
 self.header_char = header_chars[len(name.split(' ')) - 1]
 
 def run(self):
@@ -208,8 +208,8 @@ class ManConverter:
 path = os.path.join(self.base_path, cmd_path)
 try:
 os.makedirs(path)
-except OSError as e:
-if e.errno != errno.EEXIST:
+except OSError as exc:
+if exc.errno != errno.EEXIST:
 raise
 
 # strip the main command from the outputted name
@@ -223,7 +223,7 @@ class ManConverter:
 desc = getattr(parser, '_description', parser.description)
 desc = ' - ' + desc if desc else ''
 rst = _rst_header(self.header_char, f'{name}{desc}',
-  leading=main_command, capitalize=False)
+  leading=True, capitalize=False)
 
 cmd = cmd_parts[-1]
 for filename in ('synopsis', 'description', 'options', 'subcommands'):



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/dist/

2022-12-09 Thread Arthur Zamarin
commit: 1cfa96a28b3a21a7453cc89bc49f8dc143b08445
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Dec  9 11:47:29 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Dec  9 11:47:29 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=1cfa96a2

mark distutils_extensions as deprecated

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/dist/distutils_extensions.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/snakeoil/dist/distutils_extensions.py 
b/src/snakeoil/dist/distutils_extensions.py
index a5f6789e..10a77ed5 100644
--- a/src/snakeoil/dist/distutils_extensions.py
+++ b/src/snakeoil/dist/distutils_extensions.py
@@ -17,6 +17,7 @@ import shutil
 import subprocess
 import sys
 import textwrap
+import warnings
 from contextlib import ExitStack, contextmanager, redirect_stderr, 
redirect_stdout
 from multiprocessing import cpu_count
 
@@ -37,6 +38,8 @@ from ..contexts import syspath
 from ..version import get_git_version
 from .generate_docs import generate_html, generate_man
 
+warnings.warn("the distutils_extensions module is deprecated", 
DeprecationWarning, stacklevel=2)
+
 # forcibly disable lazy module loading
 os.environ['SNAKEOIL_DEMANDIMPORT'] = 'false'
 



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/, tests/

2022-12-09 Thread Arthur Zamarin
commit: b73feaf54fb73826bb6221dd10a02be61606bf24
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Dec  9 10:11:27 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Dec  9 11:38:39 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=b73feaf5

Add constraint satisfaction problem solver

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/constraints.py | 198 
 tests/test_constraints.py   |  62 ++
 2 files changed, 260 insertions(+)

diff --git a/src/snakeoil/constraints.py b/src/snakeoil/constraints.py
new file mode 100644
index ..63e46715
--- /dev/null
+++ b/src/snakeoil/constraints.py
@@ -0,0 +1,198 @@
+"""
+Facilities for solving constraint satisfaction problems.
+
+Usage examples:
+
+>>> def divides_by(x, y):
+>>> return x % y == 0
+>>>
+>>> p = Problem()
+>>> p.add_variable(range(2, 10), 'x', 'y', 'z')
+>>> p.add_constraint(divides_by, frozenset({'x', 'y'}))
+>>> p.add_constraint(lambda x, z: x > z, frozenset({'z', 'x'}))
+>>> p.add_constraint(lambda y, x, z: x+y+z > 0, frozenset({'z', 'x', 'y'}))
+>>> for solution in p:
+>>> print(f"x={solution['x']}, y={solution['y']}, z={solution['z']}")
+"""
+
+from collections import defaultdict
+from typing import Any, Iterable, Protocol
+
+
+class Constraint(Protocol):
+"""Type used for constraint satisfaction check.
+
+.. py:function:: __call__(**kwargs: Any) -> bool
+
+Check satisfaction of the constraint.
+
+:param kwargs: keyworded arguments, named after the variables passed to
+:py:func:`Problem.add_constraint`, with assigned value from the
+domain.
+:return: ``True`` if the assignment is satisfied.
+"""
+def __call__(self, **kwargs: Any) -> bool:
+raise NotImplementedError('Constraint', '__call__')
+
+
+class _Domain(list):
+def __init__(self, items: Iterable[Any]):
+super().__init__(items)
+self._hidden = []
+self._states = []
+
+def hide_value(self, value):
+super().remove(value)
+self._hidden.append(value)
+
+def push_state(self):
+self._states.append(len(self))
+
+def pop_state(self):
+if diff := self._states.pop() - len(self):
+self.extend(self._hidden[-diff:])
+del self._hidden[-diff:]
+
+
+class Problem:
+"""
+Class used to define a problem and retrieve solutions.
+
+Define a problem by calling :py:func:`add_variable` and then
+:py:func:`add_constraint`, and then iterate over the problem to
+retrieve solutions satisfying the problem.
+
+For building solutions for the problem, the back tracking algorithm
+is used. It is a deterministic algorithm, which means the same solution
+is built if the variables and constraints were identically built.
+
+:note: The class is mutable, so adding variables or constraints
+during iteration of solutions might break the solver.
+
+.. py:function:: __iter__() -> Iterator[dict[str, Any]]
+
+Retrieve solutions satisfying the problem. Each solution consists
+of a :py:class:`dict` assigning to each variable in the problem a
+single value from it's domain.
+"""
+def __init__(self):
+self.variables: dict[str, _Domain] = {}
+self.constraints: list[tuple[Constraint, frozenset[str]]] = []
+self.vconstraints: dict[str, list[tuple[Constraint, frozenset[str 
= defaultdict(list)
+
+def add_variable(self, domain: Iterable[Any], *variables: str):
+"""Add variables to the problem, which use the specified domain.
+
+:param domain: domain of possible values for the variables.
+:param variables: names of variables, to be used in assignment and
+checking the constraint satisfaction.
+:raises AssertionError: if the variable was already added previously
+to this problem.
+
+:Note: The solver prefers later values from the domain,
+meaning the first solutions will try to use the later values
+from each domain.
+"""
+for variable in variables:
+assert variable not in self.variables, f'variable {variable!r} was 
already added'
+self.variables[variable] = _Domain(domain)
+
+def add_constraint(self, constraint: Constraint, variables: 
frozenset[str]):
+"""Add constraint to the problem, which depends on the specified
+variables.
+
+:param constraint: Callable which accepts as keyworded args the
+variables, and returns True only if the assignment is satisfied.
+:param variables: names of variables, on which the constraint depends.
+Only those variables will be passed during check of constraint.
+:raises AssertionError: if the specified variables weren't added
+previously, so they have no domain.
+"""
+

[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/

2022-11-19 Thread Arthur Zamarin
commit: 0ea0ab6271538227f8ca8a1e545b16183e93d122
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Sat Nov 19 13:57:21 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Sat Nov 19 13:57:21 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=0ea0ab62

start work on 0.10.4

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/snakeoil/__init__.py b/src/snakeoil/__init__.py
index 1780dada..636d6636 100644
--- a/src/snakeoil/__init__.py
+++ b/src/snakeoil/__init__.py
@@ -11,4 +11,4 @@ This library is a bit of a grabbag of the following:
 """
 
 __title__ = 'snakeoil'
-__version__ = '0.10.3'
+__version__ = '0.10.4'



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: /, src/snakeoil/dist/

2022-11-14 Thread Arthur Zamarin
commit: 1bd48a467c3d42b9e27821853754d7d256a93537
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Fri Nov 11 18:49:34 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Fri Nov 11 18:49:34 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=1bd48a46

dist.sphinxext: new sphinx extension

Small sphinx extension to generate docs from argparse scripts.
Simplifies all `conf.py` across all pkgcore stack.

Signed-off-by: Arthur Zamarin  gentoo.org>

 .coveragerc   |   2 +-
 src/snakeoil/dist/distutils_extensions.py | 105 +-
 src/snakeoil/dist/generate_docs.py|  14 ++--
 src/snakeoil/dist/sphinxext.py|  80 +++
 src/snakeoil/dist/utilities.py|  44 +
 5 files changed, 133 insertions(+), 112 deletions(-)

diff --git a/.coveragerc b/.coveragerc
index 18303775..b24d5133 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -1,7 +1,7 @@
 [run]
 source = snakeoil
 branch = True
-omit = src/*, tests/*
+omit = src/*, tests/*, src/snakeoil/dist/*
 
 [paths]
 source = **/site-packages/snakeoil

diff --git a/src/snakeoil/dist/distutils_extensions.py 
b/src/snakeoil/dist/distutils_extensions.py
index f919826c..a5f6789e 100644
--- a/src/snakeoil/dist/distutils_extensions.py
+++ b/src/snakeoil/dist/distutils_extensions.py
@@ -18,7 +18,6 @@ import subprocess
 import sys
 import textwrap
 from contextlib import ExitStack, contextmanager, redirect_stderr, 
redirect_stdout
-from datetime import datetime
 from multiprocessing import cpu_count
 
 from setuptools import find_packages
@@ -120,38 +119,8 @@ def module_version(moduledir=MODULEDIR):
 
 Based on the assumption that a module defines __version__.
 """
-version = None
-try:
-with open(os.path.join(moduledir, '__init__.py'), encoding='utf-8') as 
f:
-version = re.search(
-r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
-f.read(), re.MULTILINE).group(1)
-except IOError as e:
-if e.errno == errno.ENOENT:
-pass
-else:
-raise
-
-if version is None:
-raise RuntimeError(f'Cannot find version for module: {MODULE_NAME}')
-
-# use versioning scheme similar to setuptools_scm for untagged versions
-git_version = get_git_version(REPODIR)
-if git_version:
-tag = git_version['tag']
-if tag is None:
-commits = git_version['commits']
-rev = git_version['rev'][:7]
-date = datetime.strptime(git_version['date'], '%a, %d %b %Y 
%H:%M:%S %z')
-date = datetime.strftime(date, '%Y%m%d')
-if commits is not None:
-version += f'.dev{commits}'
-version += f'+g{rev}.d{date}'
-elif tag != version:
-raise DistutilsError(
-f'unmatched git tag {tag!r} and {MODULE_NAME} version 
{version!r}')
-
-return version
+from .utilities import module_version
+return module_version(REPODIR, moduledir)
 
 
 def generate_verinfo(target_dir):
@@ -266,76 +235,6 @@ def data_mapping(host_prefix, path, skip=None):
if os.path.join(root, x) not in skip])
 
 
-def pkg_config(*packages, **kw):
-"""Translate pkg-config data to compatible Extension parameters.
-
-Example usage:
-
->>> from distutils.extension import Extension
->>> from pkgdist import pkg_config
->>>
->>> ext_kwargs = dict(
-... include_dirs=['include'],
-... extra_compile_args=['-std=c++11'],
-... )
->>> extensions = [
-... Extension('foo', ['foo.c']),
-... Extension('bar', ['bar.c'], **pkg_config('lcms2')),
-... Extension('ext', ['ext.cpp'], **pkg_config(('nss', 'libusb-1.0'), 
**ext_kwargs)),
-... ]
-"""
-flag_map = {
-'-I': 'include_dirs',
-'-L': 'library_dirs',
-'-l': 'libraries',
-}
-
-try:
-tokens = subprocess.check_output(
-['pkg-config', '--libs', '--cflags'] + list(packages)).split()
-except OSError as e:
-sys.stderr.write(f'running pkg-config failed: {e.strerror}\n')
-sys.exit(1)
-
-for token in tokens:
-token = token.decode()
-if token[:2] in flag_map:
-kw.setdefault(flag_map.get(token[:2]), []).append(token[2:])
-else:
-kw.setdefault('extra_compile_args', []).append(token)
-return kw
-
-
-def cython_pyx(path=MODULEDIR):
-"""Return all available cython extensions under a given path."""
-for root, _dirs, files in os.walk(path):
-for f in files:
-if f.endswith('.pyx'):
-yield str(os.path.join(root, f))
-
-
-def cython_exts(path=MODULEDIR, build_opts=None):
-"""Prepare all cython extensions under a given path to be built."""
-if build_opts is None:
-build_opts = {'depends': [], 'include_dirs': []}
-exts = []
-
-

[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/

2022-11-08 Thread Arthur Zamarin
commit: f3486bd93bb7c3faf0e9da7db360726ba019774a
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Tue Nov  8 19:39:11 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Tue Nov  8 19:39:29 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=f3486bd9

start work on 0.10.3

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/snakeoil/__init__.py b/src/snakeoil/__init__.py
index 4d322886..1780dada 100644
--- a/src/snakeoil/__init__.py
+++ b/src/snakeoil/__init__.py
@@ -11,4 +11,4 @@ This library is a bit of a grabbag of the following:
 """
 
 __title__ = 'snakeoil'
-__version__ = '0.10.2'
+__version__ = '0.10.3'



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/test/

2022-11-01 Thread Arthur Zamarin
commit: 935b06a704218d327474c6fa0f91517e578b3a7f
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Tue Nov  1 20:27:10 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Tue Nov  1 20:27:10 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=935b06a7

snakeoil/test/*.py: fix f-strings

Fixes: 7aed9341485ee53c0784df9e2982338e1ec271f2
Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/test/eq_hash_inheritance.py |  2 +-
 src/snakeoil/test/slot_shadowing.py  | 10 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/snakeoil/test/eq_hash_inheritance.py 
b/src/snakeoil/test/eq_hash_inheritance.py
index 9eb62e4c..5012f9d3 100644
--- a/src/snakeoil/test/eq_hash_inheritance.py
+++ b/src/snakeoil/test/eq_hash_inheritance.py
@@ -17,7 +17,7 @@ class Test(mixins.TargetedNamespaceWalker, 
mixins.KlassWalker):
 if getattr(cls, "__hash__intentionally_disabled__", False):
 return True
 
-namepath = "{cls.__module__}.{cls.__name__}"
+namepath = f"{cls.__module__}.{cls.__name__}"
 return not namepath.startswith(self.target_namespace)
 
 def run_check(self, cls):

diff --git a/src/snakeoil/test/slot_shadowing.py 
b/src/snakeoil/test/slot_shadowing.py
index bad525c3..3e260c2e 100644
--- a/src/snakeoil/test/slot_shadowing.py
+++ b/src/snakeoil/test/slot_shadowing.py
@@ -56,7 +56,7 @@ class SlotShadowing(mixins.TargetedNamespaceWalker, 
mixins.SubclassWalker):
 if isinstance(slots, str):
 if self.err_if_slots_is_str:
 pytest.fail(
-"cls {kls!r}; slots is {slots!r} (should be a tuple or 
list)")
+f"cls {kls!r}; slots is {slots!r} (should be a tuple or 
list)")
 slots = (slots,)
 
 if slots is None:
@@ -65,7 +65,7 @@ class SlotShadowing(mixins.TargetedNamespaceWalker, 
mixins.SubclassWalker):
 if not isinstance(slots, tuple):
 if self.err_if_slots_is_mutable:
 pytest.fail(
-"cls {kls!r}; slots is {slots!r}- - should be a tuple")
+f"cls {kls!r}; slots is {slots!r}- - should be a tuple")
 slots = tuple(slots)
 
 if slots is None or (slots and slots in raw_slottings):
@@ -73,10 +73,10 @@ class SlotShadowing(mixins.TargetedNamespaceWalker, 
mixins.SubclassWalker):
 # this means that the child either didn't define __slots__, or
 # daftly copied the parents... thus defeating the purpose.
 pytest.fail(
-"cls {kls!r}; slots is {slots!r}, seemingly inherited from "
-"{raw_slottings[slots]!r}; the derivative class should be 
__slots__ = ()")
+f"cls {kls!r}; slots is {slots!r}, seemingly inherited from "
+f"{raw_slottings[slots]!r}; the derivative class should be 
__slots__ = ()")
 
 for slot in slots:
 if slot in slotting:
 pytest.fail(
-"cls {kls!r}; slot {slot!r} was already defined at 
{slotting[slot]!r}")
+f"cls {kls!r}; slot {slot!r} was already defined at 
{slotting[slot]!r}")



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/test/

2022-11-01 Thread Arthur Zamarin
commit: 1aa7174e22c900ed829ef9e792bfd970638f729d
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Tue Nov  1 20:20:58 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Tue Nov  1 20:20:58 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=1aa7174e

snakeoil.test.eq_hash_inheritance: fix pytest warning

Usage of `setup` function is deprecated by pytest (was added as
compatibility layer for nose). Fix the warning by using correct name -
`setup_method`.

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/test/eq_hash_inheritance.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/snakeoil/test/eq_hash_inheritance.py 
b/src/snakeoil/test/eq_hash_inheritance.py
index 96cedb53..9eb62e4c 100644
--- a/src/snakeoil/test/eq_hash_inheritance.py
+++ b/src/snakeoil/test/eq_hash_inheritance.py
@@ -7,7 +7,7 @@ class Test(mixins.TargetedNamespaceWalker, mixins.KlassWalker):
 
 singleton = object()
 
-def setup(self):
+def setup_method(self):
 self._ignore_set = frozenset(self.iter_builtin_targets())
 
 def _should_ignore(self, cls):



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/compression/

2022-10-10 Thread Arthur Zamarin
commit: 135e855953fe7a648d0fd794909445093086bd64
Author: Sam James  gentoo  org>
AuthorDate: Sun Sep 25 00:20:54 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Mon Oct 10 16:48:52 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=135e8559

compression: tidy up bzip2 docs

Signed-off-by: Sam James  gentoo.org>
Closes: https://github.com/pkgcore/snakeoil/pull/84
Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/compression/_bzip2.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/snakeoil/compression/_bzip2.py 
b/src/snakeoil/compression/_bzip2.py
index b10e3ec3..1a38922c 100644
--- a/src/snakeoil/compression/_bzip2.py
+++ b/src/snakeoil/compression/_bzip2.py
@@ -1,11 +1,11 @@
 """
 bzip2 decompression/compression
 
-where possible, this module defers to cpython bz2 module- if it's not 
available,
-it results to executing bzip2 with tempfile arguments to do decompression
+Where possible, this module defers to cpython's bz2 module - if it's not 
available,
+it defers to executing bzip2 with tempfile arguments to do decompression
 and compression.
 
-Should use this module unless its absolutely critical that bz2 module be used
+Use this module unless it's absolutely critical that the bz2 module is used.
 """
 
 __all__ = ("compress_data", "decompress_data")



[gentoo-commits] proj/pkgcore/snakeoil:master commit in: src/snakeoil/compression/, tests/compression/

2022-10-10 Thread Arthur Zamarin
commit: 7c1d50adc0f82f6fc19f857930eb70c2ba7a84f2
Author: Arthur Zamarin  gentoo  org>
AuthorDate: Mon Oct 10 12:42:26 2022 +
Commit: Arthur Zamarin  gentoo  org>
CommitDate: Mon Oct 10 15:55:00 2022 +
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=7c1d50ad

compression.__init__: add tests

Signed-off-by: Arthur Zamarin  gentoo.org>

 src/snakeoil/compression/__init__.py | 27 ---
 src/snakeoil/compression/_util.py| 24 +-
 tests/compression/__init__.py| 11 +
 tests/compression/test_bzip2.py  | 10 +---
 tests/compression/test_init.py   | 88 
 5 files changed, 121 insertions(+), 39 deletions(-)

diff --git a/src/snakeoil/compression/__init__.py 
b/src/snakeoil/compression/__init__.py
index b250b1af..4b4a437c 100644
--- a/src/snakeoil/compression/__init__.py
+++ b/src/snakeoil/compression/__init__.py
@@ -1,9 +1,9 @@
 import shlex
+from functools import cached_property
 from importlib import import_module
 
-from .. import klass
+from .. import process
 from ..cli.exceptions import UserException
-from ..process import CommandNotFound, find_binary
 from ..process.spawn import spawn_get_output
 
 
@@ -12,14 +12,10 @@ class _transform_source:
 def __init__(self, name):
 self.name = name
 
-@klass.jit_attr
+@cached_property
 def module(self):
 return import_module(f'snakeoil.compression._{self.name}')
 
-@klass.jit_attr
-def parallelizable(self):
-return bool(getattr(self.module, 'parallelizable', False))
-
 def compress_data(self, data, level, parallelize=False):
 parallelize = parallelize and self.module.parallelizable
 return self.module.compress_data(data, level, parallelize=parallelize)
@@ -81,7 +77,7 @@ class ArComp:
 def __init_subclass__(cls, **kwargs):
 """Initialize result subclasses and register archive extensions."""
 super().__init_subclass__(**kwargs)
-if not all((cls.binary, cls.default_unpack_cmd, cls.exts)):
+if not all((cls.binary, cls.default_unpack_cmd, cls.exts)): # pragma: 
no cover
 raise ValueError(f'class missing required attrs: {cls!r}')
 for ext in cls.exts:
 cls.known_exts[ext] = cls
@@ -89,13 +85,13 @@ class ArComp:
 def __init__(self, path, ext=None):
 self.path = path
 
-@klass.jit_attr
+@cached_property
 def _unpack_cmd(self):
 for b in self.binary:
 try:
-binary = find_binary(b)
+binary = process.find_binary(b)
 break
-except CommandNotFound:
+except process.CommandNotFound:
 continue
 else:
 choices = ', '.join(self.binary)
@@ -107,9 +103,6 @@ class ArComp:
 def unpack(self, dest=None, **kwargs):
 raise NotImplementedError
 
-def create(self, dest):
-raise NotImplementedError
-
 
 class _Archive:
 """Generic archive format support."""
@@ -155,16 +148,16 @@ class _Tar(_Archive, ArComp):
 compress_binary = None
 default_unpack_cmd = '{binary} xf "{path}"'
 
-@klass.jit_attr
+@cached_property
 def _unpack_cmd(self):
 cmd = super()._unpack_cmd
 if self.compress_binary is not None:
 for b in self.compress_binary:
 try:
-find_binary(b)
+process.find_binary(b)
 cmd += f' --use-compress-program={b}'
 break
-except CommandNotFound:
+except process.CommandNotFound:
 pass
 else:
 choices = ', '.join(self.compress_binary)

diff --git a/src/snakeoil/compression/_util.py 
b/src/snakeoil/compression/_util.py
index 6a3c7258..e1af5aef 100644
--- a/src/snakeoil/compression/_util.py
+++ b/src/snakeoil/compression/_util.py
@@ -22,7 +22,7 @@ def _drive_process(args, mode, data):
 
 
 def compress_data(binary, data, compresslevel=9, extra_args=()):
-args = [binary, '-%ic' % compresslevel]
+args = [binary, f'-{compresslevel}c']
 args.extend(extra_args)
 return _drive_process(args, 'compression', data)
 
@@ -36,9 +36,7 @@ def decompress_data(binary, data, extra_args=()):
 class _process_handle:
 
 def __init__(self, handle, args, is_read=False):
-self.mode = 'wb'
-if is_read:
-self.mode = 'rb'
+self.mode = 'rb' if is_read else 'wb'
 
 self.args = tuple(args)
 self.is_read = is_read
@@ -55,8 +53,7 @@ class _process_handle:
 elif not isinstance(handle, int):
 if not hasattr(handle, 'fileno'):
 raise TypeError(
-"handle %r isn't a string, integer, and lacks a fileno "
-"method" % (handle,))
+f"handle {handle!r} isn't a string, integer, and lacks a 
fileno method")
 handle =