Skip to content

Commit

Permalink
Fix #95
Browse files Browse the repository at this point in the history
  • Loading branch information
Pebaz committed Jun 14, 2024
1 parent c4265d7 commit 1f20067
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions nimporter/nexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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+)-(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\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:
Expand Down Expand Up @@ -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

0 comments on commit 1f20067

Please sign in to comment.