Following the mega-linter contribution guidelines on a Ubuntu 18.04 system I ran into some errors which I'd like to address:
A) Install dev-requirements with --user
option by default:
The sequence to install the pre-requisites:
python3 -m pip install -U pip
python3 -m pip install -r requirements.dev.txt
could be improved with the --user
option:
python3 -m pip install --user -U pip # update pip
python3 -m pip install --user -r requirements.dev.txt # install development requirements
B) Align python3 usage in build.sh
with installing the pre-requisites
The build.sh
script is using python
not python3
to run the build script on line 6 leading to a syntax error:
$ bash build.sh
bash build.sh
File "./.automation/build.py", line 47
f"{REPO_HOME}/megalinter/descriptors/schemas/megalinter-descriptor.jsonschema.json"
^
SyntaxError: invalid syntax
This could be improved by testing if python3 command is available and use it when. Otherwise keep the existing behavior and use the python command:
if type python3 >/dev/null 2>/dev/null; then
python3 ./.automation/build.py
else
python ./.automation/build.py
fi
C) Force property of logging in build script throw ValueError Exception
$ bash build.sh
bash build.sh
Traceback (most recent call last):
File "./.automation/build.py", line 1782, in <module>
handlers=[logging.StreamHandler(sys.stdout)],
File "/usr/lib/python3.6/logging/__init__.py", line 1829, in basicConfig
raise ValueError('Unrecognised argument(s): %s' % keys)
ValueError: Unrecognised argument(s): force
This could be improved by catching the ValueError and repeat without force (I could not figure out the required version nor which module that actually is):
build.py 1783 ff:
try:
logging.basicConfig(
force=True,
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[logging.StreamHandler(sys.stdout)],
)
except ValueError:
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[logging.StreamHandler(sys.stdout)],
)
D) Build script generates white-space errors
Many text files in the repository are missing a newline at the end of file. Some of them are generated by build script.
This could be improved by adding the missing newlines and fixing build script to add them as well (which I could try for the case of adding one linter, other scenarios might reveal more which is to be seen).
E) YAML was out of date
My systems YAML extension in Python was not compatible with the build script leading to errors:
$ bash build.sh
Traceback (most recent call last):
File "./.automation/build.py", line 1786, in <module>
collect_linter_previews()
File "./.automation/build.py", line 1610, in collect_linter_previews
linters = megalinter.linter_factory.list_all_linters()
File "/home/mot/PhpstormProjects/mega-linter/megalinter/linter_factory.py", line 31, in list_all_linters
descriptor_file, linters_init_params
File "/home/mot/PhpstormProjects/mega-linter/megalinter/linter_factory.py", line 61, in build_descriptor_linters
language_descriptor = yaml.load(f, Loader=yaml.FullLoader)
AttributeError: module 'yaml' has no attribute 'FullLoader'
I could fix this issue by upgrading it (from 3.12 to latest):
$ python3 -m pip install --user -U PyYAML
Requirement already satisfied: PyYAML in /usr/lib/python3/dist-packages (3.12)
Collecting PyYAML
Downloading PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl (640 kB)
|ββββββββββββββββββββββββββββββββ| 640 kB 7.0 MB/s
Installing collected packages: PyYAML
Successfully installed PyYAML-5.4.1
An improvement could be to document this for the requirements or if the minimum version (which I don't know what it is) of PyYAML for FullLoader is known, to add it to the dev-requirements.txt file so that doing the pre-requisites already covers this.