From 8ae0f203f2f7f6918605bcfa69d79169419cd2be Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Sun, 2 Sep 2018 15:54:18 +1000 Subject: [PATCH] Move to python3.7 - Now getting python packages using pip instead of the ubuntu versions. - System wide installations now aren't supported. --- README.md | 2 +- TODO | 5 ++++ appimage/AppRun | 2 +- install-dependencies | 4 +-- install-tools | 10 +++---- make-appimage.py | 2 +- make-readme.py | 4 +-- setup.py | 2 +- test_distributions.py | 2 +- tests/__main___test.py | 2 +- tests/fill3_test.py | 2 +- tests/golden-files/results/pylint-hi3_py | 1 - tests/gut_test.py | 2 +- tests/lscolors_test.py | 2 +- tests/termstr_test.py | 2 +- tests/tools_test.py | 2 +- tests/worker_test.py | 2 +- vigil/__main__.py | 2 +- vigil/gut.py | 2 +- vigil/tools.py | 37 +++++++++++------------- vigil/webserver.py | 2 +- vigil/worker.py | 2 +- 22 files changed, 46 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 25b2a2d..0aead0f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Vigil maintains an up-to-date set of reports for every file in a codebase. # git clone https://github.com/ahamilton/vigil # cd vigil # ./install-dependencies - # pip3 install . + # python3.7 -m pip install . To test its working properly: diff --git a/TODO b/TODO index d3de03f..de1da5d 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,9 @@ Todo - Publish on pypi. +- Make a snap build work. +- Make a flatpak build work. +- Check the appimage build. +- Rename project to Eris. Todo (tool related) @@ -167,6 +171,7 @@ Done - Add cppcheck tool for C and C++. - Add shellcheck tool for shell scripts. - Add "git log ". +- Change to using python3.7. A-syntax, B-tests, C-auto docs, D-lint, E-coverage, F-profile, G-tidy, H-import deps A B C D E F G H diff --git a/appimage/AppRun b/appimage/AppRun index 9ad2e51..2fa6541 100755 --- a/appimage/AppRun +++ b/appimage/AppRun @@ -13,7 +13,7 @@ export PATH="${HERE}"/usr/bin/:"${HERE}"/usr/local/bin/:"${PATH}" export UNION_PRELOAD="${HERE}" export LD_PRELOAD="${HERE}/libunionpreload.so" export LD_LIBRARY_PATH="${HERE}"/usr/lib/:"${HERE}"/usr/lib/i386-linux-gnu/:"${HERE}"/usr/lib/x86_64-linux-gnu/:"${HERE}"/usr/lib32/:"${HERE}"/usr/lib64/:"${HERE}"/lib/:"${HERE}"/lib/i386-linux-gnu/:"${HERE}"/lib/x86_64-linux-gnu/:"${HERE}"/lib32/:"${HERE}"/lib64/:"${LD_LIBRARY_PATH}" -export PYTHONPATH=/usr/local/lib/python3.6/dist-packages:"${PYTHONPATH}" +export PYTHONPATH=/usr/local/lib/python3.7/dist-packages:"${PYTHONPATH}" if [ -z $APPIMAGE_ENTER ]; then EXEC=$(grep -e '^Exec=.*' "${HERE}"/*.desktop | head -n 1 | cut -d "=" -f 2- | sed -e 's|%.||g') exec ${EXEC} $@ diff --git a/install-dependencies b/install-dependencies index ba9ea7c..407571c 100755 --- a/install-dependencies +++ b/install-dependencies @@ -13,8 +13,8 @@ if [ $DIST_ID != "ubuntu" ]; then exit 1 fi echo "Installing the dependencies of the vigil script..." -sudo apt --yes install python3-pyinotify python3-pygments python3-docopt \ - python3-pillow util-linux python3-toml +sudo apt --yes install python3.7 util-linux +python3.7 -m pip install pyinotify pygments docopt pillow toml echo echo "Installing all the tools vigil may need..." ./install-tools diff --git a/install-tools b/install-tools index 44e4829..7f0916c 100755 --- a/install-tools +++ b/install-tools @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. @@ -17,14 +17,12 @@ for dependency in vigil.tools.dependencies(): dist_deps.add(dependency) if pip_deps: dist_deps.add("python-pip") -if pip3_deps: - dist_deps.add("python3-pip") if dist_deps: subprocess.run(["sudo", "apt-get", "-y", "install"] + list(dist_deps), check=True) if pip_deps: - subprocess.run(["sudo", "pip", "install"] + list(pip_deps), + subprocess.run(["python", "-m", "pip", "install"] + list(pip_deps), check=True) if pip3_deps: - subprocess.run(["sudo", "pip3", "install"] + list(pip3_deps), - check=True) + subprocess.run(["python" + vigil.tools.PYTHON_VERSION, "-m", "pip", + "install"] + list(pip3_deps), check=True) diff --git a/make-appimage.py b/make-appimage.py index 1133bcc..e8530bb 100755 --- a/make-appimage.py +++ b/make-appimage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/make-readme.py b/make-readme.py index 4af7bf0..f86ac28 100755 --- a/make-readme.py +++ b/make-readme.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # -*- coding: utf-8 -*- # Copyright (C) 2018 Andrew Hamilton. All rights reserved. @@ -35,7 +35,7 @@ Vigil maintains an up-to-date set of reports for every file in a codebase. # git clone https://github.com/ahamilton/vigil # cd vigil # ./install-dependencies - # pip3 install . + # python3.7 -m pip install . To test its working properly: diff --git a/setup.py b/setup.py index 0f8c71c..5affdf0 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/test_distributions.py b/test_distributions.py index f6f8d97..03826b8 100755 --- a/test_distributions.py +++ b/test_distributions.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/tests/__main___test.py b/tests/__main___test.py index ca56482..7467615 100755 --- a/tests/__main___test.py +++ b/tests/__main___test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2015-2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/tests/fill3_test.py b/tests/fill3_test.py index 292f4fa..d4934e9 100755 --- a/tests/fill3_test.py +++ b/tests/fill3_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # -*- coding: utf-8 -*- # Copyright (C) 2015-2018 Andrew Hamilton. All rights reserved. diff --git a/tests/golden-files/results/pylint-hi3_py b/tests/golden-files/results/pylint-hi3_py index b00b628..e69de29 100644 --- a/tests/golden-files/results/pylint-hi3_py +++ b/tests/golden-files/results/pylint-hi3_py @@ -1 +0,0 @@ -No config file found, using default configuration \ No newline at end of file diff --git a/tests/gut_test.py b/tests/gut_test.py index 68e04aa..e6248c1 100755 --- a/tests/gut_test.py +++ b/tests/gut_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2015-2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/tests/lscolors_test.py b/tests/lscolors_test.py index 064fa2f..7242294 100755 --- a/tests/lscolors_test.py +++ b/tests/lscolors_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2011, 2015-2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/tests/termstr_test.py b/tests/termstr_test.py index b283201..2f00e77 100755 --- a/tests/termstr_test.py +++ b/tests/termstr_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2015-2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/tests/tools_test.py b/tests/tools_test.py index b7a9590..7597651 100755 --- a/tests/tools_test.py +++ b/tests/tools_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/tests/worker_test.py b/tests/worker_test.py index 3189eab..01c44c5 100755 --- a/tests/worker_test.py +++ b/tests/worker_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/vigil/__main__.py b/vigil/__main__.py index 87d2f2a..1620036 100755 --- a/vigil/__main__.py +++ b/vigil/__main__.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # -*- coding: utf-8 -*- # Copyright (C) 2015-2018 Andrew Hamilton. All rights reserved. diff --git a/vigil/gut.py b/vigil/gut.py index 8c8ec9f..f0b904c 100755 --- a/vigil/gut.py +++ b/vigil/gut.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2015-2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/vigil/tools.py b/vigil/tools.py index 94491a8..e064337 100644 --- a/vigil/tools.py +++ b/vigil/tools.py @@ -9,6 +9,8 @@ import contextlib import enum import functools import gzip +import importlib +import importlib.resources import math import os import os.path @@ -26,12 +28,15 @@ import pygments.lexers import pygments.styles import toml +import vigil import vigil.fill3 as fill3 import vigil.gut as gut import vigil.lscolors as lscolors import vigil.termstr as termstr +PYTHON_VERSION = "3.7" +PYTHON_EXECUTABLE = "python" + PYTHON_VERSION CACHE_PATH = ".vigil" @@ -235,7 +240,7 @@ def metadata(path): return (Status.normal, fill3.Text(fill3.join("", text))) -@deps(deps={"python3-pygments"}, url="python3-pygments") +@deps(deps={"pip3/pygments"}, url="python3-pygments") def contents(path): with open(path) as file_: try: @@ -267,10 +272,10 @@ def _is_python_syntax_correct(path, python_version): def _python_version(path): # Need a better hueristic - for version in ["python3", "python"]: + for version in [PYTHON_EXECUTABLE, "python"]: if _is_python_syntax_correct(path, version): return version - return "python3" + return PYTHON_EXECUTABLE @deps(deps={"python"}, @@ -330,7 +335,7 @@ def _colorize_coverage_report(text): for line in text.splitlines(keepends=True)]) -@deps(deps={"python-coverage", "python3-coverage"}, url="python3-coverage") +@deps(deps={"pip/coverage", "pip3/coverage"}, url="python3-coverage") def python_coverage(path): # FIX: Also use test_*.py files. test_path = path[:-(len(".py"))] + "_test.py" @@ -355,24 +360,22 @@ def python_coverage(path): "No corresponding test file: " + os.path.normpath(test_path)) -@deps(deps={"python-pycodestyle", "python3-pycodestyle"}, - url="python-pycodestyle") +@deps(deps={"pip/pycodestyle", "pip3/pycodestyle"}, url="python-pycodestyle") def pycodestyle(path): return _run_command([_python_version(path), "-m", "pycodestyle", path]) -@deps(deps={"pydocstyle", "python3-pydocstyle"}, - url="python3-pydocstyle") +@deps(deps={"pip/pydocstyle", "pip3/pydocstyle"}, url="python3-pydocstyle") def pydocstyle(path): return _run_command([_python_version(path), "-m", "pydocstyle", path]) -@deps(deps={"python-pyflakes", "python3-pyflakes"}, url="pyflakes") +@deps(deps={"pip/pyflakes", "pip3/pyflakes"}, url="pyflakes") def pyflakes(path): return _run_command([_python_version(path), "-m", "pyflakes", path]) -@deps(deps={"pylint", "pylint3"}, url="pylint3") +@deps(deps={"pip/pylint", "pip3/pylint"}, url="pylint3") def pylint(path): return _run_command([_python_version(path), "-m", "pylint", "--errors-only", path]) @@ -402,7 +405,7 @@ def dis(path): def _get_mccabe_line_score(line, python_version): position, function_name, score = line.split() - return int(score if python_version == "python3" else score[:-1]) + return int(score if python_version == PYTHON_EXECUTABLE else score[:-1]) def _colorize_mccabe(text, python_version): @@ -412,7 +415,7 @@ def _colorize_mccabe(text, python_version): for line in text.splitlines(keepends=True)]) -@deps(deps={"python-mccabe", "python3-mccabe"}, url="python3-mccabe") +@deps(deps={"pip/mccabe", "pip3/mccabe"}, url="python3-mccabe") def python_mccabe(path): python_version = _python_version(path) stdout, *rest = _do_command([python_version, "-m", "mccabe", path]) @@ -424,11 +427,6 @@ def python_mccabe(path): return status, fill3.Text(_colorize_mccabe(stdout, python_version)) -def python_tidy(path): # Deps: found on internet? - stdout, *rest = _do_command(["python", "python-tidy.py", path]) - return Status.normal, _syntax_highlight_using_path(stdout, path) - - # FIX: Reenable when pydisasm is not causing problems # @deps(deps={"pip3/xdis"}, executables={"pydisasm"}, # url="https://pypi.python.org/pypi/xdis") @@ -437,7 +435,7 @@ def python_tidy(path): # Deps: found on internet? # Status.not_applicable) -@deps(deps={"python-bandit", "python3-bandit"}, url="python3-bandit") +@deps(deps={"pip/bandit", "pip3/bandit"}, url="python3-bandit") def bandit(path): python_version = _python_version(path) stdout, stderr, returncode = _do_command( @@ -597,8 +595,7 @@ def make_tool_function(dependencies, url, command, success_status=None, return func -tools_toml_path = os.path.join(os.path.dirname(__file__), "tools.toml") -with open(tools_toml_path) as tools_toml_file: +with importlib.resources.open_text(vigil, "tools.toml") as tools_toml_file: tools_toml = toml.load(tools_toml_file) tools_for_extensions = tools_toml["tools_for_extensions"] del tools_toml["tools_for_extensions"] diff --git a/vigil/webserver.py b/vigil/webserver.py index ed66d5b..215ab39 100755 --- a/vigil/webserver.py +++ b/vigil/webserver.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0. diff --git a/vigil/worker.py b/vigil/worker.py index bde396e..174bca8 100755 --- a/vigil/worker.py +++ b/vigil/worker.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.6 +#!/usr/bin/env python3.7 # Copyright (C) 2015-2018 Andrew Hamilton. All rights reserved. # Licensed under the Artistic License 2.0.