jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] use dataclasses with make_dist.py; Python 3.7+ required

Change-Id: I1450bc103ac7899436bc3cdbfa53b382dd393004
---
M make_dist.py
M tests/make_dist_tests.py
2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/make_dist.py b/make_dist.py
index 45d64b7..1fca5b1 100755
--- a/make_dist.py
+++ b/make_dist.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-"""Script to create a new distribution.
+"""Script to create a new distribution. Requires Python 3.7+.

The following options are supported:

@@ -37,6 +37,7 @@
- *nodist* option was added

.. versionchanged:: 8.1
+ Python 3.7+ required because *dataclasses* module is used.
*nodist* option was removed, *clear* option does not create a
distribution. *local* and *remote* option clears old distributions
first.
@@ -49,6 +50,7 @@
import abc
import shutil
import sys
+from dataclasses import dataclass, field
from pathlib import Path
from subprocess import check_call, run

@@ -57,19 +59,24 @@
from pywikibot.backports import Tuple


+@dataclass
class SetupBase(abc.ABC):

"""Setup distribution base class.

.. versionadded:: 8.0
+ .. versionchanged:: 8.1
+ *dataclass* is used.
"""

- def __init__(self, local, remote, clear, upgrade) -> None:
- """Initializer."""
- self.local = local
- self.remote = remote
- self.clear = clear
- self.upgrade = upgrade
+ local: bool
+ remote: bool
+ clear: bool
+ upgrade: bool
+ folder: Path = field(init=False)
+
+ def __post_init__(self) -> None:
+ """Post-init initializer."""
self.folder = Path().resolve()

def clear_old_dist(self) -> None: # pragma: no cover
diff --git a/tests/make_dist_tests.py b/tests/make_dist_tests.py
index 264e634..1a79759 100755
--- a/tests/make_dist_tests.py
+++ b/tests/make_dist_tests.py
@@ -9,11 +9,11 @@
import sys
import unittest

-from make_dist import handle_args
from pywikibot import __version__
-from tests.aspects import TestCase
+from tests.aspects import TestCase, require_modules


+@require_modules('dataclasses') # Python 3.7+
class TestMakeDist(TestCase):

"""Test the make_dist script."""
@@ -29,12 +29,14 @@

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."""
+ from make_dist import handle_args
sys.argv += ['-clear', '-local', '-remote', '-upgrade']
local, remote, clear, upgrade = handle_args()
self.assertTrue(local)

To view, visit change 904176. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I1450bc103ac7899436bc3cdbfa53b382dd393004
Gerrit-Change-Number: 904176
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged