diff --git a/.gitignore b/.gitignore index bec120d..be73e67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -.DS_Store _*.sh _*.txt +.DS_Store +.pre-commit-config.yaml *.bak *.egg-info *.pyc @@ -11,4 +12,6 @@ bin/ build/ dist/ examples/ +issues/ +misc/ venv/ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7f44661 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "cSpell.ignoreWords": [ + "aarch", + "cmdclass", + "outfiles", + "pypi" + ], + "files.trimFinalNewlines": true, + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true +} diff --git a/LICENSE b/LICENSE index 907ccc0..7754bd9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,9 @@ -The MIT License (MIT) +Original "https://github.com/shellcheck-py/shellcheck-py" Project License +========================================================================= -Copyright (c) 2019 Marco M. +MIT License + +Copyright (c) 2019 Ryan Rhee Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/run-tests.sh b/run-tests.sh index 502b91c..029e14e 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -2,57 +2,64 @@ set -e -PY_DOCKER_IMAGES=("2.7.16-slim" "3.7.4-slim") DOCKERFILE_TEMPLATE="tests/Dockerfile.template" -PACKAGES=() +PY_DOCKER_IMAGES=() +PY_DOCKER_IMAGES+=("2.7.16-slim") +PY_DOCKER_IMAGES+=("3.7.4-slim") +PY_DOCKER_IMAGES+=("3.8-slim") +PY_DOCKER_IMAGES+=("3.9-slim") +PY_DOCKER_IMAGES+=("3.10-slim") +PY_DOCKER_IMAGES+=("3.11-slim") -# Install packages from sources -PACKAGES+=(".") -# PyPI package -PACKAGES+=("editorconfig-checker") +create_docker_file() { + local package="$1" -echo -e "Running tests...\n\n" + # Generate a valid Dockerfile from a template file + local dockerfile="tests/Dockerfile-$py_docker_image-$package" + cp "$DOCKERFILE_TEMPLATE" "$dockerfile" -for py_docker_image in "${PY_DOCKER_IMAGES[@]}"; do - for package in "${PACKAGES[@]}"; do - is_local="0" - if [[ "$package" == "." ]]; then - package_pp="local" - is_local="1" - elif [[ "$package" == "editorconfig-checker" ]]; then - package_pp="pypi" - else - echo "Unknown package '$package'. Valid values are '.' and 'editorconfig-checker'." - exit 1 - fi + # Replace docker image + sed -i "s/\$IMAGE/$py_docker_image/g" "$dockerfile" - echo "docker image: $py_docker_image ~ package: $package ($package_pp)" + # Replace package name + if [[ "$package" == "local" ]]; then + package="." + fi + sed -i "s/\$PACKAGE/$package/g" "$dockerfile" - # Generate a valid Dockerfile from a template file - dockerfile="tests/Dockerfile-$py_docker_image-$package_pp" - cp "$DOCKERFILE_TEMPLATE" "$dockerfile" - sed -i "s/\$IMAGE/$py_docker_image/g" "$dockerfile" - sed -i "s/\$PACKAGE/$package/g" "$dockerfile" + echo "$dockerfile" +} - echo "Building docker image based on \"$dockerfile\". It could take some time..." +build_docker_image_and_run() { + local py_docker_image="$1" + local package="$2" + local dockerfile="$3" - # Build & run - docker_image="editorconfig-checker-$py_docker_image-$package_pp:latest" - docker build -t "$docker_image" -f "$dockerfile" --no-cache --quiet . - docker run --rm "$docker_image" + # Build + local docker_image="editorconfig-checker-$py_docker_image-$package:latest" + docker build -t "$docker_image" -f "$dockerfile" --no-cache --quiet . - # Run coding style tools - if [[ "$is_local" == "1" ]]; then - docker run --rm "$docker_image" make coding-style - fi + # Run `editorconfig-checker` + docker run --rm "$docker_image" ec -version +} - # Run `editorconfig-checker` - docker run --rm "$docker_image" ec -version +main() { + echo -e "Running tests...\n\n" - # Remove the created image - docker image rm "$docker_image" &> /dev/null + for py_docker_image in "${PY_DOCKER_IMAGES[@]}"; do + for package in local editorconfig-checker; do + local dockerfile=$(create_docker_file "$package") + echo "Dockerfile created at \"$dockerfile\" (\"$py_docker_image\" image and \"$package\" package)" - echo -e "\n" + echo "Building docker image. It could take some time..." + build_docker_image_and_run "$py_docker_image" "$package" "$dockerfile" + + # docker image rm "$docker_image" &> /dev/null + + echo -e "\n" + done done -done +} + +main diff --git a/setup.py b/setup.py index 7aabada..053c8fd 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- """ -This setup logic is highly ispired to the one used in `https://github.com/shellcheck-py/shellcheck-py`. +This setup logic is highly inspired to the one used in `https://github.com/shellcheck-py/shellcheck-py`. After `https://github.com/editorconfig-checker/editorconfig-checker.python/issues/15` was opened, we decided to move the wrapper logic directly in the setup phase. @@ -13,15 +13,16 @@ Once the setup is complete, the `ec` executable should be available on your machine. """ -from io import BytesIO from distutils.command.build import build as orig_build from distutils.core import Command +from io import BytesIO from os import chmod, makedirs, path, stat from platform import architecture, machine, system +from stat import S_IXGRP, S_IXOTH, S_IXUSR +from tarfile import open as tarfile_open + from setuptools import setup from setuptools.command.install import install as orig_install -from stat import S_IXUSR, S_IXGRP, S_IXOTH -from tarfile import open as tarfile_open try: # Python 3 @@ -31,8 +32,8 @@ from urllib2 import urlopen -WRAPPER_VERSION = '2.7.2' -EDITORCONFIG_CHECKER_CORE_VERSION = '2.7.0' +WRAPPER_VERSION = '2.7.3' +EDITORCONFIG_CHECKER_CORE_VERSION = '2.7.1' EDITORCONFIG_CHECKER_EXE_NAME = 'ec' @@ -88,10 +89,10 @@ def download_tarball(url): def extract_tarball(url, data): with BytesIO(data) as bio: if '.tar.' in url: - with tarfile_open(fileobj=bio) as tarf: - for info in tarf.getmembers(): + with tarfile_open(fileobj=bio) as fp: + for info in fp.getmembers(): if info.isfile() and info.name.startswith('bin/ec-'): - return tarf.extractfile(info).read() + return fp.extractfile(info).read() raise AssertionError('unreachable `extract` function') @@ -102,7 +103,12 @@ def save_executables(data, base_dir): exe += '.exe' output_path = path.join(base_dir, exe) - makedirs(base_dir) + try: + # Python 3 + makedirs(base_dir, exist_ok=True) + except TypeError: + # Python 2.7 + makedirs(base_dir) with open(output_path, 'wb') as fp: fp.write(data) diff --git a/tests/Dockerfile.template b/tests/Dockerfile.template index 3e18d77..92d8138 100644 --- a/tests/Dockerfile.template +++ b/tests/Dockerfile.template @@ -6,9 +6,7 @@ LABEL maintainer="Marco M. (mmicu) " COPY . /app WORKDIR /app -RUN set -x \ - && apt-get update \ - && apt-get install -y make \ - && python -m pip install --upgrade pip \ - && pip install -r tests/requirements.txt \ +RUN apt-get update \ + && apt-get install -y make \ + && python -m pip install --upgrade pip \ && pip install --no-cache-dir $PACKAGE diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index 3930480..0000000 --- a/tests/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -flake8