Skip to content

Commit

Permalink
add tools to use strict formating
Browse files Browse the repository at this point in the history
  • Loading branch information
inkhey committed Jun 27, 2019
1 parent 351e21a commit c2dd845
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks.git
sha: v2.2.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: check-yaml
- id: debug-statements
- id: check-merge-conflict
- repo: https://github.com/asottile/seed-isort-config
rev: v1.8.0
hooks:
- id: seed-isort-config
- repo: https://github.com/pre-commit/mirrors-isort
rev: 'v4.3.18'
hooks:
- id: isort
files: 'tests/(.*)/*.py preview_generator/(.*)/*.py setup.py build_supported_mimetypes_table_rst.py'
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
language_version: python3.6
args: [-l 100]
files: 'preview_generator setup.py build_supported_mimetypes_table_rst.py tests'
44 changes: 41 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -872,13 +872,51 @@ of the generic abstract class. For example:

ImagePreviewBuilderIMConvert(ImagePreviewBuilder)

Running Pytest :
Running Tests :
----------------
Pytest is a motor for unit testing

* `pip install pytest`
* `pip install -e [testing]`
* go into the "tests" directory : `cd path/to/you/project/directory/tests`
* run `py.test`
* run `pytest`


Others checks :
-------------------

Run mypy checks:

mypy --ignore-missing-imports --disallow-untyped-defs .

Code formatting using black:

black -l 100 preview_generator setup.py build_supported_mimetypes_table_rst.py tests

Sorting of import:

isort tests/**/*.py preview_generator/**/*.py setup.py build_supported_mimetypes_table_rst.py
Flake8 check(unused import, variable and many other checks):

flake8 preview_generator setup.py build_supported_mimetypes_table_rst.py tests


Contribute :
----------------
install preview_generator with dev dependencies (contains tests dependencies)

pip install -e '.[dev]

install pre-commit hooks:

pre-commit install

Launch test :

pytest

You now can commit and see if pre-commit is ok with your change.


------------
License
Expand Down
20 changes: 20 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[isort]
multi_line_output = 3
line_length = 100
force_single_line = true
force_sort_within_sections = true
combine_as_imports = true
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
skip_glob = .eggs*,.venv
known_standard_library = hashlib, logging, mimetype, typing, os, sys, abc, io, json, datetime, subprocess, tempfile
known_third_party =PIL,PyPDF2,magic,pdf2image,pyexifinfo,pytest,scribus,wand,xvfbwrapper
known_first_party = preview_generator
[flake8]
max-line-length = 100
show-source = True
max-complexity = 10
ignore = C901,E501,I801,W503
exclude = .venv,.eggs,tools
doctest = True
18 changes: 18 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
'pathlib',
'pdf2image'
]
tests_require = [
'pytest',
]

devtools_require=[
'flake8',
'isort',
'mypy',
'pre-commit',
]

# add black for python 3.6+
if sys.version_info.major == 3 and sys.version_info.minor >= 6:
devtools_require.append('black')

if py_version <= (3, 4):
install_requires.append("typing")
Expand Down Expand Up @@ -66,6 +80,10 @@
install_requires=install_requires,
python_requires='>= 3.5',
include_package_data=True,
extras_require={
'testing': tests_require,
'dev': tests_require + devtools_require,
},
test_suite='py.test', # TODO : change test_suite
tests_require=testpkgs,
package_data={
Expand Down

0 comments on commit c2dd845

Please sign in to comment.