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 <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to