Skip to content

Commit 18960e9

Browse files
committed
Merge pull request winpython#10 from stonebig/better_R
Better r
2 parents 39a5cb4 + 2bbbbf3 commit 18960e9

1 file changed

Lines changed: 73 additions & 22 deletions

File tree

make.py

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def __init__(self, build_number, release_level, target, instdir,
158158
@property
159159
def package_index_wiki(self):
160160
"""Return Package Index page in Wiki format"""
161-
installed_tools = [('gettext', '0.14.4'), ('SciTE', '3.3.7')]
161+
installed_tools = [('gettext', '0.14.4'), ('SciTE', '3.3.7')]
162162

163163
def get_tool_path(relpath, checkfunc):
164164
if self.simulation:
@@ -228,7 +228,7 @@ def winpy_arch(self):
228228
def pyqt_arch(self):
229229
"""Return distribution architecture, in PyQt format: x32/x64"""
230230
return 'x%d' % self.distribution.architecture
231-
231+
232232
@property
233233
def py_arch(self):
234234
"""Return distribution architecture, in Python distutils format:
@@ -297,7 +297,7 @@ def create_batch_script(self, name, contents):
297297
fd = open(osp.join(scriptdir, name), 'w')
298298
fd.write(contents)
299299
fd.close()
300-
300+
301301
def create_launcher(self, name, icon, command=None,
302302
args=None, workdir=None, settingspath=None):
303303
"""Create exe launcher with NSIS"""
@@ -453,7 +453,7 @@ def _install_required_packages(self):
453453
'PyQwt-([0-9\.]*)-py%s-%s-([a-z0-9\.\-]*).exe'
454454
% (self.python_version, self.pyqt_arch))
455455

456-
# Install 'main packages' first (was before Wheel idea, keep for now)
456+
# Install 'main packages' first (was before Wheel idea, keep for now)
457457
for happy_few in['numpy-MKL', 'scipy', 'matplotlib', 'pandas']:
458458
self.install_package(
459459
'%s-([0-9\.]*[a-z]*[0-9]?).%s(-py%s)?.exe'
@@ -636,38 +636,88 @@ def _create_batch_scripts(self):
636636
cmd.exe /k
637637
""")
638638

