Skip to content

Commit 3ce1cbd

Browse files
authored
switch to the Black code formatter (#269)
* add basic contributing guidelines * prefer new style format strings * sort the inputs
1 parent bf01b8e commit 3ce1cbd

39 files changed

+4814
-2560
lines changed

.flake8

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[flake8]
2+
ignore = E203, E266, E501, W503, E211
3+
max-line-length = 88
4+
select = B,C,E,F,W,T4,B9
5+
per-file-ignores =
6+
schema_salad/metaschema.py:B950
7+
schema_salad/tests/*.py:B011

.isort.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[settings]
2+
multi_line_output=3
3+
include_trailing_comma=True
4+
force_grid_wrap=0
5+
use_parentheses=True
6+
line_length=88

.pylintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ disable=print-statement,
140140
deprecated-sys-function,
141141
exception-escape,
142142
comprehension-escape,
143-
useless-object-inheritance
143+
useless-object-inheritance,
144+
bad-continuation,
145+
bad-whitespace
144146

145147
# Enable the message, report, category or checker with the given id(s). You can
146148
# either give multiple identifier separated by comma (,) or put this option

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
- stage: release-test
3131
python: "2.7"
3232
script: RELEASE_SKIP=head PYVER= ${TRAVIS_BUILD_DIR}/release-test.sh
33+
- stage: release-test
34+
python: "3.5"
35+
script: RELEASE_SKIP=head PYVER=3.5 ${TRAVIS_BUILD_DIR}/release-test.sh
3336
script: tox
3437
branches:
3538
only:

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Style guide:
2+
- Python 2.7 + Python 3.5+ compatible code
3+
- PEP-484 type hints, in comments for Python 2.7 compatability
4+
- Prefer new style format strings https://pyformat.info/
5+
- Use ``make format`` to format the your code
6+
7+
In order to contribute to the development of ``schema-salad``, you need to install it from source (preferably in a virtual environment):
8+
Here's a rough guide (improvements are welcome!)
9+
- Install virtualenv via pip: ``pip install virtualenv``
10+
- Clone the code repository locally: ``git clone https://github.com/common-workflow-language/schema_salad.git``
11+
- Switch to cwltool directory: ``cd schema_salad``
12+
- Create a virtual Python environment: ``virtualenv env``
13+
- To begin using the Python virtual environment, it needs to be activated: ``source env/bin/activate``
14+
- To check if you have the Python virtual environment set up: ``which python`` and it should point to python executable in your virtual env
15+
- Install schema-salad in the Python virtual environment: ``pip install .``
16+
- Check the version which might be different from the version installed in general on any system: ``schema-salad-tool --version``
17+
- After you've made the changes, you can the complete test suite via tox: ``tox``
18+
- If you want to run specific tests, say ``unit tests`` in Python 3.5, then: ``tox -e py35-unit``.
19+
- Look at ``tox.ini`` for all available tests and runtimes
20+
- If tests are passing, you can simply commit and create a PR on ``schema_salad`` repo:
21+
- After you're done working, you can deactivate the virtual environment: ``deactivate``

Makefile

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
#
1616
1717

18-
# make pycodestyle to check for basic Python code compliance
19-
# make autopep8 to fix most pep8 errors
18+
# make format to fix most python formatting errors
2019
# make pylint to check Python code for enhanced compliance including naming
2120
# and documentation
2221
# make coverage-report to check coverage of the python scripts by the tests
@@ -27,7 +26,8 @@ PACKAGE=schema-salad
2726
# `SHELL=bash` doesn't work for some, so don't use BASH-isms like
2827
# `[[` conditional expressions.
2928
PYSOURCES=$(wildcard ${MODULE}/**.py tests/*.py) setup.py
30-
DEVPKGS=pycodestyle diff_cover autopep8 pylint coverage pep257 pytest-xdist flake8
29+
DEVPKGS=diff_cover black pylint coverage pep257 pytest-xdist \
30+
flake8 flake8-bugbear
3131
COVBASE=coverage run --branch --append --source=${MODULE} \
3232
--omit=schema_salad/tests/*
3333

@@ -73,19 +73,6 @@ clean: FORCE
7373
sort_imports:
7474
isort ${MODULE}/*.py ${MODULE}/tests/*.py setup.py
7575

76-
pep8: pycodestyle
77-
## pycodestyle : check Python code style
78-
pycodestyle: $(PYSOURCES)
79-
pycodestyle --exclude=_version.py --show-source --show-pep8 $^ || true
80-
81-
pep8_report.txt: pycodestyle_report.txt
82-
pycodestyle_report.txt: $(PYSOURCES)
83-
pycodestyle --exclude=_version.py $^ > $@ || true
84-
85-
diff_pep8_report: diff_pycodestyle_report
86-
diff_pycodestyle_report: pycodestyle_report.txt
87-
diff-quality --violations=pycodestyle $^
88-
8976
pep257: pydocstyle
9077
## pydocstyle : check Python code style
9178
pydocstyle: $(PYSOURCES)
@@ -97,14 +84,9 @@ pydocstyle_report.txt: $(PYSOURCES)
9784
diff_pydocstyle_report: pydocstyle_report.txt
9885
diff-quality --violations=pycodestyle --fail-under=100 $^
9986

100-
## autopep8 : fix most Python code indentation and formatting
101-
autopep8: $(PYSOURCES)
102-
autopep8 --recursive --in-place --ignore E309 $^
103-
104-
# A command to automatically run astyle and autopep8 on appropriate files
105-
## format : check/fix all code indentation and formatting (runs autopep8)
106-
format: autopep8
107-
# Do nothing
87+
## format : check/fix all code indentation and formatting (runs black)
88+
format:
89+
black --target-version py27 schema_salad
10890

10991
## pylint : run static code analysis on Python code
11092
pylint: $(PYSOURCES)
@@ -206,7 +188,7 @@ jenkins: FORCE
206188
. env/bin/activate ; \
207189
pip install -U setuptools pip wheel ; \
208190
${MAKE} install-dep coverage.html coverage.xml pydocstyle_report.txt \
209-
sloccount.sc pycodestyle_report.txt pylint_report.txt
191+
sloccount.sc pylint_report.txt
210192
if ! test -d env3 ; then virtualenv -p python3 env3 ; fi
211193
. env3/bin/activate ; \
212194
pip install -U setuptools pip wheel ; \

gittaggers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import subprocess
22
import time
3-
3+
import pkg_resources
44
from setuptools.command.egg_info import egg_info
55

6+
SETUPTOOLS_VER = pkg_resources.get_distribution(
7+
"setuptools").version.split('.')
8+
9+
RECENT_SETUPTOOLS = int(SETUPTOOLS_VER[0]) > 40 or (
10+
int(SETUPTOOLS_VER[0]) == 40 and int(SETUPTOOLS_VER[1]) > 0) or (
11+
int(SETUPTOOLS_VER[0]) == 40 and int(SETUPTOOLS_VER[1]) == 0 and
12+
int(SETUPTOOLS_VER[2]) > 0)
613

714
class EggInfoFromGit(egg_info):
815
"""Tag the build with git commit timestamp.
916
1017
If a build tag has already been set (e.g., "egg_info -b", building
1118
from source package), leave it alone.
1219
"""
20+
1321
def git_timestamp_tag(self):
1422
gitinfo = subprocess.check_output(
1523
['git', 'log', '--first-parent', '--max-count=1',
@@ -20,7 +28,9 @@ def tags(self):
2028
if self.tag_build is None:
2129
try:
2230
self.tag_build = self.git_timestamp_tag()
23-
except (subprocess.CalledProcessError, OSError):
31+
except subprocess.CalledProcessError:
2432
pass
2533
return egg_info.tags(self)
26-
vtags = property(tags)
34+
35+
if RECENT_SETUPTOOLS:
36+
vtags = property(tags)

release-test.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module=schema_salad
88
slug=${TRAVIS_PULL_REQUEST_SLUG:=common-workflow-language/schema_salad}
99
repo=https://github.com/${slug}.git
1010
run_tests="bin/py.test --pyargs ${module}"
11-
pipver=8.0.1 # minimum required version of pip
12-
setupver=20.10.1 # minimum required version of setuptools
11+
pipver=18 # minimum required version of pip
12+
setupver=40.3 # minimum required version of setuptools
1313
PYVER=${PYVER:=2.7}
1414

1515
rm -Rf "testenv${PYVER}_"? || /bin/true
@@ -22,10 +22,10 @@ then
2222
# First we test the head
2323
# shellcheck source=/dev/null
2424
source "testenv${PYVER}_1/bin/activate"
25-
rm "testenv${PYVER}_1/lib/python-wheels/setuptools"* \
26-
&& pip install --force-reinstall -U pip==${pipver} \
27-
&& pip install setuptools==${setupver} wheel
28-
make install-dependencies
25+
rm -f "testenv${PYVER}_1/lib/python-wheels/setuptools"*
26+
pip install --force-reinstall -U pip==${pipver}
27+
pip install setuptools==${setupver} wheel
28+
pip install pytest\<5 pytest-xdist -rrequirements.txt
2929
make test
3030
pip uninstall -y ${package} || true; pip uninstall -y ${package} \
3131
|| true; make install
@@ -56,7 +56,7 @@ rm lib/python-wheels/setuptools* \
5656
# The following can fail if you haven't pushed your commits to ${repo}
5757
pip install -e "git+${repo}@${HEAD}#egg=${package}"
5858
pushd src/${package}
59-
make install-dependencies
59+
pip install pytest\<5 pytest-xdist
6060
make dist
6161
make test
6262
cp dist/${package}*tar.gz "../../../testenv${PYVER}_3/"

schema_salad/__init__.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
from __future__ import absolute_import
2-
import logging
3-
import os
4-
import sys
5-
import typing
6-
import threading
72

8-
import six
3+
import logging
94

10-
from .utils import onWindows
11-
__author__ = '[email protected]'
5+
__author__ = "[email protected]"
126

137
_logger = logging.getLogger("salad")
148
_logger.addHandler(logging.StreamHandler())

schema_salad/avro/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
__all__ = ['schema']
17+
__all__ = ["schema"]

0 commit comments

Comments
 (0)