Skip to content

Commit

Permalink
Merge pull request #68 from lehinevych/pr_61
Browse files Browse the repository at this point in the history
Update documentation
  • Loading branch information
lehinevych authored Sep 28, 2023
2 parents ad59dbb + e6c6c7d commit 06869b2
Show file tree
Hide file tree
Showing 11 changed files with 433 additions and 238 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run black --diff --check .
```

To build the documentation run:
```
poetry run sphinx-build docs/source docs/build
```

License
-------

Expand Down
20 changes: 0 additions & 20 deletions docs/Makefile

This file was deleted.

6 changes: 2 additions & 4 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ MediaWikiAPI Documentation

Here you can find the full developer API for the MediaWikiAPI project.

Contents:
Please note that some functionality available only for MediaWiki version 1.34 or higher
For instance: `content`, `infobox`, `parent_id`, `revision_id`, and `summary`

.. toctree::

api

.. automodule:: mediawikiapi
:members:
Expand Down
7 changes: 0 additions & 7 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ Changelog

Here you can find the full developer API for the MediaWikiAPI project.

Contents:

.. toctree::

changelog


Version 1.2
=============
* The `Config` allows to specify the API url. This makes the client reusable for other Mediawiki installs with the same API.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
10 changes: 8 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Release v\ |version|.

Installation
=============
Start using wikipedia for Python in less than 5 minutes!
MediaWikiAPI is compatible with Python 3 and Python 2.7.
Start using wikipedia for Python in less than 1 minute!
MediaWikiAPI is compatible with Python > 3.9
If you are looking for the the full developer API, see :ref:`api`.

Begin by installing wikipedia::
Expand Down Expand Up @@ -120,6 +120,12 @@ Changelog
API
====

Here you can find the full developer API for the MediaWikiAPI project.

Please note that some functionality available only for MediaWiki version 1.34 or higher
For instance: `content`, `infobox`, `parent_id`, `revision_id`, and `summary`


.. toctree::

api
Expand Down
13 changes: 13 additions & 0 deletions mediawikiapi/wikipediapage.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ def html(self) -> Any:

@property
def infobox(self) -> Dict[str, Any]:
"""
Info bot section of the page
Supported only for MediaWiki version 1.34 or higher
"""
if getattr(self, "_infobox", False):
return self._infobox
if not getattr(self, "_html", False):
Expand All @@ -245,6 +250,8 @@ def infobox(self) -> Dict[str, Any]:
def content(self) -> str:
"""
Plain text content of the page, excluding images, tables, and other data.
Supported only for MediaWiki version 1.34 or higher
"""
if not getattr(self, "_content", False):
query_params: Dict[str, str | int] = {
Expand Down Expand Up @@ -274,6 +281,8 @@ def revision_id(self) -> int:
other direct API calls. See `Help:Page history
<http://en.wikipedia.org/wiki/Wikipedia:Revision>`_ for more
information.
Supported only for MediaWiki version 1.34 or higher
"""
if not getattr(self, "_revid", False):
# fetch the content (side effect is loading the revid)
Expand All @@ -286,6 +295,8 @@ def parent_id(self) -> int:
"""
Revision ID of the parent version of the current revision of this
page. See ``revision_id`` for more information.
Supported only for MediaWiki version 1.34 or higher
"""
if not getattr(self, "_parentid", False):
# fetch the content (side effect is loading the revid)
Expand All @@ -296,6 +307,8 @@ def parent_id(self) -> int:
def summary(self) -> str:
"""
Plain text summary of the page.
Supported only for MediaWiki version 1.34 or higher
"""
if not getattr(self, "_summary", False):
query_params: Dict[str, str | int] = {
Expand Down
545 changes: 378 additions & 167 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.9"
beautifulsoup4 = "^4.11.1"
requests = "^2.28.1"
sphinx = { version = "^7.2.6", optional=true}


[tool.poetry.group.dev.dependencies]
mypy = "^0.991"
Expand Down
55 changes: 22 additions & 33 deletions tests/request_mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,24 +1614,11 @@
"CS1 errors: bare URL",
"CS1 errors: missing title",
"Lettuce",
"Pages with plain IPA",
"Short description is different from Wikidata",
"Stem vegetables",
"Vegetable stubs",
],
"cyclone": [
"2007 Atlantic hurricane season",
"Articles which contain graphical timelines",
"Articles with short description",
"Atlantic hurricane seasons",
"CS1 Spanish-language sources (es)",
"CS1 maint: multiple names: authors list",
"Featured articles",
"Pages using the EasyTimeline extension",
"Short description matches Wikidata",
"Source attribution",
"Tropical cyclones in 2007",
"Wikipedia indefinitely move-protected pages",
],
]
}

mock_backlinks: Dict[str, List[str]] = {
Expand Down Expand Up @@ -2257,13 +2244,13 @@
"https://upload.wikimedia.org/wikipedia/commons/a/a1/Oppenheimer_Marshall_Conant_Bradley_and_others_at_Harvard.jpg",
"https://upload.wikimedia.org/wikipedia/commons/b/b5/Radioactive.svg",
"https://upload.wikimedia.org/wikipedia/commons/2/22/Robert_Oppenheimer.ogg",
"https://upload.wikimedia.org/wikipedia/commons/d/da/SF_From_Marin_Highlands3.jpg",
"https://upload.wikimedia.org/wikipedia/commons/4/47/Sound-icon.svg",
"https://upload.wikimedia.org/wikipedia/commons/6/6f/Stylised_atom_with_three_Bohr_model_orbits_and_stylised_nucleus.svg",
"https://upload.wikimedia.org/wikipedia/commons/4/48/Trinity_-_Explosion_15s.jpg",
"https://upload.wikimedia.org/wikipedia/commons/f/fc/Trinity_Detonation_T%26B.jpg",
"https://upload.wikimedia.org/wikipedia/commons/7/7e/Trinity_Test_-_Oppenheimer_and_Groves_at_Ground_Zero_002.jpg",
"https://upload.wikimedia.org/wikipedia/commons/6/63/University_of_California_Radiation_Laboratory_staff_on_the_magnet_yoke_for_the_60-inch_cyclotron%2C_1938.jpg",
"https://upload.wikimedia.org/wikipedia/commons/f/ff/Wikidata-logo.svg",
"https://upload.wikimedia.org/wikipedia/commons/f/fa/Wikiquote-logo.svg",
"https://upload.wikimedia.org/wikipedia/en/4/4a/Commons-logo.svg",
"https://upload.wikimedia.org/wikipedia/en/e/e7/Cscr-featured.svg",
Expand Down Expand Up @@ -2309,10 +2296,13 @@
"External links",
]


mock_category_members_physics: List[str] = [
"Physics",
"Portal:Physics",
"Pedersen current",
"Force control",
"Overlap fermion",
"Trajectoid",
]


Expand Down Expand Up @@ -2361,21 +2351,20 @@
"great_wall_of_china.geo_seach_with_existing_article_name": ["Great Wall of China"],
"great_wall_of_china.geo_seach_with_non_existing_article_name": [],
"infobox_avatar": {
"Also known as": "Avatar: The Legend of Aang Avatar The Last Airbender",
"Genre": "Action Adventure Comedy drama Fantasy",
"Created by": "Michael Dante DiMartino Bryan Konietzko",
"Voices of": "Zach Tyler Eisen Mae Whitman Jack DeSena Dante Basco Jessie Flower Dee Bradley Baker Mako Greg Baldwin Grey DeLisle Mark Hamill",
"Composers": "Jeremy Zuckerman Benjamin Wynn",
"Country of origin": "United States",
"Original language": "English",
"No. of seasons": "3",
"No. of episodes": "61 (list of episodes)",
"Executive producers": "Michael Dante DiMartino Bryan Konietzko Aaron Ehasz",
"Animators": "JM Animation (32 episodes)[a] DR Movie (19 episodes)[b] Moi Animation (10 episodes)[c]",
"Running time": "23 minutes",
"Production company": "Nickelodeon Animation Studio",
"Original network": "Nickelodeon",
"Picture format": "NTSC",
"Original release": "February 21, 2005 (2005-02-21) –July 19, 2008 (2008-07-19)",
"Directed by": "James Cameron",
"Written by": "James Cameron",
"Produced by": "James Cameron Jon Landau",
"Starring": "Sam Worthington Zoe Saldana Stephen Lang Michelle Rodriguez Sigourney Weaver",
"Cinematography": "Mauro Fiore",
"Edited by": "Stephen Rivkin John Refoua James Cameron",
"Music by": "James Horner",
"Productioncompanies": "20th Century Fox Lightstorm Entertainment Dune Entertainment Ingenious Film Partners",
"Distributed by": "20th Century Fox",
"Release dates": "December 10, 2009 (2009-12-10) (London) December 18, 2009 (2009-12-18) (United States)",
"Running time": "162 minutes",
"Countries": "United States United Kingdom",
"Language": "English",
"Budget": "$237 million",
"Box office": "$2.923 billion",
},
}
4 changes: 1 addition & 3 deletions tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import mediawikiapi
from bs4 import BeautifulSoup
from decimal import Decimal
from typing import Dict, Any
from mediawikiapi import MediaWikiAPI
from mediawikiapi.config import Config
from mediawikiapi.wikipediapage import WikipediaPage
Expand Down Expand Up @@ -105,7 +104,7 @@ def setUp(self) -> None:
self.celtuce = api.page("Celtuce")
self.cyclone = api.page("2007 Atlantic hurricane season")
self.great_wall_of_china = api.page("Great Wall of China")
self.avatar = api.page(title="Avatar_(2009_film)")
self.avatar = api.page(title="Avatar (2009 film)", auto_suggest=False)

def test_from_page_id(self) -> None:
"""Test loading from a page id"""
Expand Down Expand Up @@ -192,7 +191,6 @@ def test_summary(self) -> None:
def test_categories(self) -> None:
"""Test the list of categories of Wikipedia pages."""
self.assertCountEqual(self.celtuce.categories, mock_categories["celtuce"])
self.assertCountEqual(self.cyclone.categories, mock_categories["cyclone"])

def test_sections(self) -> None:
"""Test the list of section titles."""
Expand Down

0 comments on commit 06869b2

Please sign in to comment.