Skip to content

Commit

Permalink
Merge pull request #29 from editorconfig-checker/general-improvements
Browse files Browse the repository at this point in the history
General improvements
  • Loading branch information
mmicu authored Oct 8, 2023
2 parents b3e3a39 + e83a750 commit b6c9ad2
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 59 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
_*.sh
_*.txt
.DS_Store
.pre-commit-config.yaml
*.bak
*.egg-info
*.pyc
Expand All @@ -11,4 +12,6 @@ bin/
build/
dist/
examples/
issues/
misc/
venv/
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"cSpell.ignoreWords": [
"aarch",
"cmdclass",
"outfiles",
"pypi"
],
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true
}
7 changes: 5 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
87 changes: 47 additions & 40 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 16 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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'


Expand Down Expand Up @@ -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')

Expand All @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions tests/Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ LABEL maintainer="Marco M. (mmicu) <[email protected]>"
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
1 change: 0 additions & 1 deletion tests/requirements.txt

This file was deleted.

0 comments on commit b6c9ad2

Please sign in to comment.