jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/791748 )
Change subject: [IMPR] Add a new script to create a Pywikibot distribution
......................................................................
[IMPR] Add a new script to create a Pywikibot distribution
- Add a new script "make_dist.py" to create a new distribution.
- With -local option the distribution is installed as local site-package.
It uninstalls an already installed Pywikibot site-package version.
- With -remote option the distribution is uploaded to pypi if it is not
a development release
- Change setup.py to allow creating a development release package.
- Update documentations
- Add setup.py and make_dist.py to sphinx documentation
- Exclude make_dist from flake83py35 tests because 3.6+ is needed for
this script
Change-Id: I06a830c5309b0416d90ff5206c268f5495ee7d02
---
M CONTENT.rst
M docs/index.rst
A docs/utilities/install.rst
A make_dist.py
M setup.py
M tox.ini
6 files changed, 147 insertions(+), 16 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/CONTENT.rst b/CONTENT.rst
index edef930..19fa285 100644
--- a/CONTENT.rst
+++ b/CONTENT.rst
@@ -20,6 +20,8 @@
+---------------------------+-----------------------------------------------------------+
| LICENSE | Reference to the MIT license |
+---------------------------+-----------------------------------------------------------+
+ | make_dist.py | Script to create a Pywikibot distribution |
+ +---------------------------+-----------------------------------------------------------+
| MANIFEST.in | Setup file for package data |
+---------------------------+-----------------------------------------------------------+
| pwb.py | Code entry wrapper script (directory mode only) |
diff --git a/docs/index.rst b/docs/index.rst
index 5ebf2f9..114567a 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -69,6 +69,7 @@
scripts_ref/index
tests_ref/index
Maintenance Scripts<scripts_ref/scripts.maintenance>
+ utilities/install
Miscellaneous
diff --git a/docs/utilities/install.rst b/docs/utilities/install.rst
new file mode 100644
index 0000000..f9530c7
--- /dev/null
+++ b/docs/utilities/install.rst
@@ -0,0 +1,12 @@
+Installer Scripts
+=================
+
+make\_dist script
+-----------------
+
+.. automodule:: make_dist
+
+setup script
+------------
+
+.. automodule:: setup
\ No newline at end of file
diff --git a/make_dist.py b/make_dist.py
new file mode 100644
index 0000000..574800c
--- /dev/null
+++ b/make_dist.py
@@ -0,0 +1,125 @@
+#!/usr/bin/python3
+"""Script to create a new distribution.
+
+The following options are supported:
+
+-help Print documentation of this file and of setup.py
+
+-local Install the distribution as a local site-package. If a
+ Pywikibot package is already there, it will be uninstalled
+ first.
+
+-remote Upload the package to pypi. This cannot be done if the
+ Pywikibot version is a development release.
+
+Usage::
+
+ [pwb] make_dist [options]
+
+.. note:: Requires Python 3.6+
+.. versionadded:: 7.3
+"""
+#
+# (C) Pywikibot team, 2022
+#
+# Distributed under the terms of the MIT license.
+#
+import shutil
+import subprocess
+import sys
+from pathlib import Path
+
+from pywikibot import __version__, error, info, input_yn, warning
+from pywikibot.backports import Tuple
+import setup
+
+
+def copy_files() -> None:
+ """Copy code entry point and i18n files to pywikibot.scripts folder.
+
+ pwb.py wrapper script is a console script entry point for the
+ site-package. pywikibot i18n files are used for some translations.
+ They are copied to the pywikibot scripts folder.
+ """
+ folder = Path().resolve()
+ info(f'directory is {folder}')
+
+ # copy script entry points to pywikibot\scripts
+ target = folder / 'pywikibot' / 'scripts'
+ filename = 'pwb.py'
+ info(f'copy script entry point {filename!r} to {target}... ',
+ newline=False)
+ shutil.copy(folder / filename, target / filename)
+ info('done')
+
+ target = target / 'i18n' / 'pywikibot'
+ info(f'copy i18n files to {target} ... ', newline=False)
+ target.parent.mkdir()
+ filename = '__init__.py'
+ shutil.copy(folder / 'scripts' / 'i18n' / filename,
+ target.parent / filename)
+ shutil.copytree(folder / 'scripts' / 'i18n' / 'pywikibot', target)
+ info('done')
+
+
+def cleanup() -> None:
+ """Remove all files which were copied to the pywikibot scripts folder."""
+ info('Remove copied files... ', newline=False)
+ folder = Path().resolve()
+ target = folder / 'pywikibot' / 'scripts' / 'i18n'
+ shutil.rmtree(target)
+ target = target.parent / 'pwb.py'
+ target.unlink()
+ info('done')
+
+
+def handle_args() -> Tuple[bool, bool]:
+ """Handle arguments and print documentation if requested.
+
+ Read arguments from `sys.argv` and adjust it passing `sdist` to
+ `setuptools.setup`.
+
+ :return: Return whether dist is to be installed locally or to be
+ uploaded
+ """
+ if '-help' in sys.argv:
+ info(__doc__)
+ info(setup.__doc__)
+ sys.exit()
+
+ local = '-local' in sys.argv
+ remote = '-remote' in sys.argv
+
+ if remote and 'dev' in __version__:
+ warning('Distribution must not be a developmental release to upload.')
+ remote = False
+
+ sys.argv = [sys.argv[0], 'sdist']
+ return local, remote
+
+
+def main() -> None:
+ """Script entry point."""
+ local, remote = handle_args()
+
+ copy_files()
+
+ try:
+ setup.main() # create a new package
+ except SystemExit as e:
+ error(e)
+ return
+ finally:
+ cleanup()
+
+ if local:
+ subprocess.run('pip uninstall pywikibot -y')
+ subprocess.run('pip install --no-index --find-links=dist pywikibot')
+
+ if remote and input_yn(
+ '<<lightblue>>Upload dist to pypi', automatic_quit=False):
+ subprocess.run('twine upload dist/*')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/setup.py b/setup.py
index f669576..a45eb487 100755
--- a/setup.py
+++ b/setup.py
@@ -2,22 +2,13 @@
# -*- coding: utf-8 -*-
"""Installer script for Pywikibot framework.
-To create a new distribution:
------------------------------
+**How to create a new distribution:**
- replace the developmental version string in ``pywikibot.__metadata__.py``
- by the corresponing final release
-- copy pwb.py to pywikibot/scripts folder
-- copy scripts/i18n/pywikibot folder to pywikibot/scripts/i18n/pywikibot
+ by the corresponding final release
- create the package with::
- python setup.py sdist
-
-- remove copied files
-- push the change to Gerrit and merge it to the repository
-- upload the package to PyPy by::
-
- twine upload dist/*
+ make_dist remote
- create a new tag with the version number of the final release
- synchronize the local tags with the remote repositoy
@@ -26,6 +17,8 @@
- prepare the next master release by increasing the version number in
``pywikibot.__metadata__.py`` and adding developmental identifier
- upload this patchset to Gerrit and merge it.
+
+.. warning: do not upload a development release to pypi.
"""
#
# (C) Pywikibot team, 2009-2022
@@ -185,9 +178,6 @@
last_tag = tags[-1]
warnings = []
- if 'dev' in version:
- warnings.append('Distribution must not be a developmental release.')
-
if parse_version(version) < parse_version('0'):
# any version which is not a valid PEP 440 version will be considered
# less than any valid PEP 440 version
diff --git a/tox.ini b/tox.ini
index f032442..a491bfb 100644
--- a/tox.ini
+++ b/tox.ini
@@ -25,7 +25,8 @@
usedevelop = True
commands =
flake8: flake8 --version
- flake8: flake8 --doctests {posargs}
+ flake8-py35: flake8 --doctests {posargs} --exclude make_dist.py,.tox,.git,./*.egg,build,./scripts/i18n/*
+ flake8-py38: flake8 --doctests {posargs}
hacking: flake8 --version
hacking: flake8 --format=default {posargs}
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/791748
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I06a830c5309b0416d90ff5206c268f5495ee7d02
Gerrit-Change-Number: 791748
Gerrit-PatchSet: 13
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/791730 )
Change subject: Sphinx: replace :note: field element with .. note:: directive
......................................................................
Sphinx: replace :note: field element with .. note:: directive
Bug: T308400
Change-Id: I2765688a5e3c343acbafed1e82b172701c9d6960
---
M pywikibot/data/api.py
M pywikibot/logentries.py
M pywikibot/page/_pages.py
M pywikibot/page/_wikibase.py
M pywikibot/site/_generators.py
M pywikibot/tools/__init__.py
M scripts/category.py
7 files changed, 48 insertions(+), 38 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 59d6dcc..8e821da 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -1314,9 +1314,9 @@
URL encodes the parameters provided by _encoded_items()
- :note: Not all parameters are sorted, therefore for two given
- CachedRequest objects with equal _params, the result of
- _http_param_string() is not necessarily equal.
+ .. note:: Not all parameters are sorted, therefore for two given
+ CachedRequest objects with equal _params, the result of
+ _http_param_string() is not necessarily equal.
"""
return encode_url(self._encoded_items())
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py
index 33d36df..fcc3cdc 100644
--- a/pywikibot/logentries.py
+++ b/pywikibot/logentries.py
@@ -372,9 +372,10 @@
Return the class corresponding to the @logtype string parameter.
:return: specified subclass of LogEntry
- :note: this class method cannot verify whether the given logtype
- already exits for a given site; to verify use Site.logtypes
- or use the get_valid_entry_class instance method instead.
+
+ .. note:: this class method cannot verify whether the given logtype
+ already exits for a given site; to verify use Site.logtypes
+ or use the get_valid_entry_class instance method instead.
"""
if logtype not in cls._logtypes:
bases = (OtherLogEntry, ) # type: Tuple['LogEntry', ...]
diff --git a/pywikibot/page/_pages.py b/pywikibot/page/_pages.py
index dca6379..848b7c0 100644
--- a/pywikibot/page/_pages.py
+++ b/pywikibot/page/_pages.py
@@ -10,8 +10,7 @@
various pages for Proofread Extensions are defines in
``pywikibot.proofreadpage``.
-..note::
- `Link` objects represent a wiki-page's title, while
+..note:: `Link` objects represent a wiki-page's title, while
:class:`pywikibot.Page` objects (defined here) represent the page
itself, including its contents.
"""
@@ -1377,7 +1376,7 @@
minor and botflag parameters are set to False which prevents hiding
the edit when it becomes a real edit due to a bug.
- :note: This discards content saved to self.text.
+ .. note:: This discards content saved to self.text.
"""
if self.exists():
# ensure always get the page text and not to change it.
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 0a342bc..70246a4 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -536,9 +536,10 @@
:param force: override caching
:raise NotImplementedError: a value in args or kwargs
:return: actual data which entity holds
- :note: dicts returned by this method are references to content
- of this entity and their modifying may indirectly cause
- unwanted change to the live content
+
+ .. note:: dicts returned by this method are references to content
+ of this entity and their modifying may indirectly cause
+ unwanted change to the live content
"""
if args or kwargs:
raise NotImplementedError(
@@ -942,9 +943,11 @@
redirect, do not raise an exception.
:raise NotImplementedError: a value in args or kwargs
:return: actual data which entity holds
- :note: dicts returned by this method are references to content of this
- entity and their modifying may indirectly cause unwanted change to
- the live content
+
+ .. note:: dicts returned by this method are
+ references to content of this entity and
+ their modifying may indirectly cause
+ unwanted change to the live content
"""
data = super().get(force, *args, **kwargs)
@@ -1245,9 +1248,11 @@
:param force: override caching
:raise NotImplementedError: a value in args or kwargs
:return: actual data which entity holds
- :note: dicts returned by this method are references to content of this
- entity and their modifying may indirectly cause unwanted change to
- the live content
+
+ .. note:: dicts returned by this method are
+ references to content of this entity and
+ their modifying may indirectly cause
+ unwanted change to the live content
"""
if args or kwargs:
raise NotImplementedError(
@@ -1968,9 +1973,10 @@
redirect, do not raise an exception.
:type get_redirect: bool
:raise NotImplementedError: a value in args or kwargs
- :note: dicts returned by this method are references to content
- of this entity and their modifying may indirectly cause
- unwanted change to the live content
+
+ .. note:: dicts returned by this method are references to content
+ of this entity and their modifying may indirectly cause
+ unwanted change to the live content
"""
data = super().get(force, *args, **kwargs)
@@ -2202,9 +2208,10 @@
Fetch all form data, and cache it.
:param force: override caching
- :note: dicts returned by this method are references to content
- of this entity and their modifying may indirectly cause
- unwanted change to the live content
+
+ .. note:: dicts returned by this method are references to content
+ of this entity and their modifying may indirectly cause
+ unwanted change to the live content
"""
data = super().get(force=force)
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index ce94db9..3edbd7a 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -1097,9 +1097,9 @@
.. seealso:: :api:`Blocks`
- .. note::
- logevents only logs user blocks, while this method iterates
- all blocks including IP ranges.
+ .. note:: logevents only logs user blocks,
+ while this method iterates all blocks
+ including IP ranges.
.. warning::
``iprange`` parameter cannot be used together with ``users``.
@@ -1226,8 +1226,7 @@
.. seealso:: :api:`Logevents`
- .. note::
- logevents with `logtype='block'` only logs user blocks
+ .. note:: logevents with `logtype='block'` only logs user blocks
whereas `site.blocks` iterates all blocks including IP ranges.
:param logtype: only iterate entries of this type
@@ -1237,9 +1236,11 @@
:type page: pywikibot.Page or str
:param namespace: namespace(s) to retrieve logevents from
:type namespace: int or Namespace or an iterable of them
- :note: due to an API limitation, if namespace param contains multiple
- namespaces, log entries from all namespaces will be fetched from
- the API and will be filtered later during iteration.
+
+ .. note:: due to an API limitation,
+ if namespace param contains multiple namespaces,
+ log entries from all namespaces will be fetched from
+ the API and will be filtered later during iteration.
:param start: only iterate entries from and after this Timestamp
:type start: Timestamp or ISO date string
:param end: only iterate entries up to and through this Timestamp
@@ -1548,7 +1549,7 @@
or typing.Iterable[str]
:keyword revids: Get revisions by their ID
- :note: either titles or revids must be set but not both
+ .. note:: either titles or revids must be set but not both
:param start: Iterate revisions starting at this Timestamp
:param end: Iterate revisions ending at this Timestamp
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index acb91a8..9bc7ad0 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -369,9 +369,11 @@
.. versionadded:: 3.0
- :note: MediaWiki doesn't capitalize some characters the same way as Python.
- This function tries to be close to MediaWiki's capitalize function in
- title.php. See T179115 and T200357.
+ .. note:: MediaWiki doesn't capitalize
+ some characters the same way as Python.
+ This function tries to be close to
+ MediaWiki's capitalize function in
+ title.php. See T179115 and T200357.
"""
first = string[:1]
return (_first_upper_exception(first) or first.upper()) + string[1:]
diff --git a/scripts/category.py b/scripts/category.py
index 7386033..8db8a1d 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -1039,8 +1039,8 @@
to move it to one of original_cat's sub- or super-categories.
Recursively run through subcategories' subcategories.
- :note: current_cat is only used for internal recursion. You
- should always use ``current_cat = original_cat``.
+ .. note:: current_cat is only used for internal recursion. You
+ should always use ``current_cat = original_cat``.
:param member: a page to process.
:param original_cat: original category to replace.
:param current_cat: a category which is questioned.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/791730
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I2765688a5e3c343acbafed1e82b172701c9d6960
Gerrit-Change-Number: 791730
Gerrit-PatchSet: 6
Gerrit-Owner: Klein Muçi <kleinmuci(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/791771 )
Change subject: [IMPR] raise InvalidTitleError instead of ValueError in ProofreadPage
......................................................................
[IMPR] raise InvalidTitleError instead of ValueError in ProofreadPage
If the ProofreadPage title has a wrong index raise InvalidTitleError
instead of unspecific
ValueError('ValueError: invalid literal for int() with base 10: {!r}')
Bug: T308016
Change-Id: I39c6569fb15a6864fe2f51e303741739420f4127
---
M pywikibot/proofreadpage.py
1 file changed, 6 insertions(+), 2 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py
index 8378c4f..19fc121 100644
--- a/pywikibot/proofreadpage.py
+++ b/pywikibot/proofreadpage.py
@@ -48,7 +48,7 @@
)
from pywikibot.comms import http
from pywikibot.data.api import ListGenerator, Request
-from pywikibot.exceptions import Error, OtherPageSaveError
+from pywikibot.exceptions import Error, InvalidTitleError, OtherPageSaveError
from pywikibot.page import PageSourceType
from pywikibot.tools import cached
@@ -247,7 +247,11 @@
if sep:
base = left
- num = int(right)
+ try:
+ num = int(right)
+ except ValueError:
+ raise InvalidTitleError('{} containts invalid index {!r}'
+ .format(self, right))
else:
base = right
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/791771
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I39c6569fb15a6864fe2f51e303741739420f4127
Gerrit-Change-Number: 791771
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/791774 )
Change subject: [bugfix] Preload pages if GeneratorFactory.articlenotfilter_list is not empty
......................................................................
[bugfix] Preload pages if GeneratorFactory.articlenotfilter_list is not empty
- If pagegenerators.GeneratorFactory.articlenotfilter_list is not empty
Page objects should be preloaded like for articlefilter_list.
- Add a new instance variable is_preloading which is set to True or False
when GeneratorFactory.getCombinedGenerator() is called. Otherwise its
value is None.
Change-Id: Icb2b62fb2fcbd6be0012a217b124242f0c4edd98
---
M pywikibot/pagegenerators.py
1 file changed, 24 insertions(+), 3 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 002ca17..bd1374a 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -468,8 +468,8 @@
This factory is responsible for processing command line arguments
that are used by many scripts and that determine which pages to work on.
- :Note: GeneratorFactory must be instantiated after global arguments are
- parsed except if site parameter is given.
+ .. note:: GeneratorFactory must be instantiated after global
+ arguments are parsed except if site parameter is given.
"""
def __init__(self, site: OPT_SITE_TYPE = None,
@@ -505,6 +505,21 @@
self.nopreload = False
self._validate_options(enabled_options, disabled_options)
+ self.is_preloading = None # type: Optional[bool]
+ """Return whether Page objects are preloaded. You may use this
+ instance variable after :meth:`getCombinedGenerator` is called
+ e.g.::
+
+ gen_factory = GeneratorFactory()
+ print(gen_factory.is_preloading) # None
+ gen = gen_factory.getCombinedGenerator()
+ print(gen_factory.is_preloading) # True or False
+
+ Otherwise the value is undefined and gives None.
+
+ .. versionadded:: 7.3
+ """
+
def _validate_options(self,
enable: Optional[Iterable[str]],
disable: Optional[Iterable[str]]) -> None:
@@ -574,6 +589,9 @@
Only call this after all arguments have been parsed.
+ .. versionchanged:: 7.3
+ set the instance variable :attr:`is_preloading` to True or False.
+
:param gen: Another generator to be combined with
:param preload: preload pages using PreloadingGenerator
unless self.nopreload is True
@@ -649,7 +667,10 @@
dupfiltergen = CategoryFilterPageGenerator(
dupfiltergen, self.catfilter_list)
- if (preload or self.articlefilter_list) and not self.nopreload:
+ self.is_preloading = not self.nopreload and bool(
+ preload or self.articlefilter_list or self.articlenotfilter_list)
+
+ if self.is_preloading:
if isinstance(dupfiltergen, DequeGenerator):
dupfiltergen = DequePreloadingGenerator(dupfiltergen)
else:
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/791774
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Icb2b62fb2fcbd6be0012a217b124242f0c4edd98
Gerrit-Change-Number: 791774
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged