Skip to content

Commit b6c9ad2

Browse files
authored
Merge pull request #29 from editorconfig-checker/general-improvements
General improvements
2 parents b3e3a39 + e83a750 commit b6c9ad2

7 files changed

Lines changed: 86 additions & 59 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
.DS_Store
21
_*.sh
32
_*.txt
3+
.DS_Store
4+
.pre-commit-config.yaml
45
*.bak
56
*.egg-info
67
*.pyc
@@ -11,4 +12,6 @@ bin/
1112
build/
1213
dist/
1314
examples/
15+
issues/
16+
misc/
1417
venv/

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"cSpell.ignoreWords": [
3+
"aarch",
4+
"cmdclass",
5+
"outfiles",
6+
"pypi"
7+
],
8+
"files.trimFinalNewlines": true,
9+
"files.insertFinalNewline": true,
10+
"files.trimTrailingWhitespace": true
11+
}

LICENSE

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
The MIT License (MIT)
1+
Original "https://github.com/shellcheck-py/shellcheck-py" Project License
2+
=========================================================================
23

3-
Copyright (c) 2019 Marco M.
4+
MIT License
5+
6+
Copyright (c) 2019 Ryan Rhee
47

58
Permission is hereby granted, free of charge, to any person obtaining a copy
69
of this software and associated documentation files (the "Software"), to deal

run-tests.sh

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,64 @@
22

33
set -e
44

5-
PY_DOCKER_IMAGES=("2.7.16-slim" "3.7.4-slim")
65
DOCKERFILE_TEMPLATE="tests/Dockerfile.template"
76

8-
PACKAGES=()
7+
PY_DOCKER_IMAGES=()
8+
PY_DOCKER_IMAGES+=("2.7.16-slim")
9+
PY_DOCKER_IMAGES+=("3.7.4-slim")
10+
PY_DOCKER_IMAGES+=("3.8-slim")
11+
PY_DOCKER_IMAGES+=("3.9-slim")
12+
PY_DOCKER_IMAGES+=("3.10-slim")
13+
PY_DOCKER_IMAGES+=("3.11-slim")
914

10-
# Install packages from sources
11-
PACKAGES+=(".")
12-
# PyPI package
13-
PACKAGES+=("editorconfig-checker")
15+
create_docker_file() {
16+
local package="$1"
1417

15-
echo -e "Running tests...\n\n"
18+
# Generate a valid Dockerfile from a template file
19+
local dockerfile="tests/Dockerfile-$py_docker_image-$package"
20+
cp "$DOCKERFILE_TEMPLATE" "$dockerfile"
1621

17-
for py_docker_image in "${PY_DOCKER_IMAGES[@]}"; do
18-
for package in "${PACKAGES[@]}"; do
19-
is_local="0"
20-
if [[ "$package" == "." ]]; then
21-
package_pp="local"
22-
is_local="1"
23-
elif [[ "$package" == "editorconfig-checker" ]]; then
24-
package_pp="pypi"
25-
else
26-
echo "Unknown package '$package'. Valid values are '.' and 'editorconfig-checker'."
27-
exit 1
28-
fi
22+
# Replace docker image
23+
sed -i "s/\$IMAGE/$py_docker_image/g" "$dockerfile"
2924

30-
echo "docker image: $py_docker_image ~ package: $package ($package_pp)"
25+
# Replace package name
26+
if [[ "$package" == "local" ]]; then
27+
package="."
28+
fi
29+
sed -i "s/\$PACKAGE/$package/g" "$dockerfile"
3130

32-
# Generate a valid Dockerfile from a template file
33-
dockerfile="tests/Dockerfile-$py_docker_image-$package_pp"
34-
cp "$DOCKERFILE_TEMPLATE" "$dockerfile"
35-
sed -i "s/\$IMAGE/$py_docker_image/g" "$dockerfile"
36-
sed -i "s/\$PACKAGE/$package/g" "$dockerfile"
31+
echo "$dockerfile"
32+
}
3733

38-
echo "Building docker image based on \"$dockerfile\". It could take some time..."
34+
build_docker_image_and_run() {
35+
local py_docker_image="$1"
36+
local package="$2"
37+
local dockerfile="$3"
3938

40-
# Build & run
41-
docker_image="editorconfig-checker-$py_docker_image-$package_pp:latest"
42-
docker build -t "$docker_image" -f "$dockerfile" --no-cache --quiet .
43-
docker run --rm "$docker_image"
39+
# Build
40+
local docker_image="editorconfig-checker-$py_docker_image-$package:latest"
41+
docker build -t "$docker_image" -f "$dockerfile" --no-cache --quiet .
4442

45-
# Run coding style tools
46-
if [[ "$is_local" == "1" ]]; then
47-
docker run --rm "$docker_image" make coding-style
48-
fi
43+
# Run `editorconfig-checker`
44+
docker run --rm "$docker_image" ec -version
45+
}
4946

