diff --git a/CHANGELOG.md b/CHANGELOG.md index 01cb5bf..111c754 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Versions and bullets are arranged chronologically from latest to oldest. +## v0.2.1 + +- Fix bad module name parsing + ## v0.2.0 - Add a new command `upgrade` diff --git a/setup.py b/setup.py index 999f9dc..a5b99fd 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="legunto", - version="0.2.0", + version="0.2.1", description="Fetch MediaWiki Scribunto modules from wikis", long_description=long_description, long_description_content_type="text/markdown", diff --git a/src/scribunto/__init__.py b/src/scribunto/__init__.py index a97aa36..5519cfc 100644 --- a/src/scribunto/__init__.py +++ b/src/scribunto/__init__.py @@ -3,8 +3,7 @@ def search_dependencies(text: str, prefix=None) -> List[str]: - regex = \ - r'''(?:require|mw\.loadData)\s*\(\s*['"](?:[Mm]odule|모듈):(.+)['"]\s*''' + regex = r'''(?:require|mw\.loadData)\s*\(\s*['"](?:[Mm]odule|모듈):([^'"]+)['"]''' # noqa: E501 find = re.findall(regex, text) find = list(set(find)) @@ -19,18 +18,14 @@ def search_dependencies(text: str, prefix=None) -> List[str]: def rewrite_requires(text: str, prefix: str) -> str: # Module:foo/bar -> Module:foo-bar - regex = \ - r'''(?:require|mw\.loadData)\s*\(\s*['"](?:[Mm]odule|모듈):.+['"]\s*''' + regex = r'''(?:require|mw\.loadData)\s*\(\s*['"](?:[Mm]odule|모듈):[^'"]+['"]''' # noqa: E501 module_names = re.findall(regex, text) for name in module_names: text = text.replace(name, name.replace("/", "-")) # Module:foo -> Module:@en/foo - regex = ( - r"""((?:require|mw\.loadData)\s*\(\s*['"](?:[Mm]odule|모듈):)""" - r"""(.+)(['"]\s*)""" - ) + regex = r"""((?:require|mw\.loadData)\s*\(\s*['"](?:[Mm]odule|모듈):)([^'"]+)(['"])""" # noqa: E501 text = re.sub(regex, fr'\1@{prefix}/\2\3', text) diff --git a/test/scribunto_test.py b/test/scribunto_test.py index 3ba5103..ffbccf0 100644 --- a/test/scribunto_test.py +++ b/test/scribunto_test.py @@ -33,6 +33,12 @@ def test_search_dependencies() -> None: assert actual.sort() == expected.sort() + text = 'require("Module:i18n").loadI18n("Module:WikidataIB/i18n", i18n)' + expected = ['@en/i18n'] + actual = scribunto.search_dependencies(text, 'en') + + assert actual == expected + def test_rewrite_requires() -> None: text = '''