Skip to content

Commit f206b63

Browse files
committed
remove requirements on cython and jinja2 for build
1 parent 12329b8 commit f206b63

File tree

4 files changed

+59
-53
lines changed

4 files changed

+59
-53
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ luarocks install nn
7575
* Have installed the following python libraries:
7676
```
7777
pip install numpy
78-
pip install Cython
79-
pip install Jinja2
8078
pip install pytest
81-
pip install numpy
8279
pip install python-mnist # used for unit tests
8380
```
8481
- lua51 headers should be installed, ie something like `sudo apt-get install lua5.1 liblua5.1-dev`
@@ -128,6 +125,9 @@ from __future__ import print_function, division
128125

129126
# Recent news
130127

128+
2 March:
129+
* removed requirements on Cython, Jinja2 for installation
130+
131131
28th Februrary:
132132
* builds ok on Mac OS X now :-) See https://travis-ci.org/hughperkins/pytorch/builds/112292866
133133

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
rm -Rf build PyBuild.so dist *.egg-info cbuild
1313
# python setup.py build_ext -i || exit 1
14-
python setup.py cython_only || exit 1
14+
if [[ -v CYTHON ]]; then { python setup.py cython_only || exit 1; } fi
1515
mkdir cbuild
1616
TORCH_INSTALL=$(dirname $(dirname $(which luajit)))
1717
(cd cbuild; cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${TORCH_INSTALL} && make -j 4 install) || exit 1

setup.py

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,52 @@
1717
print('home_dir:', home_dir)
1818

1919
cython_present = False
20-
from Cython.Build import cythonize
21-
cython_present = True
20+
#from Cython.Build import cythonize
21+
#cython_present = True
2222

2323
jinja_present = False
24-
import jinja2
25-
jinja_present = True
26-
27-
# first generate cython pyx from jinja template...
28-
from jinja2 import Environment, PackageLoader, Template
29-
env = Environment(loader=jinja2.FileSystemLoader('.'))
30-
templateNames = [
31-
'src/PyTorch.jinja2.pyx', 'src/Storage.jinja2.pyx', 'src/PyTorch.jinja2.pxd', 'src/nnWrapper.jinja2.cpp', 'src/nnWrapper.jinja2.h',
32-
'test/jinja2.test_pytorch.py', 'src/Storage.jinja2.pxd', 'src/nnWrapper.jinja2.pxd', 'src/lua.jinja2.pxd', 'src/lua.jinja2.pyx']
33-
for templateName in templateNames:
34-
template = env.get_template(templateName)
35-
pyx = template.render(
36-
header='GENERATED FILE, do not edit by hand, ' +
37-
'Source: ' + templateName,
38-
header1='GENERATED FILE, do not edit by hand',
39-
header2='Source: ' + templateName)
40-
outFilename = templateName.replace('.jinja2', '').replace('jinja2.', '')
41-
print('outfilename', outFilename)
42-
isUpdate = True
43-
if os.path.isfile(outFilename):
44-
# read existing file, see if anything changed
45-
f = open(outFilename, 'rb') # binary, so get linux line endings, even on Windows
46-
pyx_current = f.read()
47-
f.close()
48-
if pyx_current == pyx:
49-
isUpdate = False
50-
if isUpdate:
51-
print(outFilename + ' (changed)')
52-
f = open(outFilename, 'wb')
53-
f.write(pyx.encode('utf-8'))
54-
f.close()
24+
#jinja_present = True
5525

26+
running_cython = False
5627
for arg in sys.argv:
5728
if arg in ('cython_only'):
58-
print('cython finished, exiting')
59-
sys.exit(0)
29+
running_cython=True
30+
break
31+
32+
if running_cython:
33+
print('Cythonizing...')
34+
from Cython.Build import cythonize
35+
import jinja2
36+
# first generate cython pyx from jinja template...
37+
from jinja2 import Environment, PackageLoader, Template
38+
env = Environment(loader=jinja2.FileSystemLoader('.'))
39+
templateNames = [
40+
'src/PyTorch.jinja2.pyx', 'src/Storage.jinja2.pyx', 'src/PyTorch.jinja2.pxd', 'src/nnWrapper.jinja2.cpp', 'src/nnWrapper.jinja2.h',
41+
'test/jinja2.test_pytorch.py', 'src/Storage.jinja2.pxd', 'src/nnWrapper.jinja2.pxd', 'src/lua.jinja2.pxd', 'src/lua.jinja2.pyx']
42+
for templateName in templateNames:
43+
template = env.get_template(templateName)
44+
pyx = template.render(
45+
header='GENERATED FILE, do not edit by hand, ' +
46+
'Source: ' + templateName,
47+
header1='GENERATED FILE, do not edit by hand',
48+
header2='Source: ' + templateName)
49+
outFilename = templateName.replace('.jinja2', '').replace('jinja2.', '')
50+
print('outfilename', outFilename)
51+
isUpdate = True
52+
if os.path.isfile(outFilename):
53+
# read existing file, see if anything changed
54+
f = open(outFilename, 'rb') # binary, so get linux line endings, even on Windows
55+
pyx_current = f.read()
56+
f.close()
57+
if pyx_current == pyx:
58+
isUpdate = False
59+
if isUpdate:
60+
print(outFilename + ' (changed)')
61+
f = open(outFilename, 'wb')
62+
f.write(pyx.encode('utf-8'))
63+
f.close()
64+
print('cython finished, exiting')
65+
sys.exit(0)
6066

6167
building_dist = False
6268
for arg in sys.argv:
@@ -121,11 +127,11 @@ def get_file_datetime(filepath):
121127
language="c++")
122128
)
123129

124-
ext_modules = cythonize(ext_modules)
130+
#ext_modules = cythonize(ext_modules)
125131

126132
setup(
127133
name='PyTorch',
128-
version='2.2.0-SNAPSHOT',
134+
version='',
129135
author='Hugh Perkins',
130136
author_email='hughperkins@gmail.com',
131137
description=(
@@ -135,7 +141,7 @@ def get_file_datetime(filepath):
135141
long_description='Python wrappers for torch and nn',
136142
classifiers=[
137143
],
138-
install_requires=['Cython', 'numpy', 'Jinja2'],
144+
install_requires=['numpy'],
139145
scripts=[],
140146
ext_modules=ext_modules,
141147
py_modules=['floattensor', 'PyTorchAug'],

src/PyTorch.cpp

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)