John Vandenberg has uploaded a new change for review. https://gerrit.wikimedia.org/r/292338
Change subject: Add apt packages ...................................................................... Add apt packages Add trusty+sid job as precise does not have many packages such as python-unicodecsv, and precise+sid does not allow apt additions of python packages, as they drag in many other dependencies and the apt-get install fails. Package versions added: - bs4 - future - pycountry - stdnum 0.6 - unicodecsv - unittest2 Bug: T136807 Bug: T136808 Change-Id: Idb781e5af96f8d713511457cd18afd08c3091b83 --- M .travis.yml M pywikibot/cosmetic_changes.py M requirements.txt M scripts/isbn.py M tests/isbn_tests.py 5 files changed, 79 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/38/292338/1 diff --git a/.travis.yml b/.travis.yml index a0186ad..272703c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -132,9 +132,10 @@ - LANGUAGE=en FAMILY=wikipedia PYWIKIBOT2_TEST_PROD_ONLY=1 - LANGUAGE=zh FAMILY=wikisource PYSETUP_TEST_EXTRAS=1 PYWIKIBOT2_TEST_PROD_ONLY=1 PYWIKIBOT2_TEST_NO_RC=1 +# Note: 2.7_with_system_site_packages is equivalent to virtualenv: system_site_packages: true matrix: include: - - python: '2.7_with_system_site_packages' # equivalent to virtualenv: system_site_packages: true + - python: '2.7_with_system_site_packages' env: LANGUAGE=he FAMILY=wikivoyage DIST=precise-sudo PYWIKIBOT2_TEST_NO_RC=1 dist: precise sudo: required @@ -144,7 +145,13 @@ - djvulibre-bin - graphviz - liblua5.1-0-dev + # python-bs4: diff broken - python-ipaddr + - python-pycountry + - python-six + - python-stdnum + - python-tz + - python-unittest2 - python: '2.7_with_system_site_packages' env: LANGUAGE=nb FAMILY=wikipedia DIST=trusty PYSETUP_TEST_EXTRAS=1 dist: trusty @@ -155,7 +162,34 @@ - djvulibre-bin - graphviz - liblua5.1-0-dev + - python-bs4 - python-ipaddr + - python-pycountry + - python-six + - python-stdnum + - python-tz + - python-unicodecsv + - python-unittest2 + - python: '2.7_with_system_site_packages' + env: LANGUAGE=test FAMILY=wikipedia DIST=trusty+sid PYSETUP_TEST_EXTRAS=1 + dist: trusty + sudo: required + addons: + apt: + sources: + - debian-sid + packages: + - djvulibre-bin + - liblua5.1-0-dev + - python-bs4 + - python-ipaddr + - python-future + - python-pycountry + - python-six + - python-stdnum + - python-tz + - python-unicodecsv + - python-unittest2 - python: '2.7' env: LANGUAGE=en FAMILY=wpbeta SITE_ONLY=1 OAUTH_DOMAIN="en.wikipedia.beta.wmflabs.org" - python: '3.3' diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py index 6afa7b0..577bdc0 100755 --- a/pywikibot/cosmetic_changes.py +++ b/pywikibot/cosmetic_changes.py @@ -64,9 +64,23 @@ from warnings import warn try: - import stdnum.isbn as stdnum_isbn + from stdnum import isbn as stdnum_isbn + # 0.8 includes validate which raises useful exceptions + try: + from stdnum.exceptions import ValidationError as StdNumValidationError + from stdnum.isbn import validate as stdnum_isbn_validate + except ImportError: + stdnum_isbn_validate = None + StdNumValidationError = ValueError + try: + from stdnum.isbn import is_valid as stdnum_isbn_is_valid + except ImportError: + from stdnum.isbn import validate as stdnum_isbn_is_valid except ImportError: stdnum_isbn = None + stdnum_isbn_validate = None + stdnum_isbn_is_valid = None + StdNumValidationError = None import pywikibot @@ -159,8 +173,13 @@ isbn = match.group('code') if stdnum_isbn: try: - stdnum_isbn.validate(isbn) - except stdnum_isbn.ValidationError as e: + if stdnum_isbn_validate: + stdnum_isbn_validate(isbn) + else: + if not stdnum_isbn_is_valid(isbn): + raise StdNumValidationError( + 'ISBN {0} not valid'.format(isbn)) + except StdNumValidationError as e: if strict: raise pywikibot.log('ISBN "%s" validation error: %s' % (isbn, e)) diff --git a/requirements.txt b/requirements.txt index 9b4400a..907bcec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -45,7 +45,7 @@ unicodecsv ; python_version < '3' and python_version >= '2.7' # cosmetic_changes and scripts/isbn -python-stdnum +python-stdnum>=0.2 # GUI Pillow @@ -86,7 +86,7 @@ # Also script_wui.py is not currently functional, so it isnt installed here. # core HTML comparison parser in diff module -beautifulsoup4 +beautifulsoup4>=4.2.1 # scripts/states_redirect.py pycountry diff --git a/scripts/isbn.py b/scripts/isbn.py index b96676c..cd2e08b 100755 --- a/scripts/isbn.py +++ b/scripts/isbn.py @@ -1361,8 +1361,8 @@ # isbnlib marks any ISBN10 with lowercase 'X' as invalid isbn = isbn.upper() try: - stdnum.isbn - except NameError: + stdnum.isbn.validate + except (NameError, AttributeError): pass else: try: @@ -1376,6 +1376,16 @@ return True try: + stdnum.isbn.is_valid + except (NameError, AttributeError): + pass + else: + if not stdnum.isbn.is_valid(isbn): + raise InvalidIsbnException( + 'ISBN {0} not valid'.format(isbn)) + return True + + try: isbnlib except NameError: pass diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py index 668219a..3d8b2e7 100644 --- a/tests/isbn_tests.py +++ b/tests/isbn_tests.py @@ -12,8 +12,14 @@ __version__ = '$Id$' try: - from stdnum.exceptions import ValidationError as StdNumValidationError -except ImportError: + import stdnum + # Prior to 0.8, isbn raised ValueError + try: + from stdnum.exceptions import ValidationError as StdNumValidationError + except ImportError: + StdNumValidationError = ValueError +except ImportError as e: + stdnum = e StdNumValidationError = None from pywikibot import Bot, Claim, ItemPage -- To view, visit https://gerrit.wikimedia.org/r/292338 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idb781e5af96f8d713511457cd18afd08c3091b83 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: John Vandenberg <jay...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits