Skip to content

Commit a0faf6c

Browse files
committed
Fixed #445 and $453
* Update the configure script so that it doesn't restrict to python27 on windows * Update the configure script so that it won't activate itself * Update README doc for the instruction to activate and deactivate the virtualenv
1 parent 666cc88 commit a0faf6c

File tree

3 files changed

+141
-50
lines changed

3 files changed

+141
-50
lines changed

README.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ or on windows:
6565
configure
6666

6767

68+
Activate the virtualenv
69+
-----------------------
70+
To activate the virtualenv, run (on posix):
71+
source bin/activate
72+
or on windows:
73+
bin\activate
74+
75+
76+
Deactivate the virtualenv
77+
-------------------------
78+
To deactivate the virtualenv, run (on both posix and windows):
79+
deactivate
80+
81+
6882
VERSIONING SCHEMA
6983
-----------------
7084
Starting at AboutCode version 4.0.0, the AboutCode Toolkit will follow SemVer for the versioning schema.

configure

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2015 nexB Inc. http://www.nexb.com/ - All rights reserved.
3+
# Copyright (c) nexB Inc. http://www.nexb.com/ - All rights reserved.
44
#
5+
6+
set -e
7+
8+
if [[ "$OS" == "Windows_NT" ]]; then
9+
echo "You seem to be running on Windows under Cygwin / MSYS(2), like e.g. Git for Windows Bash. This script does"
10+
echo "not properly work in this scenario. As a Windows user, please run 'configure.bat' from a regular command"
11+
echo "prompt instead."
12+
exit 1
13+
fi
14+
515
################################
616
# change these variables to customize this script locally
717
################################
@@ -10,6 +20,8 @@ export TPP_DIR="thirdparty"
1020

1121
# default configurations
1222
CONF_DEFAULT="etc/conf"
23+
24+
1325
#################################
1426

1527
CFG_CMD_LINE_ARGS="$@"
@@ -26,3 +38,5 @@ if [[ "$PYTHON_EXE" == "" ]]; then
2638
fi
2739

2840
$PYTHON_EXE "$CONFIGURE_ROOT_DIR/etc/configure.py" $CFG_CMD_LINE_ARGS
41+
42+
set +e

configure.bat

Lines changed: 111 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,127 @@
11
@echo OFF
2-
3-
@rem Copyright (c) 2018 nexB Inc. http://www.nexb.com/ - All rights reserved.
2+
@setlocal
3+
@rem Copyright (c) nexB Inc. http://www.nexb.com/ - All rights reserved.
44

55
@rem ################################
6-
@rem # change these variables to customize this script locally
6+
@rem # A configuration script for Windows
7+
@rem #
8+
@rem # The options and (optional) arguments are:
9+
@rem # --clean : this is exclusive of anything else and cleans the environment
10+
@rem # from built and installed files
11+
@rem #
12+
@rem # --python < path to python.exe> : this must be the first argument and set
13+
@rem # the path to the Python executable to use. If < path to python.exe> is
14+
@rem # set to "path", then the executable will be the python.exe available
15+
@rem # in the PATH.
16+
@rem #
17+
@rem # <some conf path> : this must be the last argument and sets the path to a
18+
@rem # configuration directory to use.
719
@rem ################################
8-
@rem # you can define one or more thirdparty dirs, each prefixed with TPP_DIR
9-
set TPP_DIR=thirdparty
1020

21+
@rem ################################
22+
@rem # Defaults. Change these variables to customize this script locally
23+
@rem ################################
24+
@rem # you can define one or more thirdparty dirs, each where the varibale name
25+
@rem # is prefixed with TPP_DIR
26+
set "TPP_DIR=thirdparty"
1127

1228
@rem # default configurations
13-
set CONF_DEFAULT="etc/conf"
29+
set "CONF_DEFAULT=etc/conf"
30+
31+
@rem # default supported version for Python 3
32+
set SUPPORTED_PYTHON3=3.6
33+
1434
@rem #################################
1535

