jenkins-bot submitted this change.
[dist] use build instead of setuptools.setup() to build the distribution
- use build instead of setuptools.setup() to build the distribution
- -upgrade option installs build or twine if necessary
- Show yellow progress lines during build process
- Add ROADMAP and CODE_OF_CONDUCT files; this is necessary to combine
it with README
- remove sdist and bdist arg parsing tests
Bug: T335830
Change-Id: I20674cf6d9c2cc570b85c204e99084dc6758986e
---
M MANIFEST.in
M make_dist.py
M tests/make_dist_tests.py
3 files changed, 57 insertions(+), 24 deletions(-)
diff --git a/MANIFEST.in b/MANIFEST.in
index 38512f9..a4f38b2 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1 +1,3 @@
graft pywikibot/scripts/i18n/pywikibot
+include CODE_OF_CONDUCT.rst
+include ROADMAP.rst
\ No newline at end of file
diff --git a/make_dist.py b/make_dist.py
index 0453ba1..2f0fb95 100755
--- a/make_dist.py
+++ b/make_dist.py
@@ -16,8 +16,8 @@
-clear Clear old dist folders and leave. Does not create a
distribution.
--upgrade Upgrade distribution packages pip, setuptools, wheel and
- twine first
+-upgrade Upgrade pip first; upgrade or install distribution packages
+ build and twine first.
Usage::
@@ -41,6 +41,9 @@
*nodist* option was removed, *clear* option does not create a
distribution. *local* and *remote* option clears old distributions
first.
+.. versionchanged:: 8.2
+ Build frontend was changed from setuptools to build. ``-upgrade``
+ option also installs packages if necessary.
"""
#
# (C) Pywikibot team, 2022-2023
@@ -51,10 +54,10 @@
import shutil
import sys
from dataclasses import dataclass, field
+from importlib import import_module
from pathlib import Path
from subprocess import check_call, run
-import setup
from pywikibot import __version__, error, info, input_yn, warning
from pywikibot.backports import Tuple
@@ -84,11 +87,11 @@
.. versionadded:: 7.5
"""
- info('Removing old dist folders... ', newline=False)
+ info('<<lightyellow>>Removing old dist folders... ', newline=False)
shutil.rmtree(self.folder / 'build', ignore_errors=True)
shutil.rmtree(self.folder / 'dist', ignore_errors=True)
shutil.rmtree(self.folder / 'pywikibot.egg-info', ignore_errors=True)
- info('done')
+ info('<<lightyellow>>done')
@abc.abstractmethod
def copy_files(self) -> None:
@@ -103,30 +106,46 @@
:return: True if no error occurs, else False
"""
- if self.upgrade: # pragma: no cover
- check_call('python -m pip install --upgrade pip', shell=True)
- check_call(
- 'pip install --upgrade setuptools wheel twine ', shell=True)
-
if self.local or self.remote or self.clear:
self.clear_old_dist()
if self.clear:
return True # pragma: no cover
+ if self.upgrade: # pragma: no cover
+ check_call('python -m pip install --upgrade pip', shell=True)
+ for module in ('build', 'twine'):
+ info(f'<<lightyellow>>Install or upgrade {module}')
+ try:
+ import_module(module)
+ except ModuleNotFoundError:
+ check_call(f'pip install {module}', shell=True)
+ else:
+ check_call(f'pip install --upgrade {module}', shell=True)
+ else:
+ for module in ('build', 'twine'):
+ try:
+ import_module(module)
+ except ModuleNotFoundError as e: # pragma: no cover
+ error(f'<<lightred>>{e}')
+ info('<<lightblue>>You may use -upgrade option to install')
+ return False
+
self.copy_files()
+ info('<<lightyellow>>Build package')
try:
- setup.main() # create a new package
- except SystemExit as e: # pragma: no cover
+ check_call('python -m build')
+ except Exception as e: # pragma: no cover
error(e)
return False
finally:
self.cleanup()
- # check description
+ info('<<lightyellow>>Check package and description')
if run('twine check dist/*', shell=True).returncode:
return False # pragma: no cover
if self.local:
+ info('<<lightyellow>>Install locally')
check_call('pip uninstall pywikibot -y', shell=True)
check_call(
'pip install --no-index --pre --find-links=dist pywikibot',
@@ -159,6 +178,7 @@
Pywikibot i18n files are used for some translations. They are copied
to the pywikibot scripts folder.
"""
+ info('<<lightyellow>>Copy files')
info(f'directory is {self.folder}')
info(f'clear {self.target} directory')
shutil.rmtree(self.target, ignore_errors=True)
@@ -168,16 +188,16 @@
def cleanup(self) -> None:
"""Remove all copied files from pywikibot scripts folder."""
- info('Remove copied files... ', newline=False)
+ info('<<lightyellow>>Remove copied files... ', newline=False)
shutil.rmtree(self.target)
# restore pywikibot en.json file
filename = 'en.json'
self.target.mkdir()
shutil.copy(self.source / filename, self.target / filename)
- info('done')
+ info('<<lightyellow>>done')
-def handle_args() -> Tuple[bool, bool, bool, bool, bool]:
+def handle_args() -> Tuple[bool, bool, bool, bool]:
"""Handle arguments and print documentation if requested.
Read arguments from `sys.argv` and adjust it passing `sdist` to
@@ -187,6 +207,7 @@
uploaded
"""
if '-help' in sys.argv:
+ import setup
info(__doc__)
info(setup.__doc__)
sys.exit()
@@ -200,7 +221,7 @@
warning('Distribution must not be a developmental release to upload.')
remote = False
- sys.argv = [sys.argv[0], 'sdist', 'bdist_wheel']
+ sys.argv = [sys.argv[0]]
return local, remote, clear, upgrade
diff --git a/tests/make_dist_tests.py b/tests/make_dist_tests.py
index 347221e..ef14c98 100755
--- a/tests/make_dist_tests.py
+++ b/tests/make_dist_tests.py
@@ -19,17 +19,11 @@
net = False
- def _test_argv(self):
- """Test argv."""
- self.assertIn('sdist', sys.argv)
- self.assertIn('bdist_wheel', sys.argv)
-
def test_handle_args_empty(self):
"""Test make_dist handle_args function."""
from make_dist import handle_args
args = handle_args()
self.assertEqual(args, (False, ) * 4)
- self._test_argv()
def test_handle_args(self):
"""Test make_dist handle_args function."""
@@ -40,7 +34,6 @@
self.assertEqual(remote, 'dev' not in __version__)
self.assertTrue(clear)
self.assertTrue(upgrade)
- self._test_argv()
if __name__ == '__main__': # pragma: no cover
To view, visit change 914783. To unsubscribe, or for help writing mail filters, visit settings.