Skip to content

Commit

Permalink
Merge branch 'release/v1.9.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantomas42 committed Nov 8, 2016
2 parents 87e3566 + 2a99fdd commit 0776c07
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 122 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
@@ -1,15 +1,14 @@
language: python
python:
- 2.7
- 3.2
- 3.3
- 3.4
install:
- pip install -U setuptools
- python bootstrap.py
- ./bin/buildout
before_script:
- ./bin/flake8 bvc
- ./bin/flake8 --application-import-names bvc bvc/
script:
- ./bin/cover
after_success:
Expand Down
10 changes: 6 additions & 4 deletions README.rst
Expand Up @@ -42,7 +42,7 @@ Options

usage: check-buildout-updates [-h] [--pre] [-s SPECIFIERS] [-i INCLUDES]
[-e EXCLUDES] [-w] [--indent INDENTATION]
[--sorting {alpha,length}]
[--sorting {alpha,ascii,length}]
[--service-url SERVICE_URL] [--timeout TIMEOUT]
[-t THREADS] [-v] [-q]
[source]
Expand Down Expand Up @@ -74,8 +74,9 @@ Options

File:
-w, --write Write the updates in the source file
--indent INDENTATION Spaces used when indenting "key = value" (default: 32)
--sorting {alpha,length}
--indent INDENTATION Spaces used when indenting "key = value" (default:
auto)
--sorting {alpha,ascii,length}
Sorting algorithm used on the keys when writing source
file (default: None)

Expand Down Expand Up @@ -114,13 +115,14 @@ Python compatibility
--------------------

Buildout-versions-checker has been originally developed for Python 2.7, but
has been ported and tested for Python 3.2, 3.3 and 3.4.
has been ported and tested for Python 3.3 and 3.4.

Requirements
------------

* six >= 1.4.1
* futures >= 3.0.2
* packaging >= 16

Extras
------
Expand Down
27 changes: 17 additions & 10 deletions buildout.cfg
Expand Up @@ -46,28 +46,35 @@ eggs = nose

[flake8]
eggs = flake8
flake8-import-order
pep8-naming
recipe = zc.recipe.egg

[coveralls]
eggs = python-coveralls
recipe = zc.recipe.egg

[versions]
PyYAML = 3.11
PyYAML = 3.12
blessings = 1.6
configparser = 3.5.0
coverage = 4.0.3
flake8 = 2.5.1
futures = 3.0.3
mccabe = 0.3.1
enum34 = 1.1.6
flake8 = 3.0.4
flake8-import-order = 0.9.2
futures = 3.0.5
mccabe = 0.5.2
nose = 1.3.7
nose-progressive = 1.5.1
packaging = 15.3
packaging = 16.7
pbp.recipe.noserunner = 0.2.6
pep8 = 1.5.7
pyflakes = 1.0.0
python-coveralls = 2.6.0
requests = 2.9.1
pep8-naming = 0.4.1
pycodestyle = 2.0.0
pyflakes = 1.2.3
pyparsing = 2.1.10
python-coveralls = 2.9.0
requests = 2.11.1
sh = 1.11
six = 1.10.0
zc.buildout = 2.5.0
zc.buildout = 2.5.3
zc.recipe.egg = 2.0.3
12 changes: 6 additions & 6 deletions bvc/checker.py
@@ -1,24 +1,24 @@
"""Version checker for Buildout Versions Checker"""
import os
import json
import os
import socket

from concurrent import futures
from collections import OrderedDict
from concurrent import futures
try:
from urllib2 import urlopen
from urllib2 import URLError
from ConfigParser import NoSectionError
from urllib2 import URLError
from urllib2 import urlopen
except ImportError: # Python 3
from configparser import NoSectionError
from urllib.error import URLError
from urllib.request import urlopen
from configparser import NoSectionError

from packaging.specifiers import SpecifierSet
from packaging.version import parse as parse_version

from bvc.logger import logger
from bvc.configparser import VersionsConfigParser
from bvc.logger import logger


class VersionsChecker(object):
Expand Down
42 changes: 35 additions & 7 deletions bvc/configparser.py
@@ -1,11 +1,14 @@
"""Config parser for Buildout Versions Checker"""
import re
from operator import itemgetter

