Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Python 3 support #58

Merged
merged 2 commits into from
Apr 3, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions nodeenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ def writefile(dest, content, overwrite=True, append=False):
f = open(dest, 'rb')
c = f.read()
f.close()
if c != content:
if c != content.encode('utf-8'):
if not overwrite:
logger.info(' * File %s exists with different content; '
' not overwriting', dest)
return
if append:
logger.info(' * Appending nodeenv settings to %s', dest)
f = open(dest, 'a')
f = open(dest, 'ab')
f.write(DISABLE_POMPT.encode('utf-8'))
f.write(content.encode('utf-8'))
f.write(ENABLE_PROMPT.encode('utf-8'))
Expand Down Expand Up @@ -374,6 +374,25 @@ def install_node(env_dir, src_dir, opt):
for name, value in zip(make_param_names, make_param_values)
if value is not None]

if sys.version_info.major > 2:
# Currently, the node.js build scripts are using python2.*, therefore
# we need to temporarily point python exec to the python 2.* version
# in this case.
try:
_, which_python2_output = callit(['which', 'python2'])
python2_path = which_python2_output[0].decode('utf-8')
except (OSError, IndexError):
raise OSError('Python >=3.0 virtualenv detected, but no python2'
' command (required for building node.js) was found')
logger.debug(' * Temporarily pointing python to %s', python2_path)
node_tmpbin_dir = join(src_dir, 'tmpbin')
node_tmpbin_link = join(node_tmpbin_dir, 'python')
mkdir(node_tmpbin_dir)
if not os.path.exists(node_tmpbin_link):
callit(['ln', '-s', python2_path, node_tmpbin_link])
env['PATH'] = '{}:{}'.format(node_tmpbin_dir,
os.environ.get('PATH', ''))

conf_cmd = []
conf_cmd.append('./configure')
conf_cmd.append('--prefix=%s' % pipes.quote(env_dir))
Expand Down