jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1251913?usp=email )
Change subject: dist: Improvements for make_dist script
......................................................................
dist: Improvements for make_dist script
- use the Python interpreter running the script (`sys.executable`)
for calling pip
- uet `WITH_EXTENSION=0` on Windows to force pure-Python tokenizer
for mwparserfromhell.
- Defer final warning until after installer run
- update tests
- Update documentation accordingly
Bug: T420089
Change-Id: I74308a25ed514f8695d632a71dea23c35191eff7
---
M make_dist.py
M tests/make_dist_tests.py
2 files changed, 49 insertions(+), 18 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/make_dist.py b/make_dist.py
index 51f3f2b..e4cc08d 100755
--- a/make_dist.py
+++ b/make_dist.py
@@ -59,6 +59,7 @@
from __future__ import annotations
import abc
+import os
import shutil
import sys
from contextlib import suppress
@@ -70,6 +71,9 @@
from pywikibot import __version__, error, info, input_yn, warning
+pip = f'{sys.executable} -m pip'
+
+
@dataclass
class SetupBase(abc.ABC):
@@ -78,6 +82,9 @@
.. version-added:: 8.0
.. version-changed:: 8.1
*dataclass* is used.
+ .. version-changed:: 11.1
+ Use ``sys.executable`` to determine the Python Python interpreter
+ executing this script.
"""
local: bool
@@ -124,15 +131,15 @@
return True
if self.upgrade: # pragma: no cover
- check_call('python -m pip install --upgrade pip', shell=True)
+ check_call(f'{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)
+ check_call(f'{pip} install {module}', shell=True)
else:
- check_call(f'pip install --upgrade {module}', shell=True)
+ check_call(f'{pip} install --upgrade {module}', shell=True)
else:
for module in ('build', 'twine'):
try:
@@ -147,6 +154,9 @@
"""Build the packages.
.. version-added:: 9.3
+ .. version-changed:: 11.1
+ Use pure-Python implementation of tokenizer for
+ mwparserfromhell with Windows.
"""
self.copy_files()
info('<<lightyellow>>Build package')
@@ -164,9 +174,15 @@
if self.local:
info('<<lightyellow>>Install locally')
- check_call(f'pip uninstall {self.package} -y', shell=True)
- check_call(f'pip install --no-cache-dir --no-index --pre '
- f'--find-links=dist {self.package}', shell=True)
+ check_call(f'{pip} uninstall {self.package} -y', shell=True)
+ env = os.environ.copy()
+ if sys.platform.startswith('win32'):
+ # set the WITH_EXTENSION ennvironment variable for mwpfh;
+ # refer the mwpfh documentation
+ env['WITH_EXTENSION'] = '0'
+ check_call(f'{pip} install --no-cache-dir --pre '
+ f'--find-links=dist {self.package}',
+ shell=True, env=env)
if self.remote and input_yn(
'<<lightblue>>Upload dist to pypi', automatic_quit=False):
@@ -268,20 +284,24 @@
clear = '-clear' in sys.argv
upgrade = '-upgrade' in sys.argv
scripts = 'scripts' in sys.argv
+ msg = ''
if not scripts and remote and 'dev' in __version__: # pragma: no cover
- warning('Distribution must not be a developmental release to upload.')
+ msg = 'Distribution must not be a developmental release to upload.'
remote = False
sys.argv = [sys.argv[0]]
- return local, remote, clear, upgrade, scripts
+ return local, remote, clear, upgrade, scripts, msg
def main() -> None:
"""Script entry point."""
- *args, scripts = handle_args()
+ *args, scripts, msg = handle_args()
installer = SetupScripts if scripts else SetupPywikibot
- return installer(*args).run()
+ done = installer(*args).run()
+ if msg:
+ warning(f'<<lightred>>{msg}<<default>>')
+ return done
if __name__ == '__main__':
diff --git a/tests/make_dist_tests.py b/tests/make_dist_tests.py
index a50908a..5008f6f 100755
--- a/tests/make_dist_tests.py
+++ b/tests/make_dist_tests.py
@@ -24,27 +24,35 @@
def test_handle_args_empty(self) -> None:
"""Test make_dist handle_args function."""
args = make_dist.handle_args()
- self.assertEqual(args, (False, ) * 5)
+ self.assertEqual(args, (False, ) * 5 + ('', ))
def test_handle_args_scripts(self) -> None:
"""Test make_dist handle_args function."""
sys.argv += ['-local', 'scripts', '-remote']
- local, remote, clear, upgrade, scripts = make_dist.handle_args()
+ local, remote, clear, upgrade, scripts, msg = make_dist.handle_args()
self.assertTrue(local)
self.assertTrue(remote)
self.assertFalse(clear)
self.assertFalse(upgrade)
self.assertTrue(scripts)
+ self.assertEqual(msg, '')
def test_handle_args(self) -> None:
"""Test make_dist handle_args function."""
sys.argv += ['-clear', '-local', '-remote', '-upgrade']
- local, remote, clear, upgrade, scripts = make_dist.handle_args()
+ local, remote, clear, upgrade, scripts, msg = make_dist.handle_args()
self.assertTrue(local)
self.assertEqual(remote, 'dev' not in __version__)
self.assertTrue(clear)
self.assertTrue(upgrade)
self.assertFalse(scripts)
+ if 'dev' in __version__:
+ self.assertStartsWith(
+ msg,
+ 'Distribution must not be a developmental release to upload'
+ )
+ else:
+ self.assertEqual(msg, '')
def test_main(self) -> None:
"""Test main result."""
@@ -52,11 +60,14 @@
sys.argv = [*saved_argv, '-clear']
self.assertTrue(make_dist.main())
- # no build or twine modules
- self.assertFalse(make_dist.main())
- sys.argv = [*saved_argv, '-local']
- self.assertFalse(make_dist.main())
- sys.argv = saved_argv
+ try:
+ import build # noqa: autoflake
+ except ModuleNotFoundError:
+ # no build or twine modules
+ self.assertFalse(make_dist.main())
+ sys.argv = [*saved_argv, '-local']
+ self.assertFalse(make_dist.main())
+ sys.argv = saved_argv
if __name__ == '__main__':
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1251913?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I74308a25ed514f8695d632a71dea23c35191eff7
Gerrit-Change-Number: 1251913
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]