from itertools import chain
try:
from ConfigParser import RawConfigParser
except ImportError: # Python 3
from configparser import RawConfigParser

from bvc.indentation import perfect_indentation

OPERATORS = re.compile(r'[+-]$')


Expand All @@ -16,8 +19,16 @@ class VersionsConfigParser(RawConfigParser):
"""
optionxform = str

def __init__(self, *args, **kwargs):
self.sorting = kwargs.pop('sorting', None)
self.indentation = kwargs.pop('indentation', -1)
RawConfigParser.__init__(self, *args, **kwargs)

def ascii_sorter(self, items):
return sorted(items, key=lambda x: x[0])

def alpha_sorter(self, items):
return sorted(items, key=itemgetter(0))
return sorted(items, key=lambda x: x[0].lower())

def length_sorter(self, items):
return sorted(self.alpha_sorter(items),
Expand Down Expand Up @@ -52,21 +63,38 @@ def write_section(self, fd, section, indentation, sorting):
else:
key = '{key:<{indent}}{operator}'.format(
key=key, operator=operator,
indent=indentation - int(bool(operator)))
indent=max(indentation - int(bool(operator)), 0))
value = value.replace('\n', '{:<{indent}}'.format(
'\n', indent=indentation + 3))
string_section += '{key}= {value}\n'.format(key=key, value=value)
string_section += '{key}{operator:<{indent}}{value}\n'.format(
key=key, operator='=', value=value,
indent=int(bool(indentation)) + 1)

fd.write(string_section.encode('utf-8'))

def write(self, source, indentation=32, sorting=None):
def write(self, source):
"""
Write an .ini-format representation of the
configuration state with a readable indentation.
"""
if self.indentation < 0:
self.indentation = self.perfect_indentation

with open(source, 'wb') as fd:
sections = list(self._sections.keys())
for section in sections[:-1]:
self.write_section(fd, section, indentation, sorting)
self.write_section(fd, section,
self.indentation, self.sorting)
fd.write('\n'.encode('utf-8'))
self.write_section(fd, sections[-1], indentation, sorting)
self.write_section(fd, sections[-1],
self.indentation, self.sorting)

@property
def perfect_indentation(self, rounding=4):
"""
Find the perfect indentation required for writing
the file, by iterating over the different options.
"""
return perfect_indentation(
chain(*[self.options(section) for section in self.sections()])
)
9 changes: 9 additions & 0 deletions bvc/indentation.py
@@ -0,0 +1,9 @@
"""Indentation for Buildout Versions Checker"""


def perfect_indentation(keys, rounding=4):
"""
Find perfect indentation by iterating over keys.
"""
max_key_length = max(len(k) for k in keys)
return max_key_length + (rounding - (max_key_length % rounding))
31 changes: 19 additions & 12 deletions bvc/scripts/check_buildout_updates.py
@@ -1,17 +1,19 @@
"""Command line for Buildout Versions Checker"""
from six import string_types

import sys
import copy
import logging
import sys

from argparse import Action
from argparse import ArgumentError
from argparse import ArgumentParser
from argparse import _ensure_value

from bvc.logger import logger
from six import string_types

from bvc.checker import VersionsChecker
from bvc.configparser import VersionsConfigParser
from bvc.indentation import perfect_indentation
from bvc.logger import logger


class StoreSpecifiers(Action):
Expand Down Expand Up @@ -63,10 +65,11 @@ def cmdline(argv=sys.argv[1:]):
'-w', '--write', action='store_true', dest='write', default=False,
help='Write the updates in the source file')
file_group.add_argument(
'--indent', dest='indentation', type=int, default=32,
help='Spaces used when indenting "key = value" (default: 32)')
'--indent', dest='indentation', type=int, default=-1,
help='Spaces used when indenting "key = value" (default: auto)')
file_group.add_argument(
'--sorting', dest='sorting', default='', choices=['alpha', 'length'],
'--sorting', dest='sorting', default='',
choices=['alpha', 'ascii', 'length'],
help='Sorting algorithm used on the keys when writing source file '
'(default: None)')
network_group = parser.add_argument_group('Network')
Expand Down Expand Up @@ -116,20 +119,24 @@ def cmdline(argv=sys.argv[1:]):
if not checker.updates:
sys.exit(0)

indentation = options.indentation
if indentation < 0:
indentation = perfect_indentation(checker.updates.keys())
logger.warning('[versions]')
for package, version in checker.updates.items():
logger.warning('%s= %s',
package.ljust(options.indentation),
version)
logger.warning('%s= %s', package.ljust(indentation), version)

if options.write:
config = VersionsConfigParser()
config = VersionsConfigParser(
indentation=options.indentation,
sorting=options.sorting)
config.read(source)
if not config.has_section('versions'):
config.add_section('versions')
for package, version in checker.updates.items():
config.set('versions', package, version)

config.write(source, options.indentation, options.sorting)
config.write(source)
logger.info('- %s updated.', source)

sys.exit(0)
22 changes: 13 additions & 9 deletions bvc/scripts/find_unused_versions.py
@@ -1,13 +1,14 @@
"""Command line for finding unused pinned versions"""
from six import string_types

import sys
import logging
import sys

from argparse import ArgumentParser

from bvc.logger import logger
from six import string_types

from bvc.checker import UnusedVersionsChecker
from bvc.configparser import VersionsConfigParser
from bvc.logger import logger


def cmdline(argv=sys.argv[1:]):
Expand All @@ -31,10 +32,11 @@ def cmdline(argv=sys.argv[1:]):
'-w', '--write', action='store_true', dest='write', default=False,
help='Write the updates in the source file')
file_group.add_argument(
'--indent', dest='indentation', type=int, default=32,
help='Spaces used when indenting "key = value" (default: 32)')
'--indent', dest='indentation', type=int, default=-1,
help='Spaces used when indenting "key = value" (default: auto)')
file_group.add_argument(
'--sorting', dest='sorting', default='', choices=['alpha', 'length'],
'--sorting', dest='sorting', default='',
choices=['alpha', 'ascii', 'length'],
help='Sorting algorithm used on the keys when writing source file '
'(default: None)')
verbosity_group = parser.add_argument_group('Verbosity')
Expand Down Expand Up @@ -72,12 +74,14 @@ def cmdline(argv=sys.argv[1:]):
logger.warning('- %s is unused.', package)

if options.write:
config = VersionsConfigParser()
config = VersionsConfigParser(
indentation=options.indentation,
sorting=options.sorting)
config.read(source)
for package in checker.unused:
config.remove_option('versions', package)

config.write(source, options.indentation, options.sorting)
config.write(source)
logger.info('- %s updated.', source)

sys.exit(0)
24 changes: 14 additions & 10 deletions bvc/scripts/indent_buildout.py
@@ -1,12 +1,13 @@
"""Command line for (re)indenting buildout files"""
from six import string_types

import sys
import logging
import sys

from argparse import ArgumentParser

from bvc.logger import logger
from six import string_types

from bvc.configparser import VersionsConfigParser
from bvc.logger import logger


def cmdline(argv=sys.argv[1:]):
Expand All @@ -17,10 +18,11 @@ def cmdline(argv=sys.argv[1:]):
help='The buildout files to (re)indent')
format_group = parser.add_argument_group('Formatting')
format_group.add_argument(
'--indent', dest='indentation', type=int, default=32,
help='Spaces used when indenting "key = value" (default: 32)')
'--indent', dest='indentation', type=int, default=-1,
help='Spaces used when indenting "key = value" (default: auto)')
format_group.add_argument(
'--sorting', dest='sorting', default='', choices=['alpha', 'length'],
'--sorting', dest='sorting', default='',
choices=['alpha', 'ascii', 'length'],
help='Sorting algorithm used on the keys when writing source file '
'(default: None)')
verbosity_group = parser.add_argument_group('Verbosity')
Expand Down Expand Up @@ -49,12 +51,14 @@ def cmdline(argv=sys.argv[1:]):
sys.exit(0)

for source in options.sources:
config = VersionsConfigParser()
config = VersionsConfigParser(
indentation=options.indentation,
sorting=options.sorting)
config_readed = config.read(source)
if config_readed:
config.write(source, options.indentation, options.sorting)
config.write(source)
logger.warning('- %s (re)indented at %s spaces.',
source, options.indentation)
source, config.indentation)
else:
logger.warning('- %s cannot be read.', source)

Expand Down

0 comments on commit 0776c07

Please sign in to comment.