Skip to content

Commit 2a2a979

Browse files
committed
Merge pull request #18 from bashtage/setup-cythonize
Setup cythonize
2 parents 68578b1 + 4eb4e2e commit 2a2a979

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

randomstate/src/common/entropy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ bool entropy_getbytes(void *dest, size_t size)
100100
CRYPT_VERIFYCONTEXT) || !hCryptProv) {
101101
return true;
102102
}
103-
done = CryptGenRandom(hCryptProv, size, (unsigned char *)dest);
103+
done = CryptGenRandom(hCryptProv, (DWORD)size, (unsigned char *)dest);
104104
CryptReleaseContext(hCryptProv, 0);
105105
if (!done) {
106106
return false;

setup.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def write_config(file_name, config):
3333
val = '"' + val + '"'
3434
config.write('DEF ' + key + ' = ' + str(val) + '\n')
3535

36+
base_include_dirs = [mod_dir] + [numpy.get_include()]
37+
if os.name == 'nt' and sys.version_info < (3, 5):
38+
base_include_dirs += [join(mod_dir, 'src', 'common')]
39+
3640

3741
for rng in rngs:
3842
if rng not in compile_rngs:
@@ -43,9 +47,7 @@ def write_config(file_name, config):
4347
sources = [join(mod_dir, file_name + '.pyx'),
4448
join(mod_dir, 'src', 'common', 'entropy.c'),
4549
join(mod_dir, 'distributions.c')]
46-
include_dirs = [mod_dir] + [numpy.get_include()]
47-
if os.name == 'nt' and sys.version_info < (3, 5):
48-
include_dirs += [join(mod_dir, 'src', 'common')]
50+
include_dirs = base_include_dirs[:]
4951

5052
if rng == 'RNG_PCG32':
5153
sources += [join(mod_dir, 'src', 'pcg', 'pcg32.c')]
@@ -120,13 +122,13 @@ def write_config(file_name, config):
120122
configs.append(config)
121123

122124
# Generate files and extensions
123-
extensions = cythonize([Extension('randomstate.entropy',
124-
sources=[join(mod_dir, 'entropy.pyx'),
125-
join(mod_dir, 'src', 'common', 'entropy.c')],
126-
include_dirs=config['include_dirs'],
127-
define_macros=extra_defs,
128-
extra_compile_args=extra_compile_args,
129-
extra_link_args=extra_link_args)])
125+
extensions = [Extension('randomstate.entropy',
126+
sources=[join(mod_dir, 'entropy.pyx'),
127+
join(mod_dir, 'src', 'common', 'entropy.c')],
128+
include_dirs=base_include_dirs,
129+
define_macros=extra_defs,
130+
extra_compile_args=extra_compile_args,
131+
extra_link_args=extra_link_args)]
130132

131133
for config in configs:
132134
config_file_name = mod_dir + '/' + config['file_name'] + '-config.pxi'
@@ -142,15 +144,16 @@ def write_config(file_name, config):
142144
write_config(config_file_name, config)
143145
shutil.copystat(join(mod_dir, 'interface.pyx'), config_file_name)
144146

145-
ext = \
146-
cythonize([Extension('randomstate.prng.' + config['file_name'] + '.' + config['file_name'],
147-
sources=config['sources'],
148-
include_dirs=config['include_dirs'],
149-
define_macros=config['defs'] + extra_defs,
150-
extra_compile_args=extra_compile_args,
151-
extra_link_args=extra_link_args)])[0]
147+
ext = Extension('randomstate.prng.' + config['file_name'] + '.' + config['file_name'],
148+
sources=config['sources'],
149+
include_dirs=config['include_dirs'],
150+
define_macros=config['defs'] + extra_defs,
151+
extra_compile_args=extra_compile_args,
152+
extra_link_args=extra_link_args)
152153
extensions.append(ext)
153154

155+
ext_modules = cythonize(extensions)
156+
154157
setup(name='randomstate',
155158
version='0.1',
156159
packages=find_packages(),
@@ -162,7 +165,7 @@ def write_config(file_name, config):
162165
description='Next-gen RandomState supporting multiple PRNGs',
163166
url='https://github.com/bashtage/ng-numpy-randomstate',
164167
long_description=open('README.md').read(),
165-
ext_modules=extensions,
168+
ext_modules=ext_modules,
166169
zip_safe=False)
167170

168171
# Clean up generated files

0 commit comments

Comments
 (0)