Skip to content

Commit

Permalink
Fix #93
Browse files Browse the repository at this point in the history
  • Loading branch information
Pebaz committed Jun 14, 2024
1 parent c4265d7 commit 85f97a2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 30 deletions.
29 changes: 16 additions & 13 deletions nimporter/nexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,18 @@ 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+)(-?.+)',
string
)

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 +310,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
63 changes: 47 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,54 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "nimporter"
version = "2.0.0"
version = "2.0.1"
description = "Compile Nim extensions for Python when imported!"
authors = ["Pebaz <https://github.com/Pebaz>", "SekouDiaoNlp <[email protected]>"]
authors = [
"Pebaz <https://github.com/Pebaz>",
"SekouDiaoNlp <[email protected]>",
]
license = "MIT"
keywords = ["nim", "python", "compiler", "import", "performance", "cython", "transpiler", "nimpy", "cython-alternative", "nim-source", "nim-compiler", "nimporter-library"]
classifiers = ["Development Status :: 5 - Production/Stable", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities", "Intended Audience :: Developers", "Intended Audience :: End Users/Desktop", "Intended Audience :: Education", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11",]
keywords = [
"nim",
"python",
"compiler",
"import",
"performance",
"cython",
"transpiler",
"nimpy",
"cython-alternative",
"nim-source",
"nim-compiler",
"nimporter-library",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
homepage = "https://github.com/Pebaz/nimporter"
repository = "https://github.com/Pebaz/nimporter"
documentation = "https://pebaz.github.io/nimporter/index.html"
maintainers = ["Pebaz <https://github.com/Pebaz>", "SekouDiaoNlp <[email protected]>"]
readme = "README.md"
packages = [
{ include = 'nimporter' },
{ include = 'tests', format = 'sdist' },
maintainers = [
"Pebaz <https://github.com/Pebaz>",
"SekouDiaoNlp <[email protected]>",
]
readme = "README.md"
packages = [{ include = 'nimporter' }, { include = 'tests', format = 'sdist' }]
include = [
{ path = 'README.md', format = 'sdist' },
{ path = 'LICENSE', format = 'sdist' },
Expand All @@ -27,18 +60,16 @@ include = [
{ path = '*.sh', format = 'sdist' },
{ path = '*.ps1', format = 'sdist' },
]
exclude = [
{ path = '*.md', format = 'wheel' },
]
exclude = [{ path = '*.md', format = 'wheel' }]

[tool.poetry.scripts]
nimporter = 'nimporter.cli:main'

[tool.poetry.dependencies]
python = "^3.7"
py-cpuinfo = "^9.0.0" # Auto-detect user architecture
icecream = "^2.1.3" # Instrumentation
cookiecutter = "^2.1.1" # Folder structure
py-cpuinfo = "^9.0.0" # Auto-detect user architecture
icecream = "^2.1.3" # Instrumentation
cookiecutter = "^2.1.1" # Folder structure


[tool.poetry.dev-dependencies]
Expand All @@ -60,5 +91,5 @@ files = [
"nimporter/lib.py",
"nimporter/nimporter.py",
"nimporter/nexporter.py",
"nimporter/cli.py"
"nimporter/cli.py",
]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='nimporter',
version='2.0.0',
version='2.0.1',
license='MIT',
description='Compile Nim extensions for Python when imported!',
long_description=io.open('README.md', encoding='utf-8').read(),
Expand Down

0 comments on commit 85f97a2

Please sign in to comment.