Skip to content

Commit

Permalink
Cleanup for v.0.27 (#159)
Browse files Browse the repository at this point in the history
* test: drop outdated test stub
* test: fix py27 deps (broken by #154)

This is a temporary workaround for this specific version of Argh.
Since v.0.28 the support for Python 2.x will be dropped and we'll
revert this commit there.

* docs: updated changelog
* docs: remove example of to-be-deprecated API

It was a poor design decision to misuse annotations for arg help.
We'll replace it with proper typing support in later versions.

* chore: bump version

* chore: update supported Python versions everywhere

Documentation, trove classifiers, tests (tox, CI).

* chore: declare support for Python 3.11
* refactor: minor changes for readability
  • Loading branch information
neithere committed Feb 8, 2023
1 parent 4d1dbc9 commit d46c67c
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', 'pypy-3.7']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.7']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
15 changes: 12 additions & 3 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
Changelog
~~~~~~~~~

Version 0.26.3-dev
------------------
Version 0.27.0
--------------

This is the last version to support Python 2.7.

Backward incompatible changes:

Expand All @@ -20,10 +22,17 @@ Fixed bugs:
- When command function signature contained ``**kwargs`` *and* positionals
without defaults and with underscores in their names, a weird behaviour could
be observed (issue #104).
- Fixed introspection through decorators (issue #111).
- Switched to Python's built-in `unittest.mock` (PR #154).
- Fixed bug with `skip_unknown_args=True` (PR #134).
- Fixed tests for Python 3.9.7+ (issue #148).

Other changes:

- Include the license files in manifest (PR #112).
- Included the license files in manifest (PR #112).
- Extended the list of similar projects (PR #87).
- Fixed typos and links in documentation (PR #110, #116, #156).
- Switched CI to Github Actions (PR #153).

Version 0.26.2
--------------
Expand Down
2 changes: 1 addition & 1 deletion argh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
from .helpers import *


__version__ = '0.26.3-dev'
__version__ = '0.27.0'
7 changes: 1 addition & 6 deletions argh/assembling.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def _get_args_from_signature(function):
flags = [] # name_or_flags
akwargs = {} # keyword arguments for add_argument()

# XXX DEPRECATION WARNING: this will be removed after v.0.28
if name in annotations:
# help message: func(a : "b") -> add_argument("a", help="b")
akwargs.update(help=annotations.get(name))
Expand Down Expand Up @@ -192,12 +193,6 @@ def set_default_command(parser, function):
If `parser.description` is empty and the function has a docstring,
it is used as the description.
.. note::
An attempt to set default command to a parser which already has
subparsers (e.g. added with :func:`~argh.assembling.add_commands`)
results in a `AssemblingError`.
.. note::
If there are both explicitly declared arguments (e.g. via
Expand Down
4 changes: 2 additions & 2 deletions argh/dispatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class ArghNamespace(argparse.Namespace):
:attr:`~argh.constants.DEST_FUNCTION` arguments passed to it via
parser's defaults).
"""
def __init__(self, *args, **kw):
super(ArghNamespace, self).__init__(*args, **kw)
def __init__(self, *args, **kwargs):
super(ArghNamespace, self).__init__(*args, **kwargs)
self._functions_stack = []

def __setattr__(self, k, v):
Expand Down
13 changes: 8 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ Dependencies
The `argh` library is supported (and tested unless otherwise specified) on
the following versions of Python:

* 2.7 (including PyPy 1.8)
* 3.1 (`argparse` library is required; **not** tested)
* 3.4
* 3.5
* 2.7
* 3.7
* 3.8
* 3.9
* 3.10
* 3.11
* PyPy 7.3.1+ (2.7, 3.6)

.. versionchanged:: 0.15
Added support for Python 3.x, dropped support for Python ≤ 2.5.
Expand All @@ -22,7 +25,7 @@ the following versions of Python:
Argh may perfectly work under 3.3, I'm just not testing it.

.. versionchanged:: 0.27
Added support for Python 3.5, dropped support for Python 2.6 and 3.2.
Added support for Python 3.7, dropped support for Python 2.6 and 3.2.

Why this one?
-------------
Expand Down
19 changes: 2 additions & 17 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,8 @@ The function's docstring is automatically included in the help message.
When the script is called as ``./app.py my-command --help``, the docstring
is displayed along with a short overview of the arguments.

However, in many cases it's a good idea do add extra documentation per argument.

In Python 3 it's easy:

.. code-block:: python
def load(path : 'file to load', format : 'json or yaml' = 'yaml'):
"Loads given file as YAML (unless other format is specified)"
return loaders[format].load(path)
Python 2 does not support annotations so the above example would raise a
`SyntaxError`. You would need to add help via `argparse` API::

parser.add_argument('path', help='file to load')

...which is far from DRY and very impractical if the functions are dispatched
in a different place. This is when extended declarations become useful.
In many cases it's a good idea do add extra documentation per argument.
Extended argument declaration can be helpful in that case.

Extended Argument Declaration
.............................
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ def run_tests(self):
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'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 :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: User Interfaces',
Expand Down
36 changes: 24 additions & 12 deletions test/test_assembling.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
import sys
import unittest.mock as mock
try:
import unittest.mock as mock
except ImportError:
# FIXME: remove in v.0.28
import mock
import pytest

import argh
Expand Down Expand Up @@ -124,32 +128,40 @@ def test_add_subparsers_when_default_command_exists__supported():

def one(): return 1
def two(): return 2
def three(): return 3

p = argh.ArghParser()
p.set_default_command(one)
p.add_commands([two])
p.add_commands([two, three])

ns_one = p.parse_args([])
ns_two = p.parse_args(['two'])
ns_default = p.parse_args([])

assert ns_one.get_function() == one
assert ns_two.get_function() == two
ns_explicit_two = p.parse_args(['two'])
ns_explicit_three = p.parse_args(['three'])

assert ns_default.get_function() == one
assert ns_explicit_two.get_function() == two
assert ns_explicit_three.get_function() == three


@pytest.mark.skipif(sys.version_info < (3,4), reason='supported since Python 3.4')
def test_set_default_command_when_subparsers_exist__supported():
def one(): return 1
def two(): return 2
def three(): return 3

p = argh.ArghParser()
p.add_commands([one])
p.set_default_command(two)
p.add_commands([one, two])
p.set_default_command(three)

ns_default = p.parse_args([])
ns_explicit_one = p.parse_args(['one'])
ns_explicit_two = p.parse_args(['two'])

ns_two = p.parse_args([])
ns_one = p.parse_args(['one'])

assert ns_one.get_function() == one
assert ns_two.get_function() == two
assert ns_explicit_one.get_function() == one
assert ns_explicit_two.get_function() == two
assert ns_default.get_function() == three


def test_set_default_command_mixed_arg_types():
Expand Down
6 changes: 5 additions & 1 deletion test/test_dispatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
~~~~~~~~~~~~~~~~~
"""
import argh
from unittest.mock import Mock, patch
try:
from unittest.mock import Mock, patch
except ImportError:
# FIXME: remove in v.0.28
from mock import Mock, patch
import pytest

from .base import make_IO
Expand Down
6 changes: 5 additions & 1 deletion test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
import argparse

import iocapture
import unittest.mock as mock
try:
import unittest.mock as mock
except ImportError:
# FIXME: remove in v.0.28
import mock
import pytest

import argh
Expand Down
6 changes: 5 additions & 1 deletion test/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
~~~~~~~~~~~~~~~~~
"""
import sys
import unittest.mock as mock
try:
import unittest.mock as mock
except ImportError:
# FIXME: remove in v.0.28
import mock

import argh

Expand Down
14 changes: 12 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
[tox]
envlist=py37,py38,pypy
envlist = py27, py37, py38, py39, py310, py311, pypy, pypy3

[testenv]
deps=
-rreqs-dev.txt
commands=
py.test []
pytest []

[testenv:py27,pypy]
deps=
-rreqs-dev.txt
mock

[testenv:pypy]
deps=
-rreqs-dev.txt
mock

[testenv:tdd]
# Special case for active development phase.
Expand Down

0 comments on commit d46c67c

Please sign in to comment.