jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1328299?usp=email )

Change subject: i18n: Resolve bundle paths from package
......................................................................

i18n: Resolve bundle paths from package

Resolve message bundle directories from the imported messages package
instead of the current working directory. This keeps bundle discovery
working when Pywikibot is launched outside the repository root.

Change-Id: I0748a21810bfef58f9a9d8c18c317c92210813c5
---
M pywikibot/i18n.py
M tests/i18n_tests.py
2 files changed, 25 insertions(+), 3 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 7e776d5..25cd470 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -879,14 +879,17 @@
     >>> path = next(i18n.bundles())
     >>> path.is_dir()
     True
-    >>> path.parent.as_posix()
-    'scripts/i18n'
+    >>> path.is_absolute()
+    True
+    >>> path.parent.name
+    'i18n'

     .. version-added:: 7.0

     :param stem: Yield the Path.stem if True and the Path object otherwise
     """
-    for dirpath in Path(*_messages_package_name.split('.')).iterdir():
+    mod = __import__(_messages_package_name, fromlist=['__path__'])
+    for dirpath in Path(next(iter(mod.__path__))).iterdir():
         if dirpath.is_dir() and not dirpath.match('*__'):  # ignore cache
             if stem:
                 yield dirpath.stem
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index e556fa8..40dcdd1 100755
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -7,6 +7,8 @@
 """Test i18n module."""
 from __future__ import annotations

+import os
+import tempfile
 import unittest
 from contextlib import suppress

@@ -421,6 +423,23 @@
         self.assertEqual(msg, summary + '; kosmetische Änderungen')


+class BundlesTestCase(TestCase):
+
+    """Test message bundle discovery."""
+
+    net = False
+
+    def test_different_working_directory(self) -> None:
+        """Test bundle discovery outside the package parent directory."""
+        old_cwd = os.getcwd()
+        with tempfile.TemporaryDirectory() as directory:
+            try:
+                os.chdir(directory)
+                self.assertIn('pywikibot', i18n.bundles(stem=True))
+            finally:
+                os.chdir(old_cwd)
+
+
 class TestExtractPlural(TestCase):
 
     """Test extracting plurals from a dummy string."""

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1328299?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: I0748a21810bfef58f9a9d8c18c317c92210813c5
Gerrit-Change-Number: 1328299
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[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]

Reply via email to