Skip to content

Commit 0da4030

Browse files
committed
Windows compat, at least for unparsing and actually loading the package.
1 parent c2a9e2b commit 0da4030

2 files changed

Lines changed: 48 additions & 16 deletions

File tree

transpyle/configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
LOGTS_PATHS = {
2828
'Linux': pathlib.Path('~', '.local', 'share', APP_DIRNAME),
2929
'Darwin': pathlib.Path('~', 'Library', 'Logs', APP_DIRNAME),
30-
# TODO: where to store logs on Windows?
31-
# 'Windows': pathlib.Path('%LOCALAPPDATA%', APP_DIRNAME)
30+
# TODO: where to store logs on Windows? AppData is a fair target, there is no real better option there: https://docs.microsoft.com/en-us/windows/desktop/shell/csidl or https://docs.microsoft.com/en-us/windows/desktop/shell/knownfolderid
31+
'Windows': pathlib.Path('%LOCALAPPDATA%', APP_DIRNAME)
3232
}
3333

3434
LOGS_PATH = LOGTS_PATHS[platform.system()]

transpyle/cpp/compiler_interface.py

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@ class GppInterface(CompilerInterface):
2828
'MPI': pathlib.Path('mpic++')
2929
}
3030

31+
compile_flags = tuple()
32+
33+
# Config does not always contain these items (eg. on Windows)
34+
35+
if 'BASECFLAGS' in PYTHON_CONFIG:
36+
compile_flags = tuple(split_and_strip('{} {}'.format(compile_flags,PYTHON_CONFIG['BASECFLAGS'])))
37+
38+
if 'BASECPPFLAGS' in PYTHON_CONFIG:
39+
compile_flags = tuple(split_and_strip('{} {}'.format(compile_flags,PYTHON_CONFIG['BASECPPFLAGS'])))
40+
3141
_flags = {
3242
'': ('-O3', '-fPIC', '-Wall', '-Wextra', '-Wpedantic', '-fdiagnostics-color=always'),
33-
'compile': tuple(split_and_strip('{} {}'.format(
34-
PYTHON_CONFIG['BASECFLAGS'], PYTHON_CONFIG['BASECPPFLAGS']))),
43+
'compile': compile_flags,
3544
'link': (),
3645
'OpenMP': ('-fopenmp',)
3746
}
@@ -41,13 +50,20 @@ class GppInterface(CompilerInterface):
4150
pathlib.Path(PYTHON_CONFIG['INCLUDEPY']),
4251
*[pathlib.Path(_, 'core', 'include') for _ in np.__path__]]
4352

44-
library_paths = [
45-
pathlib.Path(PYTHON_CONFIG['LIBDIR'])]
53+
library_paths = []
54+
if 'LIBDIR' in PYTHON_CONFIG:
55+
library_paths.append(pathlib.Path(PYTHON_CONFIG['LIBDIR']))
4656

47-
ldlibrary = pathlib.Path(PYTHON_CONFIG['LDLIBRARY'].lstrip('lib')).with_suffix('')
57+
if 'LDLIBRARY' in PYTHON_CONFIG:
58+
ldlibrary = pathlib.Path(PYTHON_CONFIG['LDLIBRARY'].lstrip('lib')).with_suffix('')
59+
else:
60+
ldlibrary = None
4861

49-
libraries = split_and_strip('-l{} {} {} {}'.format(
50-
ldlibrary, PYTHON_CONFIG['LIBS'], PYTHON_CONFIG['SYSLIBS'], PYTHON_CONFIG['LINKFORSHARED']))
62+
if 'LIBS' in PYTHON_CONFIG and 'SYSLIBS' in PYTHON_CONFIG and 'LINKFORSHARED' in PYTHON_CONFIG:
63+
libraries = split_and_strip('-l{} {} {} {}'.format(
64+
ldlibrary, PYTHON_CONFIG['LIBS'], PYTHON_CONFIG['SYSLIBS'], PYTHON_CONFIG['LINKFORSHARED']))
65+
else:
66+
libraries = []
5167

5268
_options = {
5369
'compile': ['-I{}'.format(_) for _ in include_paths],
@@ -63,10 +79,19 @@ class ClangppInterface(CompilerInterface):
6379

6480
_executables = {'': pathlib.Path('clang++')}
6581

82+
compile_flags = tuple()
83+
84+
# Config does not always contain these items (eg. on Windows)
85+
86+
if 'BASECFLAGS' in PYTHON_CONFIG:
87+
compile_flags = tuple(split_and_strip('{} {}'.format(compile_flags, PYTHON_CONFIG['BASECFLAGS'])))
88+
89+
if 'BASECPPFLAGS' in PYTHON_CONFIG:
90+
compile_flags = tuple(split_and_strip('{} {}'.format(compile_flags, PYTHON_CONFIG['BASECPPFLAGS'])))
91+
6692
_flags = {
6793
'': ('-O3', '-fPIC', '-Wall', '-Wextra', '-Wpedantic', '-fcolor-diagnostics'),
68-
'compile': tuple(split_and_strip('{} {}'.format(
69-
PYTHON_CONFIG['BASECFLAGS'], PYTHON_CONFIG['BASECPPFLAGS']))),
94+
'compile': compile_flags,
7095
'OpenMP': ('-fopenmp',)
7196
}
7297
# -Ofast
@@ -75,13 +100,20 @@ class ClangppInterface(CompilerInterface):
75100
pathlib.Path(PYTHON_CONFIG['INCLUDEPY']),
76101
*[pathlib.Path(_, 'core', 'include') for _ in np.__path__]]
77102

78-
library_paths = [
79-
pathlib.Path(PYTHON_CONFIG['LIBDIR'])]
103+
library_paths = []
104+
if 'LIBDIR' in PYTHON_CONFIG:
105+
library_paths.append(pathlib.Path(PYTHON_CONFIG['LIBDIR']))
80106

81-
ldlibrary = pathlib.Path(PYTHON_CONFIG['LDLIBRARY'].lstrip('lib')).with_suffix('')
107+
if 'LDLIBRARY' in PYTHON_CONFIG:
108+
ldlibrary = pathlib.Path(PYTHON_CONFIG['LDLIBRARY'].lstrip('lib')).with_suffix('')
109+
else:
110+
ldlibrary = None
82111

83-
libraries = split_and_strip('-l{} {} {} {}'.format(
84-
ldlibrary, PYTHON_CONFIG['LIBS'], PYTHON_CONFIG['SYSLIBS'], PYTHON_CONFIG['LINKFORSHARED']))
112+
if 'LIBS' in PYTHON_CONFIG and 'SYSLIBS' in PYTHON_CONFIG and 'LINKFORSHARED' in PYTHON_CONFIG:
113+
libraries = split_and_strip('-l{} {} {} {}'.format(
114+
ldlibrary, PYTHON_CONFIG['LIBS'], PYTHON_CONFIG['SYSLIBS'], PYTHON_CONFIG['LINKFORSHARED']))
115+
else:
116+
libraries = []
85117

86118
_options = {
87119
'compile': ['-I{}'.format(_) for _ in include_paths],

0 commit comments

Comments
 (0)