[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/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/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/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 = []
-
-