50-
# Run `editorconfig-checker`
51-
docker run --rm "$docker_image" ec -version
47+
main() {
48+
echo -e "Running tests...\n\n"
5249

53-
# Remove the created image
54-
docker image rm "$docker_image" &> /dev/null
50+
for py_docker_image in "${PY_DOCKER_IMAGES[@]}"; do
51+
for package in local editorconfig-checker; do
52+
local dockerfile=$(create_docker_file "$package")
53+
echo "Dockerfile created at \"$dockerfile\" (\"$py_docker_image\" image and \"$package\" package)"
5554

56-
echo -e "\n"
55+
echo "Building docker image. It could take some time..."
56+
build_docker_image_and_run "$py_docker_image" "$package" "$dockerfile"
57+
58+
# docker image rm "$docker_image" &> /dev/null
59+
60+
echo -e "\n"
61+
done
5762
done
58-
done
63+
}
64+
65+
main

setup.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
"""
5-
This setup logic is highly ispired to the one used in `https://github.com/shellcheck-py/shellcheck-py`.
5+
This setup logic is highly inspired to the one used in `https://github.com/shellcheck-py/shellcheck-py`.
66
77
After `https://github.com/editorconfig-checker/editorconfig-checker.python/issues/15` was opened,
88
we decided to move the wrapper logic directly in the setup phase.
@@ -13,15 +13,16 @@
1313
Once the setup is complete, the `ec` executable should be available on your machine.
1414
"""
1515

16-
from io import BytesIO
1716
from distutils.command.build import build as orig_build
1817
from distutils.core import Command
18+
from io import BytesIO
1919
from os import chmod, makedirs, path, stat
2020
from platform import architecture, machine, system
21+
from stat import S_IXGRP, S_IXOTH, S_IXUSR
22+
from tarfile import open as tarfile_open
23+
2124
from setuptools import setup
2225
from setuptools.command.install import install as orig_install
23-
from stat import S_IXUSR, S_IXGRP, S_IXOTH
24-
from tarfile import open as tarfile_open
2526

2627
try:
2728
# Python 3
@@ -31,8 +32,8 @@
3132
from urllib2 import urlopen
3233

3334

34-
WRAPPER_VERSION = '2.7.2'
35-
EDITORCONFIG_CHECKER_CORE_VERSION = '2.7.0'
35+
WRAPPER_VERSION = '2.7.3'
36+
EDITORCONFIG_CHECKER_CORE_VERSION = '2.7.1'
3637
EDITORCONFIG_CHECKER_EXE_NAME = 'ec'
3738

3839

@@ -88,10 +89,10 @@ def download_tarball(url):
8889
def extract_tarball(url, data):
8990
with BytesIO(data) as bio:
9091
if '.tar.' in url:
91-
with tarfile_open(fileobj=bio) as tarf:
92-
for info in tarf.getmembers():
92+
with tarfile_open(fileobj=bio) as fp:
93+
for info in fp.getmembers():
9394
if info.isfile() and info.name.startswith('bin/ec-'):
94-
return tarf.extractfile(info).read()
95+
return fp.extractfile(info).read()
9596

9697
raise AssertionError('unreachable `extract` function')
9798

@@ -102,7 +103,12 @@ def save_executables(data, base_dir):
102103
exe += '.exe'
103104

104105
output_path = path.join(base_dir, exe)
105-
makedirs(base_dir)
106+
try:
107+
# Python 3
108+
makedirs(base_dir, exist_ok=True)
109+
except TypeError:
110+
# Python 2.7
111+
makedirs(base_dir)
106112

107113
with open(output_path, 'wb') as fp:
108114
fp.write(data)

tests/Dockerfile.template

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ LABEL maintainer="Marco M. (mmicu) <mmicu.github00@gmail.com>"
66
COPY . /app
77
WORKDIR /app
88

9-
RUN set -x \
10-
&& apt-get update \
11-
&& apt-get install -y make \
12-
&& python -m pip install --upgrade pip \
13-
&& pip install -r tests/requirements.txt \
9+
RUN apt-get update \
10+
&& apt-get install -y make \
11+
&& python -m pip install --upgrade pip \
1412
&& pip install --no-cache-dir $PACKAGE

tests/requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)