diff --git a/nimporter.py b/nimporter.py index c39c080..ebfdd03 100644 --- a/nimporter.py +++ b/nimporter.py @@ -126,7 +126,7 @@ class NimCompiler: '-d:strip', '-d:lto', '-d:ssl' - ] + (['--cc:vcc'] if sys.platform == 'win32' else []) + ] + (['--cc:vcc'] if shutil.which('vccexe') else []) EXT_DIR = 'nim-extensions' @classmethod @@ -313,6 +313,27 @@ def find_nim_std_lib(cls): The Path to the Nim stdlib 'lib' directory if it exists and None otherwise. """ + # If Nim is not installed there's nothing to be done + nimexe = shutil.which('nim') + if not nimexe: + return None + + # Installed via choosenim_install Pypi package + choosenim_dir = Path('~/.choosenim/toolchains').expanduser().absolute() + if choosenim_dir.exists: + try: + nim_ver = (subprocess.check_output(['nim', '-v']) + .decode(errors='ignore') + .splitlines()[0] + ) + + version_string = nim_ver.split()[3] + stdlib = choosenim_dir / f'nim-{version_string}/lib' + + if (stdlib / 'system.nim').exists(): + return stdlib.resolve().absolute() + except: + "Keep trying other methods" # Installed via ChooseNim if shutil.which('choosenim'): @@ -322,20 +343,19 @@ def find_nim_std_lib(cls): (choosenim,) = [i for i in o.splitlines() if 'Path:' in i] toolchain = Path(choosenim.split('Path:').pop().strip()) stdlib = toolchain / 'lib' - if not (stdlib / 'system.nim').exists(): - return None - return stdlib.resolve().absolute() + + if (stdlib / 'system.nim').exists(): + return stdlib.resolve().absolute() # Installed manually - nimexe = shutil.which('nim') - if not nimexe: - return None nimexe = Path(nimexe) result = nimexe.parent / '../lib' if not (result / 'system.nim').exists(): result = nimexe.resolve().parent / '../lib' + if not (result / 'system.nim').exists(): return None + return result.resolve().absolute() @classmethod diff --git a/setup.py b/setup.py index b1b475d..116e636 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ setup( name='nimporter', - version='1.0.3', + version='1.0.4', license="MIT", description='Compile Nim extensions for Python when imported!', long_description=open('README.md').read(), diff --git a/tests/test_build.py b/tests/test_build.py index d644bad..b2b1dd7 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -87,14 +87,20 @@ def test_invoke_compiler_success(): assert any( "Warning: imported and not used: 'asyncstreams'" in i for i in war ) - assert any('Hint: system [Processing]' in i for i in hin) + assert any('Hint' in i for i in hin) finally: if out_file.exists(): out_file.unlink() if sys.platform == 'win32': - Path('tests/pkg1/warn.exp').unlink() - Path('tests/pkg1/warn.lib').unlink() + warn_exp = Path('tests/pkg1/warn.exp') + warn_lib = Path('tests/pkg1/warn.lib') + + if warn_exp.exists(): + warn_exp.unlink() + + if warn_lib.exists(): + warn_lib.unlink() def test_invoke_compiler_failure(): @@ -112,7 +118,7 @@ def test_invoke_compiler_failure(): assert not out_file.exists(), err assert any('Error: cannot open file: fallacy' in i for i in err) - assert any('Hint: system [Processing]' in i for i in hin) + assert any('Hint' in i for i in hin) finally: if out_file.exists(): out_file.unlink()