From d5b01d6298e4f0f50c15336f195eab5576f02e0f Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 30 Aug 2017 10:33:35 +0200 Subject: [PATCH 1/6] Automatically (re-)configure if Git commits have changed --- .gitignore | 1 + MANIFEST.in | 5 +++-- etc/release/MANIFEST.in.release | 5 ++++- scancode | 25 ++++++++++++++++++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index df3f70056fa..82a8b476b0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # ScanCode special files /SCANCODE_DEV_MODE +/SCANCODE_GIT_MODE # Python compiled files *.py[cod] diff --git a/MANIFEST.in b/MANIFEST.in index 3c1c088160b..d68be2d33d1 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,7 +2,6 @@ graft src graft etc graft thirdparty graft samples - graft tests prune src/scancode_toolkit.egg-info @@ -27,8 +26,10 @@ include scancode include scancode.bat include extractcode include extractcode.bat +include .travis.yml +include appveyor.yml -include .travis.yml appveyor.yml exclude SCANCODE_DEV_MODE +exclude SCANCODE_GIT_MODE global-exclude *.py[co] __pycache__ *.*~ diff --git a/etc/release/MANIFEST.in.release b/etc/release/MANIFEST.in.release index 4168afdafd0..cd3ca1cd12e 100644 --- a/etc/release/MANIFEST.in.release +++ b/etc/release/MANIFEST.in.release @@ -26,7 +26,10 @@ include scancode include scancode.bat include extractcode include extractcode.bat -include .travis.yml appveyor.yml +include .travis.yml +include appveyor.yml exclude SCANCODE_DEV_MODE +exclude SCANCODE_GIT_MODE + global-exclude *.py[co] __pycache__ *.*~ diff --git a/scancode b/scancode index a863caee25e..cf69839728b 100755 --- a/scancode +++ b/scancode @@ -105,10 +105,33 @@ _canonicalize_file_path() { SCANCODE_BIN="$( realpath "${BASH_SOURCE[0]}" )" SCANCODE_ROOT_DIR="$( cd "$( dirname "${SCANCODE_BIN}" )" && pwd )" +SCANCODE_CONFIG_DIR="etc/conf" + +GIT_STATUS=$(git -C "$SCANCODE_ROOT_DIR" status --porcelain 2> /dev/null) +if [ $? -eq 0 ]; then + # This is a Git working tree, check whether it is clean. + if [ -z "$GIT_STATUS" ]; then + # This is a clean working tree, check whether configure has been run + # before for this commit. + GIT_COMMIT_CONFIGURED=$(cat "$SCANCODE_ROOT_DIR/SCANCODE_GIT_MODE" 2> /dev/null) + GIT_COMMIT_HEAD=$(git -C "$SCANCODE_ROOT_DIR" rev-parse HEAD) + if [ "$GIT_COMMIT_CONFIGURED" != "$GIT_COMMIT_HEAD" ]; then + echo "* (Re-)Configuring ScanCode because Git commits have changed..." + CONFIGURE_QUIET=1 $SCANCODE_ROOT_DIR/configure $SCANCODE_CONFIG_DIR + fi + echo $GIT_COMMIT_HEAD > "$SCANCODE_ROOT_DIR/SCANCODE_GIT_MODE" + else + echo "* (Re-)Configuring ScanCode because Git working tree is not clean..." + CONFIGURE_QUIET=1 $SCANCODE_ROOT_DIR/configure $SCANCODE_CONFIG_DIR + fi +else + rm -f "$SCANCODE_ROOT_DIR/SCANCODE_GIT_MODE" +fi + SCANCODE_CONFIGURED_PYTHON=$SCANCODE_ROOT_DIR/bin/python if [ ! -f "$SCANCODE_CONFIGURED_PYTHON" ]; then echo "* Configuring ScanCode for first use..." - CONFIGURE_QUIET=1 $SCANCODE_ROOT_DIR/configure etc/conf + CONFIGURE_QUIET=1 $SCANCODE_ROOT_DIR/configure $SCANCODE_CONFIG_DIR fi $SCANCODE_ROOT_DIR/bin/scancode "$@" From a138c65a93db5f9cc0704c13ecba4d4020d2d6db Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 30 Aug 2017 10:38:43 +0200 Subject: [PATCH 2/6] Do not write a space after ellipses Make this in line with output from the start scripts. --- etc/configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/configure.py b/etc/configure.py index 44cada3448a..8a1e4266923 100644 --- a/etc/configure.py +++ b/etc/configure.py @@ -213,7 +213,7 @@ def create_virtualenv(std_python, root_dir, tpp_dirs, quiet=False): def activate(root_dir): """ Activate a virtualenv in the current process.""" - print("* Activating ...") + print("* Activating...") bin_dir = os.path.join(root_dir, 'bin') activate_this = os.path.join(bin_dir, 'activate_this.py') with open(activate_this) as f: From 5478e650eb2b292e952af86346d531f91f6b6547 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 30 Aug 2017 10:54:51 +0200 Subject: [PATCH 3/6] When configuring, print which config is being used even in quiet mode As there is a subtle difference when running ./configure directly (dev config is being used) and ./configure being run by the scancode script (dev config not being used), print the config being usd in any case. This is usuall is just two lines and does not really clutter the output. --- etc/configure.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etc/configure.py b/etc/configure.py index 8a1e4266923..6eee4426462 100644 --- a/etc/configure.py +++ b/etc/configure.py @@ -365,6 +365,8 @@ def get_conf_files(config_dir_paths, root_dir, file_names=requirements): abs_path = os.path.join(root_dir, path) if os.path.exists(abs_path): configs.append(path) + print('Using configuration directory:\n' + ' %(path)s' % locals()) else: print() print('WARNING: Skipping missing Configuration directory:\n' From 24f125da0800b04b0bd85304451314b138615bbf Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 30 Aug 2017 11:12:08 +0200 Subject: [PATCH 4/6] Move the comment about development mode to the SCANCODE_DEV_MODE file This way the explanation is also visible without looking at the source code. --- etc/conf/dev/base.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/etc/conf/dev/base.py b/etc/conf/dev/base.py index 31c5fa3a1e6..ba4435f6afe 100644 --- a/etc/conf/dev/base.py +++ b/etc/conf/dev/base.py @@ -7,14 +7,11 @@ def setup_dev_mode(): - """ - Create the development mode tag file. In development mode, ScanCode does - not rely on license data to remain untouched and will always check the - license index cache for consistency, rebuilding it if necessary. - """ from scancode import root_dir with open(os.path.join(root_dir, 'SCANCODE_DEV_MODE'), 'wb') as sdm: - sdm.write('This is a tag file to notify that ScanCode is used in development mode.') + sdm.write('This is a tag file to notify that ScanCode is used in development mode. ' + 'In this mode, ScanCode does not rely on license data to remain untouched and will ' + 'always check the license index cache for consistency, rebuilding it if necessary.') setup_dev_mode() From 773bffab3219b491e6763e7f1ea2b025ee168eef Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 30 Aug 2017 11:18:06 +0200 Subject: [PATCH 5/6] Remove any stale development tag file from previous configure runs --- etc/conf/base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/etc/conf/base.py b/etc/conf/base.py index 6f1b431d30a..1e7d8617bdd 100644 --- a/etc/conf/base.py +++ b/etc/conf/base.py @@ -43,6 +43,21 @@ def unsupported(platform): unsupported(os + arch) +def clear_dev_mode(): + """ + Remove any stale development tag file from previous configure runs. + """ + import os + from scancode import root_dir + try: + os.remove(os.path.join(root_dir, 'SCANCODE_DEV_MODE')) + except OSError: + pass + + +clear_dev_mode() + + """ Re/build the license cache on every configure run. """ From c95017a319b8b7ebe87c4a777bb425929a89ac39 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 30 Aug 2017 11:21:47 +0200 Subject: [PATCH 6/6] Do not shadow the os package with a variable name --- etc/conf/base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/etc/conf/base.py b/etc/conf/base.py index 1e7d8617bdd..9222e4e3cea 100644 --- a/etc/conf/base.py +++ b/etc/conf/base.py @@ -23,11 +23,11 @@ def unsupported(platform): sys_platform = str(sys.platform).lower() if 'linux' in sys_platform: - os = 'linux' + platform = 'linux' elif'win32' in sys_platform: - os = 'win' + platform = 'win' elif 'darwin' in sys_platform: - os = 'mac' + platform = 'mac' else: unsupported(sys_platform) @@ -38,9 +38,9 @@ def unsupported(platform): 'mac': ['64',], } -arches = supported_combos[os] +arches = supported_combos[platform] if arch not in arches: - unsupported(os + arch) + unsupported(platform + arch) def clear_dev_mode():