16-
set ABOUT_ROOT_DIR=%~dp0
17-
@rem !!!!!!!!!!! ATTENTION !!!!!
18-
@rem there is a space at the end of the set SCANCODE_CLI_ARGS= line ...
19-
@rem NEVER remove this!
20-
@rem otherwise, this script and scancode do not work.
21-
22-
set ABOUT_CLI_ARGS=
23-
@rem Collect/Slurp all command line arguments in a variable
24-
:collectarg
25-
if ""%1""=="""" (
26-
goto continue
27-
)
28-
call set ABOUT_CLI_ARGS=%ABOUT_CLI_ARGS% %1
29-
shift
30-
goto collectarg
31-
32-
:continue
33-
34-
@rem default configuration when no args are passed
35-
if "%ABOUT_CLI_ARGS%"==" " (
36-
set ABOUT_CLI_ARGS="%CONF_DEFAULT%"
37-
goto configure
36+
@rem python --version
37+
@rem python -c "import sys;print(sys.executable)"
38+
39+
40+
@rem Current directory where this .bat files lives
41+
set CFG_ROOT_DIR=%~dp0
42+
43+
@rem path where a configured Python should live in the current virtualenv if installed
44+
set CONFIGURED_PYTHON=%CFG_ROOT_DIR%Scripts\python.exe
45+
46+
set PYTHON_EXECUTABLE=
47+
48+
@rem parse command line options and arguments
49+
:collectopts
50+
if "%1" EQU "--help" (goto cli_help)
51+
if "%1" EQU "--clean" (set CFG_CMD_LINE_ARGS=--clean) && goto find_python
52+
if "%1" EQU "--python" (set PROVIDED_PYTHON=%~2) && shift && shift && goto collectopts
53+
54+
@rem We are not cleaning: Either we have a provided configure config path or we use a default.
55+
if ""%1""=="""" (
56+
set CFG_CMD_LINE_ARGS=%CONF_DEFAULT%
57+
) else (
58+
set CFG_CMD_LINE_ARGS=%1
3859
)
3960

40-
:configure
41-
if not exist "c:\python27\python.exe" (
42-
echo(
43-
echo On Windows, AboutCode requires Python 2.7.x 32 bits to be installed first.
44-
echo(
45-
echo Please download and install Python 2.7 ^(Windows x86 MSI installer^) version 2.7.10.
46-
echo Install Python on the c: drive and use all default installer options.
47-
echo Do NOT install Python v3 or any 64 bits edition.
48-
echo Instead download Python from this url and see the README.rst file for more details:
49-
echo(
50-
echo https://www.python.org/ftp/python/2.7.15/python-2.7.15.msi
51-
echo(
52-
exit /b 1
61+
@rem If we have a pre-configured Python in our virtualenv, reuse this as-is and run
62+
if exist ""%CONFIGURED_PYTHON%"" (
63+
set PYTHON_EXECUTABLE=%CONFIGURED_PYTHON%
64+
goto run
5365
)
5466

55-
call c:\python27\python.exe "%ABOUT_ROOT_DIR%etc\configure.py" %ABOUT_CLI_ARGS%
56-
if %errorlevel% neq 0 (
57-
exit /b %errorlevel%
67+
@rem If we have a command arg for Python use this as-is
68+
if ""%PROVIDED_PYTHON%""==""path"" (
69+
@rem use a bare python available in the PATH
70+
set PYTHON_EXECUTABLE=python
71+
goto run
5872
)
59-
if exist "%SCANCODE_ROOT_DIR%bin\activate" (
60-
"%SCANCODE_ROOT_DIR%bin\activate"
73+
if exist ""%PROVIDED_PYTHON%"" (
74+
set PYTHON_EXECUTABLE=%PROVIDED_PYTHON%
75+
goto run
76+
)
77+
78+
79+
@rem otherwise we search for a suitable Python interpreter
80+
:find_python
81+
82+
@rem First check the existence of the "py" launcher (available in Python 3)
83+
@rem if we have it, check if we have a py -3 installed with the good version or a py 2.7
84+
@rem if not, check if we have an old py 2.7
85+
@rem exist if all fails
86+
87+
where py >nul 2>nul
88+
if %ERRORLEVEL% == 0 (
89+
@rem we have a py launcher, check for the availability of our required Python 3 version
90+
py -3.6 --version >nul 2>nul
91+
if %ERRORLEVEL% == 0 (
92+
set PYTHON_EXECUTABLE=py -3.6
93+
) else (
94+
@rem we have no required python 3, let's try python 2:
95+
py -2 --version >nul 2>nul
96+
if %ERRORLEVEL% == 0 (
97+
set PYTHON_EXECUTABLE=py -2
98+
) else (
99+
@rem we have py and no python 3 and 2, exit
100+
echo * Unable to find an installation of Python.
101+
exit /b 1
102+
)
103+
)
104+
) else (
105+
@rem we have no py launcher, check for a default Python 2 installation
106+
if not exist ""%DEFAULT_PYTHON2%"" (
107+
echo * Unable to find an installation of Python.
108+
exit /b 1
109+
) else (
110+
set PYTHON_EXECUTABLE=%DEFAULT_PYTHON2%
111+
)
112+
)
113+
114+
:run
115+
116+
@rem without this things may not always work on Windows 10, but this makes things slower
117+
set PYTHONDONTWRITEBYTECODE=1
118+
119+
call %PYTHON_EXECUTABLE% "%CFG_ROOT_DIR%etc\configure.py" %CFG_CMD_LINE_ARGS%
120+
121+
122+
@rem Return a proper return code on failure
123+
if %ERRORLEVEL% neq 0 (
124+
exit /b %ERRORLEVEL%
61125
)
62-
goto EOS
126+
endlocal
63127

64-
:EOS

0 commit comments

Comments
 (0)