diff --git a/Makefile b/Makefile index 0d94189..24aae05 100644 --- a/Makefile +++ b/Makefile @@ -19,14 +19,25 @@ pypi-html: run-tests: python3 -m unittest discover tests/ '*test.py' + +run-type-check: + mypy ./example.py run-coverage: coverage run --source=wikipediaapi -m unittest discover tests/ '*test.py' coverage report -m -release: run-tests pypi-html - if [ "x$(MSG)" = "x" ]; then \ - echo "Use make release MSG='some msg'"; \ +requirements: + pip3 install -r requirements.txt + +requirements-dev: + pip3 install -r requirements-dev.txt + +pre-release-check: run-tests run-coverage pypi-html run-type-check + +release: pre-release-check + if [ "x$(MSG)" = "x" -o "x$(VERSION)" = "x" ]; then \ + echo "Use make release MSG='some msg' VERSION='1.2.3'"; \ exit 1; \ fi; \ version=`grep __version__ wikipediaapi/__init__.py | sed -r 's/.*= \( *(.*), *(.*), *(.*)\)/\1.\2.\3/'`; \ @@ -35,13 +46,43 @@ release: run-tests pypi-html exit 1; \ fi; \ echo "Current version: $$version"; \ - short=`echo $$version | cut -f1-2 -d.`; \ - echo "Short version: $$short"; \ - sed -ri 's/^release = .*/release = "'$$version'"/' conf.py; \ - sed -ri 's/^version = .*/version = "'$$short'"/' conf.py; \ - git commit conf.py -m "Update version to $$version in conf.py"; \ + as_number() { \ + total=0; \ + for p in `echo $$1 | tr "." "\n"`; do \ + total=$$(( $$total * 1000 + $$p )); \ + done; \ + echo $$total; \ + }; \ + number_dots=`echo -n $(VERSION) | sed -r 's/[^.]//g' | wc -c`; \ + if [ ! "$${number_dots}" = "2" ]; then \ + echo "Version has to have format X.Y.Z"; \ + echo "Specified version is $(VERSION)"; \ + exit 2; \ + fi; \ + number_version=`as_number $$version`; \ + number_VERSION=`as_number $(VERSION);`; \ + if [ $$number_version -ge $$number_VERSION ]; then \ + echo -n "Specified version $(VERSION) ($$number_VERSION) is lower than"; \ + echo "current version $$version ($$number_version)"; \ + echo "New version has to be greater"; \ + exit 2; \ + fi; \ + has_documentation=`grep -c "^$(VERSION)\\$$" CHANGES.rst`; \ + if [ $$has_documentation -eq 0 ]; then \ + echo "There is no information about $(VERSION) in CHANGES.rst"; \ + exit 3; \ + fi; \ + short_VERSION=`echo $(VERSION) | cut -f1-2 -d.`; \ + commas_VERSION=`echo $(VERSION) | sed -r 's/\./, /g'`; \ + echo "Short version: $$short_VERSION"; \ + sed -ri 's/version=.*/version="'$(VERSION)'",/' setup.py; \ + sed -ri 's/^release = .*/release = "'$(VERSION)'"/' conf.py; \ + sed -ri 's/^version = .*/version = "'$$short_VERSION'"/' conf.py; \ + sed -ri 's/^Current version is: .*/Current version is: "'$(VERSION)'"/' wikipediaapi/__init__.py; \ + sed -ri 's/^__version__ = .*/__version__ = ('"$$commas_VERSION"')/' wikipediaapi/__init__.py; \ + git commit setup.py conf.py wikipediaapi/__init__.py -m "Update version to $(VERSION) for new release."; \ git push; \ - git tag $$version -m "$(MSG)"; \ + git tag $(VERSION) -m "$(MSG)"; \ git push --tags origin master # Catch-all target: route all unknown targets to Sphinx using the new @@ -51,3 +92,4 @@ release: run-tests pypi-html + diff --git a/conf.py b/conf.py index 1855f52..97756e8 100644 --- a/conf.py +++ b/conf.py @@ -57,7 +57,7 @@ # The short X.Y version. version = "0.3" # The full version, including alpha/beta/rc tags. -release = "0.3.5" +release = "0.3.7" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..ca31bce --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,2 @@ +mypy +sphinx diff --git a/requirements.txt b/requirements.txt index f229360..c9eb394 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ requests +typing diff --git a/setup.py b/setup.py index b6f8439..9ce1d8b 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def fix_doc(txt): setup( name='Wikipedia-API', - version='0.3.5', + version="0.3.7", description='Python Wrapper for Wikipedia', long_description=README + '\n\n' + CHANGES, classifiers=[ diff --git a/tests/extract_html_format_test.py b/tests/extract_html_format_test.py index 855981e..bd1eda0 100644 --- a/tests/extract_html_format_test.py +++ b/tests/extract_html_format_test.py @@ -108,3 +108,19 @@ def test_text(self): "
Text for section 5.1\n\n\n
" ) ) + + def test_with_erroneous_edit(self): + page = self.wiki.page('Test_Edit') + self.maxDiff = None + section = page.section_by_title('Section with Edit') + self.assertEqual(section.title, 'Section with Edit') + self.assertEqual( + page.text, + ( + "Summary text\n\n
\n\n" + + "Text for section 1
\n\n" + "Text for section with edit\n\n\n
" + ) + ) diff --git a/tests/mock_data.py b/tests/mock_data.py index e13d134..822e8da 100644 --- a/tests/mock_data.py +++ b/tests/mock_data.py @@ -108,6 +108,36 @@ def wikipedia_api_request(page, params): } } }, + 'en:action=query&prop=extracts&titles=Test_Edit&': { + "batchcomplete": "", + "warnings": { + "extracts": { + "*": "\"exlimit\" was too large for a whole article extracts request, lowered to 1." + } + }, + "query": { + "normalized": [ + { + "from": "Test_Edit", + "to": "Test Edit" + } + ], + "pages": { + "4": { + "pageid": 4, + "ns": 0, + "title": "Test Edit", + "extract": ( + "Summary text\n\n
\n" + + "Text for section 1
\n\n\n" + + "Text for section with edit\n\n\n
" + ) + } + } + } + }, 'en:action=query&inprop=protection|talkid|watched|watchers|visitingwatchers|notificationtimestamp|subjectid|url|readable|preload|displaytitle&prop=info&titles=Test_1&': { "batchcomplete": "", "query": { diff --git a/wikipediaapi/__init__.py b/wikipediaapi/__init__.py index 7dd09d5..a4c7f31 100644 --- a/wikipediaapi/__init__.py +++ b/wikipediaapi/__init__.py @@ -2,7 +2,7 @@ Wikipedia-API is easy to use Python wrapper for `Wikipedias'`_ API. It supports extracting texts, sections, links, categories, translations, etc from Wikipedia. Documentation provides code snippets for the most common use cases. You can learn more at: http://wikipedia-api.readthedocs.io/en/latest/ -Current version is: 0.3.5 +Current version is: "0.3.7" ''' from .wikipedia import * -__version__ = (0, 3, 5) +__version__ = (0, 3, 7) diff --git a/wikipediaapi/wikipedia.py b/wikipediaapi/wikipedia.py index 48eaa3d..4d05947 100644 --- a/wikipediaapi/wikipedia.py +++ b/wikipediaapi/wikipedia.py @@ -1,10 +1,13 @@ import logging import re import requests +from typing import Dict, Any, List log = logging.getLogger(__name__) # https://www.mediawiki.org/wiki/API:Main_page +PagesDict = Dict[str, 'WikipediaPage'] + class ExtractFormat(object): # (Enum): # Wiki: https://goo.gl/PScNVV @@ -65,7 +68,9 @@ class Namespace(object): ExtractFormat.HTML: re.compile( r'\n? *