Skip to content

Commit

Permalink
Merge pull request #117 from hugovk/update-versions
Browse files Browse the repository at this point in the history
Update Python versions
  • Loading branch information
bw2 authored Oct 8, 2019
2 parents 726ac12 + 58e5b7f commit 527ebb6
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 169 deletions.
7 changes: 0 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ matrix:
language: python
- python: 3.4
language: python
- python: 3.3
language: python
- python: 3.2
language: python
- python: 2.7
language: python
- python: 2.6
language: python
- python: pypy
language: python
- python: pypy3
Expand All @@ -31,5 +26,3 @@ install: pip install mock
# command to run tests:
script: python setup.py test

# migrate to container-based travis.ci: http://docs.travis-ci.com/user/migrating-from-legacy
sudo: false
27 changes: 21 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
ConfigArgParse
--------------

.. image:: https://img.shields.io/pypi/v/ConfigArgParse.svg?style=flat
:alt: PyPI version
:target: https://pypi.python.org/pypi/ConfigArgParse

.. image:: https://img.shields.io/pypi/pyversions/ConfigArgParse.svg
:alt: Supported Python versions
:target: https://pypi.python.org/pypi/ConfigArgParse

.. image:: https://travis-ci.org/bw2/ConfigArgParse.svg?branch=master
:alt: Travis CI build
:target: https://travis-ci.org/bw2/ConfigArgParse

Overview
~~~~~~~~

Expand Down Expand Up @@ -37,7 +52,7 @@ Features
- extensible (:code:`ConfigFileParser` can be subclassed to define a new
config file format)
- unittested by running the unittests that came with argparse but on
configargparse, and using tox to test with python2.7+ and python3+
configargparse, and using tox to test with Python 2.7 and Python 3+

Example
~~~~~~~
Expand Down Expand Up @@ -263,7 +278,7 @@ argparse in all usecases.

Previously existing modules (PyPI search keywords: config argparse):

- argparse (built-in module python v2.7+ )
- argparse (built-in module Python v2.7+)

- Good:

Expand Down Expand Up @@ -294,7 +309,7 @@ Previously existing modules (PyPI search keywords: config argparse):
"choices" are not handled as expected. For example, if you
specify a required value in a config file, you still have to
specify it again on the command line.
- doesn't work with python 3 yet
- doesn't work with Python 3 yet
- no unit tests, code not well documented

- appsettings v0.5 (https://pypi.python.org/pypi/appsettings)
Expand All @@ -309,7 +324,7 @@ Previously existing modules (PyPI search keywords: config argparse):

- passes in config file and env settings via parse_args
namespace param
- tests not finished and don't work with python3 (import
- tests not finished and don't work with Python 3 (import
StringIO)

- argparse_config v0.5.1
Expand All @@ -321,7 +336,7 @@ Previously existing modules (PyPI search keywords: config argparse):

- Bad:

- doesn't work with python3 (error during pip install)
- doesn't work with Python 3 (error during pip install)

