You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2025/11/07 18:01:22 UTC
(allura) 01/04: rely on defopt package
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch db/explore_encryption
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 13d5c856dab4e17205892d1433d1926e06f37d16
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Thu Nov 6 15:59:46 2025 -0500
rely on defopt package
---
Allura/allura/scripts/scripttask.py | 74 ++++++++++++++++++-------------------
requirements.in | 1 +
requirements.txt | 10 +++++
3 files changed, 46 insertions(+), 39 deletions(-)
diff --git a/Allura/allura/scripts/scripttask.py b/Allura/allura/scripts/scripttask.py
index 0c9d339ac..61e7f02b0 100644
--- a/Allura/allura/scripts/scripttask.py
+++ b/Allura/allura/scripts/scripttask.py
@@ -63,6 +63,8 @@ def execute(cls, *, limit: int = 10, dry_run: bool = False):
import io
import logging
+import defopt
+
from allura.lib.decorators import task
from allura.lib.helpers import shlex_split
@@ -113,48 +115,42 @@ def main(cls):
cls.execute(options)
-try:
- import defopt
-except ModuleNotFoundError:
- pass
-else:
-
- class MetaDefOpt(type):
- def __new__(meta, classname, bases, classDict):
- return task(type.__new__(meta, classname, bases, classDict))
+class MetaDefOpt(type):
+ def __new__(meta, classname, bases, classDict):
+ return task(type.__new__(meta, classname, bases, classDict))
- @property
- def __doc__(cls):
- with contextlib.redirect_stdout(io.StringIO()) as stderr:
- try:
- cls.main(argv=['--help'])
- except SystemExit:
- pass
- return stderr.getvalue()
+ @property
+ def __doc__(cls):
+ with contextlib.redirect_stdout(io.StringIO()) as stderr:
+ try:
+ cls.main(argv=['--help'])
+ except SystemExit:
+ pass
+ return stderr.getvalue()
- class DefOptScriptTask(metaclass=MetaDefOpt):
- """Base class for a command-line script that is also executable as a task."""
+class DefOptScriptTask(metaclass=MetaDefOpt):
+ """Base class for a command-line script that is also executable as a task."""
- def __new__(cls, arg_string=''):
- # when taskd calls SomeTaskClass(), then this runs. Not really the normal way to use __new__
- # and can't use __init__ since we want to return a value
- return cls._execute_task(arg_string)
+ def __new__(cls, arg_string=''):
+ # when taskd calls SomeTaskClass(), then this runs. Not really the normal way to use __new__
+ # and can't use __init__ since we want to return a value
+ return cls._execute_task(arg_string)
- @classmethod
- def _execute_task(cls, arg_string):
- try:
- return cls.main(argv=shlex_split(arg_string or ''))
- except SystemExit:
- raise Exception("Error parsing args: '%s'" % arg_string)
+ @classmethod
+ def _execute_task(cls, arg_string):
+ try:
+ return cls.main(argv=shlex_split(arg_string or ''))
+ except SystemExit:
+ raise Exception("Error parsing args: '%s'" % arg_string)
- @classmethod
- def main(cls, **extra_kwargs):
- defopt_params = dict(
- no_negated_flags=True,
- ) | extra_kwargs
- return defopt.run(cls.execute, **defopt_params)
+ @classmethod
+ def main(cls, **extra_kwargs):
+ defopt_params = dict(
+ no_negated_flags=True,
+ ) | extra_kwargs
+ return defopt.run(cls.execute, **defopt_params)
- @classmethod
- def execute(cls, *args, **kwargs):
- """User code goes here, using defopt kwargs with type annotations"""
- raise NotImplementedError
+ @classmethod
+ def execute(cls, *args, **kwargs):
+ """User code goes here, using defopt kwargs with type annotations"""
+ raise NotImplementedError
diff --git a/requirements.in b/requirements.in
index 0b48ae4be..44b5786c0 100644
--- a/requirements.in
+++ b/requirements.in
@@ -6,6 +6,7 @@ beaker-session-jwt
colander
cryptography
decorator
+defopt
EasyWidgets
emoji
faust-cchardet
diff --git a/requirements.txt b/requirements.txt
index 575a767d1..d38a4869e 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -47,6 +47,7 @@ colander==1.8.3
# via -r requirements.in
colorama==0.4.6 ; sys_platform == 'win32'
# via
+ # defopt
# pytest
# qrcode
crank==0.8.1
@@ -60,6 +61,8 @@ cryptography==46.0.2
# pymongocrypt
decorator==5.2.1
# via -r requirements.in
+defopt==7.0.0
+ # via -r requirements.in
diff-match-patch==20230430
# via sxsdiff
distlib==0.4.0
@@ -69,6 +72,7 @@ dnspython==2.8.0
docutils==0.22.2
# via
# -r requirements.in
+ # defopt
# pypeline
easywidgets==0.4.3
# via -r requirements.in
@@ -190,6 +194,8 @@ platformdirs==4.5.0
# via virtualenv
pluggy==1.6.0
# via pytest
+pockets==0.9.1
+ # via sphinxcontrib-napoleon
pre-commit==4.3.0
# via -r requirements.in
profanityfilter==2.1.0
@@ -273,7 +279,9 @@ six==1.17.0
# creoleparser
# genshi
# html5lib
+ # pockets
# python-dateutil
+ # sphinxcontrib-napoleon
# sxsdiff
# webhelpers2
smmap==5.0.2
@@ -284,6 +292,8 @@ sniffio==1.3.1
# httpx
soupsieve==2.8
# via beautifulsoup4
+sphinxcontrib-napoleon==0.7
+ # via defopt
sxsdiff==0.3.0
# via -r requirements.in
termcolor==3.1.0