639+
640+
self.create_batch_script('Add_or_removeLine.vbs',r"""
641+
'from http://blogs.technet.com/b/heyscriptingguy/archive/2007/09/07/
642+
' how-can-i-remove-any-line-in-a-text-file-that-contains-a-specified-string-value.aspx
643+
If WScript.Arguments.Count <> 3 then
644+
WScript.Echo "usage: Add_or_removeLine.vbs filename word_to_find line_to_add" &_
645+
vbNewLine & "or Add_or_removeLine.vbs filename word_to_find -remove"
646+
WScript.Quit
647+
end If
648+
649+
Set colArgs = WScript.Arguments
650+
Add_or_removeLine colArgs(0), colArgs(1), colArgs(2)
651+
652+
function Add_or_removeLine(strFilename, strFind, strAction)
653+
Set inputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strFilename, 1)
654+
a_change = False
655+
Do Until inputFile.AtEndOfStream
656+
strLine = inputFile.ReadLine
657+
If InStr(strLine, strFind) = 0 Then
658+
result_text= result_text & strLine & vbNewLine
659+
else
660+
a_change = True
661+
if strAction <> "-remove" then result_text= result_text & strLine & vbNewLine & strAction & vbNewLine
662+
End If
663+
Loop
664+
inputFile.Close
665+
666+
if a_change then
667+
Set outputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strFilename,2,true)
668+
outputFile.Write result_text
669+
outputFile.Close
670+
end if
671+
end function
672+
""")
673+
639674
self.create_batch_script('start_with_r.bat', r"""@echo off
640675
call %~dp0env.bat
641676
642677
rem ******************
643678
rem R part (supposing you install it in \tools\R of winpython)
644679
rem ******************
645680
set tmp_Rdirectory=R
646-
if not exist "%WINPYDIR%\..\tools\%tmp_Rdirectory%\bin" goto r_end
681+
if not exist "%WINPYDIR%\..\tools\%tmp_Rdirectory%\bin" goto r_bad
647682
648683
rem R_HOME for rpy2, R_HOMEBIN for PATH
649684
set R_HOME=%WINPYDIR%\..\tools\%tmp_Rdirectory%\
650685
set R_HOMEbin=%WINPYDIR%\..\tools\%tmp_Rdirectory%\bin
651686
652-
653687
set SYS_PATH=%PATH%
654688
set PATH=%SYS_PATH%;%R_HOMEbin%
655689
656690
echo "r!"
657-
echo "if you want it to be on your winpython icon, update %WINPYDIR%\settings\winpython.ini with"
658-
echo "PATH=%path%"
659-
echo " "
660-
echo to launch Ipython with R, type now "Ipython notebook"
661-
rem Ipython notebook
691+
echo "We are going to update %WINPYDIR%\settings\winpython.ini with"
692+
echo "R_HOME = %R_HOME%"
693+
echo "(relaunch this batch, if you move your winpython)"
694+
pause
662695
663-
:r_end
696+
%~dp0Add_or_removeLine.vbs ..\settings\winpython.ini "R_HOME = " -remove
664697
665-
cmd.exe /k
698+
rem Handle case when winpython.ini is not already created
699+
if exist "..\settings\winpython.ini" goto ini_exists
700+
701+
echo [debug]>"..\settings\winpython.ini"
702+
echo state = disabled>>"..\settings\winpython.ini"
703+
echo [environment]>>"..\settings\winpython.ini"
704+
705+
:ini_exists
706+
%~dp0Add_or_removeLine.vbs ..\settings\winpython.ini "[environment]" "R_HOME = %R_HOME%"
707+
goto r_end
708+
709+
:r_bad
710+
711+
echo directory "%WINPYDIR%\..\tools\%tmp_Rdirectory%\bin" not found
712+
echo please install R at "%WINPYDIR%\..\tools\%tmp_Rdirectory%"
713+
pause
714+
715+
:r_end
666716
""")
667717
# Prepare a live patch on python (shame we need it) to have mingw64ok
668718
patch_distutils = ""
669719
if self.py_arch == "win-amd64":
670-
patch_distutils=r"""
720+
patch_distutils = r"""
671721
%~dp0Find_And_replace.vbs "%WINPYDIR%\Lib\distutils\cygwinccompiler.py" "-O -W" "-O -DMS_WIN64 -W"
672722
673723
set WINPYXX=%WINPYVER:~0,1%%WINPYVER:~2,1%
@@ -690,8 +740,9 @@ def _create_batch_scripts(self):
690740
..\tools\mingw32\bin\dlltool -D python%WINPYXX%.dll -d python%WINPYXX%.def -l libpython%WINPYXX%.dll.a
691741
move /Y libpython%WINPYXX%.dll.a libs
692742
del python%WINPYXX%.def
693-
"""
694-
self.create_batch_script('Find_And_replace.vbs',r"""
743+
"""
744+
745+
self.create_batch_script('Find_And_replace.vbs', r"""
695746
' from http://stackoverflow.com/questions/15291341/
696747
' a-batch-file-to-read-a-file-and-replace-a-string-with-a-new-one
697748
@@ -714,7 +765,7 @@ def _create_batch_scripts(self):
714765
outputFile.Write result_text
715766
outputFile.Close
716767
Set outputFile = Nothing
717-
end if
768+
end if
718769
end function
719770
""")
720771

@@ -777,9 +828,9 @@ def _create_batch_scripts(self):
777828
workdir=r'Lib\site-packages\PyQt4\examples\demos\qtdemo')
778829

779830
# pre-run wingw batch
780-
print ('now pre-running extra mingw')
831+
print('now pre-running extra mingw')
781832
filepath = osp.join(self.winpydir, 'scripts', 'make_cython_use_mingw.bat')
782-
p = subprocess.Popen(filepath, shell=True, stdout = subprocess.PIPE)
833+
p = subprocess.Popen(filepath, shell=True, stdout=subprocess.PIPE)
783834
stdout, stderr = p.communicate()
784835

785836
self._print_done()
@@ -837,12 +888,12 @@ def make(self, remove_existing=True):
837888
if not self.simulation:
838889
self._create_launchers()
839890
self._create_batch_scripts()
840-
891+
841892
if remove_existing and not self.simulation:
842893
self._print("Cleaning up distribution")
843894
self.distribution.clean_up()
844895
self._print_done()
845-
896+
846897
# Writing package index
847898
self._print("Writing package index")
848899
fname = osp.join(self.winpydir, os.pardir,
@@ -946,7 +997,7 @@ def make_all(build_number, release_level, pyver,
946997

947998
#make_all(1, '', pyver='3.4', rootdir=r'D:\Winpython',
948999
# verbose=False, archis=(32, ))
949-
make_all(2, '', pyver='3.4', rootdir=r'D:\Winpython',
1000+
make_all(1, '', pyver='3.4', rootdir=r'D:\Winpython',
9501001
verbose=False, archis=(64, ))
9511002
#make_all(2, '', pyver='3.3', rootdir=r'D:\Winpython',
9521003
# verbose=False, archis=(32, ))

0 commit comments

Comments
 (0)