- yconf v0.3.2 - (https://pypi.python.org/pypi/yconf) - features
and interface not that great
Expand All @@ -338,7 +353,7 @@ Previously existing modules (PyPI search keywords: config argparse):

- Bad:

- doesn't work with python3
- doesn't work with Python 3
- 2+ years since last release to PyPI
- apparently unmaintained

Expand Down
28 changes: 12 additions & 16 deletions configargparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
import re
import sys
import types
from collections import OrderedDict

if sys.version_info >= (3, 0):
from io import StringIO
else:
from StringIO import StringIO

if sys.version_info < (2, 7):
from ordereddict import OrderedDict
else:
from collections import OrderedDict


ACTION_TYPES_THAT_DONT_NEED_A_VALUE = (argparse._StoreTrueAction,
argparse._StoreFalseAction, argparse._CountAction,
Expand Down Expand Up @@ -152,8 +148,8 @@ def parse(self, stream):
if not line or line[0] in ["#", ";", "["] or line.startswith("---"):
continue
white_space = "\\s*"
key = "(?P<key>[^:=;#\s]+?)"
value = white_space+"[:=\s]"+white_space+"(?P<value>.+?)"
key = r"(?P<key>[^:=;#\s]+?)"
value = white_space+r"[:=\s]"+white_space+"(?P<value>.+?)"
comment = white_space+"(?P<comment>\\s[;#].*)?"

key_only_match = re.match("^" + key + comment + "$", line)
Expand All @@ -174,7 +170,7 @@ def parse(self, stream):
items[key] = value
continue

raise ConfigFileParserException("Unexpected line %s in %s: %s" % (i,
raise ConfigFileParserException("Unexpected line {} in {}: {}".format(i,
getattr(stream, 'name', 'stream'), line))
return items

Expand All @@ -187,7 +183,7 @@ def serialize(self, items):
if isinstance(value, list):
# handle special case of lists
value = "["+", ".join(map(str, value))+"]"
r.write("%s = %s\n" % (key, value))
r.write("{} = {}\n".format(key, value))
return r.getvalue()


Expand Down Expand Up @@ -402,7 +398,7 @@ def parse_known_args(self, args = None, namespace = None,
args = list(args)

# normalize args by converting args like --key=value to --key value
normalized_args = list()
normalized_args = []
for arg in args:
if arg and arg[0] in self.prefix_chars and '=' in arg:
key, value = arg.split('=', 1)
Expand Down Expand Up @@ -472,8 +468,8 @@ def parse_known_args(self, args = None, namespace = None,
"-h" in args or "--help" in args)

# prepare for reading config file(s)
known_config_keys = dict((config_key, action) for action in self._actions
for config_key in self.get_possible_config_keys(action))
known_config_keys = {config_key: action for action in self._actions
for config_key in self.get_possible_config_keys(action)}

# open the config file(s)
config_streams = []
Expand Down Expand Up @@ -571,7 +567,7 @@ def write_config_file(self, parsed_namespace, output_file_paths, exit_after=Fals
with open(output_file_path, "w") as output_file:
pass
except IOError as e:
raise ValueError("Couldn't open %s for writing: %s" % (
raise ValueError("Couldn't open {} for writing: {}".format(
output_file_path, e))
if output_file_paths:
# generate the config file contents
Expand Down Expand Up @@ -693,7 +689,7 @@ def convert_item_to_command_line_arg(self, action, key, value):
args.append( command_line_key )
args.append( value )
else:
raise ValueError("Unexpected value type %s for value: %s" % (
raise ValueError("Unexpected value type {} for value: {}".format(
type(value), value))

return args
Expand All @@ -710,7 +706,7 @@ def get_possible_config_keys(self, action):
return keys

for arg in action.option_strings:
if any([arg.startswith(2*c) for c in self.prefix_chars]):
if any(arg.startswith(2*c) for c in self.prefix_chars):
keys += [arg[2:], arg] # eg. for '--bla' return ['bla', '--bla']

return keys
Expand Down Expand Up @@ -789,7 +785,7 @@ def format_values(self):
r.write(source)
for key, (action, value) in settings.items():
if key:
r.write(" %-19s%s\n" % (key+":", value))
r.write(" {:<19}{}\n".format(key+":", value))
else:
if isinstance(value, str):
r.write(" %s\n" % value)
Expand Down
15 changes: 3 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def launch_http_server(directory):
logging.debug("Can't use port %d: %s" % (port, e.strerror))
continue

print("HTML coverage report now available at http://%s%s" % (
print("HTML coverage report now available at http://{}{}".format(
socket.gethostname(), (":%s" % port) if port != 80 else ""))

os.chdir(directory)
Expand Down Expand Up @@ -72,14 +72,6 @@ def launch_http_server(directory):
tests_require = [
'PyYAML',
]
if sys.version_info < (2, 7):
install_requires.extend([
'argparse',
'ordereddict',
])
tests_require.extend([
'unittest2',
])


setup(
Expand All @@ -102,17 +94,16 @@ def launch_http_server(directory):
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
"Programming Language :: Python :: 2",
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
test_suite='tests',
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
install_requires=install_requires,
tests_require=tests_require,
extras_require = {
Expand Down
Loading

0 comments on commit 527ebb6

Please sign in to comment.