From 1f200671321894dcf3737b6455a7962db3e65fe5 Mon Sep 17 00:00:00 2001 From: Pebaz Date: Fri, 14 Jun 2024 01:26:42 -0400 Subject: [PATCH] Fix #95 --- nimporter/nexporter.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/nimporter/nexporter.py b/nimporter/nexporter.py index 46360bc..9064cfe 100644 --- a/nimporter/nexporter.py +++ b/nimporter/nexporter.py @@ -256,22 +256,17 @@ def compile_extensions_to_c(platforms: List[str], root: Path) -> None: prevent_win32_max_path_length_error(out_dir) return - -def _is_valid_identifier(string: str) -> Union[Match[str], None, bool]: - import re - match = re.search('^[A-Za-z_][A-Z-a-z0-9_\\-]*', string) - return match and len(match.string) == len(string) - - def _is_semver(string: str) -> bool: + import re try: - lib_name, lib_version = string.rsplit('-', maxsplit=1) - assert _is_valid_identifier(lib_name) + match = re.search( + r'(\w+)-(?\d+)\.(?\d+)\.(?\d+)(-?.+)' + ) - major, minor, patch = lib_version.split('.') - assert major.isdigit() - assert minor.isdigit() - assert patch.isdigit() + groups = match.groupdict() + assert groups['major'].isdigit() + assert groups['minor'].isdigit() + assert groups['patch'].isdigit() return True except: @@ -314,6 +309,13 @@ def prevent_win32_max_path_length_error(path: Path) -> None: mod_name = '@'.join(segments[index:]) break + # Local imports which don't include a semver + else: + mod_name = item.name.replace('@m', '') + new_name = ic(f'NIMPORTER@{mod_name}') + assert not item.with_name(new_name).exists(), ( + f"Bug with @ replacements: {new_name} shouldn't already exist" + ) item.replace(item.with_name(new_name)) return