Skip to content

Commit 7b67ec1

Browse files
committed
Doc: Python 3.7 ready, add pre-commit hooks
1 parent 7e8ae57 commit 7b67ec1

File tree

10 files changed

+124
-85
lines changed

10 files changed

+124
-85
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ It is **very** important to keep up to date tests and documentation.
1212
Is your code right?
1313

1414
- [ ] PEP8 compliant
15-
- [ ] `flake8` passed (bonus)
16-
- [ ] `pylint` passed (bonus)
15+
- [ ] `flake8` passed

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
fail_fast: true
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: master
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: flake8
9+
- id: end-of-file-fixer
10+
- id: check-docstring-first
11+
- id: debug-statements
12+
- id: check-ast
13+
- id: no-commit-to-branch
14+
- repo: https://github.com/ambv/black
15+
rev: stable
16+
hooks:
17+
- id: black
18+
language_version: python3.6

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ python:
33
- 2.7
44
- 3.5
55
- 3.6
6-
- nightly # currently points to 3.7-dev
6+
- 3.7-dev
7+
- nightly # currently points to 3.8-dev
78

89
addons:
910
apt:
@@ -18,13 +19,12 @@ env:
1819
- DISPLAY=":42"
1920

2021
install:
21-
- pip install flake8 numpy pillow pylint sphinx
22-
- pip install -e .
22+
- python -m pip install flake8 numpy pillow sphinx
23+
- python -m pip install -e .
2324

2425
script:
25-
- py.test --showlocals --display=":42.0"
26-
- flake8 .
27-
- if [[ $TRAVIS_PYTHON_VERSION < '3.7' ]]; then pylint mss; fi
26+
- python -m pytest --display=":42.0" tests
27+
- python -m flake8 .
2828
- if [[ $TRAVIS_PYTHON_VERSION > '2.8' ]]; then cd docs && make clean html; fi
2929

3030
after_script:

docs/source/api.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,30 @@ Methods
5050

5151
The parent's class for every OS implementation.
5252

53-
.. method:: grab(monitor)
53+
.. method:: grab(region)
5454

55-
:param dict monitor: monitor's information.
55+
:param dict monitor: region's coordinates.
5656
:rtype: :class:`ScreenShot`
5757
:raises NotImplementedError: Subclasses need to implement this.
5858

59-
Retrieve screen pixels for a given monitor.
59+
Retrieve screen pixels for a given *region*.
6060

6161
.. note::
6262

63-
``monitor`` can be a ``tuple`` like ``PIL.Image.grab()`` accepts,
63+
*monitor* can be a ``tuple`` like ``PIL.Image.grab()`` accepts,
6464
it will be converted to the appropriate ``dict``.
6565

6666
.. method:: save([mon=1], [output='mon-{mon}.png'], [callback=None])
6767

6868
:param int mon: the monitor's number.
6969
:param str output: the output's file name.
7070
:type callback: callable or None
71-
:param callback: callback called before saving the screen shot to a file. Takes the ``output`` argument as parameter.
71+
:param callback: callback called before saving the screen shot to a file. Takes the *output* argument as parameter.
7272
:rtype: iterable
7373
:return: Created file(s).
7474

7575
Grab a screen shot and save it to a file.
76-
The ``output`` parameter can take several keywords to customize the filename:
76+
The *output* parameter can take several keywords to customize the filename:
7777

7878
- ``{mon}``: the monitor number
7979
- ``{top}``: the screen shot y-coordinate of the upper-left corner
@@ -130,17 +130,17 @@ Methods
130130
:param tuple size: The (width, height) pair.
131131
:param int level: PNG compression level.
132132
:param str output: output's file name.
133-
:raises ScreenShotError: On error when writing ``data`` to ``output``.
134-
:raises zlib.error: On bad compression ``level``.
133+
:raises ScreenShotError: On error when writing *data* to *output*.
134+
:raises zlib.error: On bad compression *level*.
135135

136136
Dump data to the image file. Pure Python PNG implementation.
137-
If ``output`` is ``None``, create no file but return the whole PNG data.
137+
If *output* is ``None``, create no file but return the whole PNG data.
138138

139139
.. versionadded:: 3.0.0
140140

141141
.. versionadded:: 3.2.0
142142

143-
Added the ``level`` keyword argument to control the PNG compression level.
143+
The *level* keyword argument to control the PNG compression level.
144144

145145

146146
Properties
@@ -250,11 +250,11 @@ Exception
250250
On GNU/Linux, and if the error comes from the XServer, it contains XError details.
251251
This is an empty dict by default.
252252

253-
For Xerrors, you can find information on `Using the Default Error Handlers <https://tronche.com/gui/x/xlib/event-handling/protocol-errors/default-handlers.html>`_.
253+
For XErrors, you can find information on `Using the Default Error Handlers <https://tronche.com/gui/x/xlib/event-handling/protocol-errors/default-handlers.html>`_.
254254

255255
:rtype: dict[str, Any]
256256

257-
.. versionchanged:: 3.3.0
257+
.. versionadded:: 3.3.0
258258

259259

260260
Factory

docs/source/developers.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Setup
1111
2. Create you own branch.
1212
3. Be sure to add/update tests and documentation within your patch.
1313

14+
Additionnally, you can install `pre-commit <http://pre-commit.com/>`_ to ensure you are doing things well::
15+
16+
$ python -m pip install --upgrade --user pre-commit
17+
$ pre-commit install
18+
1419

1520
Testing
1621
=======
@@ -20,7 +25,7 @@ Dependency
2025

2126
You will need `pytest <https://pypi.python.org/pypi/pytest>`_::
2227

23-
$ pip install pytest
28+
$ python -m pip install --upgrade --user pytest
2429

2530

2631
How to Test?
@@ -32,7 +37,7 @@ Enable the developer mode::
3237

3338
Launch the test suit::
3439

35-
$ py.test
40+
$ python -m pytest tests
3641

3742
.. Note::
3843

@@ -42,24 +47,23 @@ Launch the test suit::
4247
Validating the Code
4348
===================
4449

45-
It is important to keep a clean base code. Use tools like `flake8 <https://pypi.python.org/pypi/flake8>`_ and `Pylint <https://pypi.python.org/pypi/pylint>`_.
50+
It is important to keep a clean base code. Use tools like `flake8 <https://pypi.python.org/pypi/flake8>`_.
4651

4752

4853
Dependencies
4954
------------
5055

5156
Install required packages::
5257

53-
$ pip install flake8 pylint
58+
$ python -m pip install --upgrade --user flake8
5459

5560

5661
How to Validate?
5762
----------------
5863

5964
::
6065

61-
$ flake8
62-
$ pylint mss
66+
$ python -m flake8 .
6367

6468
If there is no output, you are good ;)
6569

@@ -76,7 +80,7 @@ Dependencies
7680

7781
Install required packages::
7882

79-
$ pip install mypy-lang
83+
$ python -m pip install --upgrade --user mypy-lang
8084

8185

8286
Running Mypy
@@ -95,7 +99,7 @@ Dependencies
9599

96100
You will need `Sphinx <http://sphinx-doc.org/>`_::
97101

98-
$ pip install sphinx
102+
$ python -m pip install --upgrade --user sphinx
99103

100104

101105
How to Build?

docs/source/examples/opencv_numpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# cv2.imshow('OpenCV/Numpy grayscale',
3131
# cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
3232

33-
print('fps: {0}'.format(1 / (time.time()-last_time)))
33+
print('fps: {0}'.format(1 / (time.time() - last_time)))
3434

3535
# Press "q" to quit
3636
if cv2.waitKey(25) & 0xFF == ord('q'):

docs/source/installation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Recommended Way
99

1010
Quite simple::
1111

12-
$ pip install --upgrade mss
12+
$ python -m pip install --upgrade --user mss
1313

1414

1515
From Sources
@@ -23,4 +23,4 @@ Alternatively, you can get a copy of the module from GitHub::
2323

2424
And then::
2525

26-
$ sudo python setup.py install
26+
$ python setup.py install --user

setup.cfg

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[bdist_wheel]
2+
universal = 1
3+
4+
[flake8]
5+
ignore =
6+
# E203 whitespace before ':', but E203 is not PEP 8 compliant
7+
E203
8+
# W503 line break before binary operator, but W503 is not PEP 8 compliant
9+
W503
10+
max-line-length = 120
11+
12+
[tool:pytest]
13+
addopts =
14+
--showlocals
15+
--strict
16+
--failed-first
17+
--no-print-logs
18+
-r fE
19+
-v

setup.py

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,57 @@
66

77

88
classifiers = [
9-
'Development Status :: 5 - Production/Stable',
10-
'Environment :: MacOS X',
11-
'Environment :: Win32 (MS Windows)',
12-
'Environment :: X11 Applications',
13-
'Intended Audience :: Customer Service',
14-
'Intended Audience :: Developers',
15-
'Intended Audience :: Information Technology',
16-
'Intended Audience :: Education',
17-
'Intended Audience :: End Users/Desktop',
18-
'Intended Audience :: Financial and Insurance Industry',
19-
'Intended Audience :: Healthcare Industry',
20-
'Intended Audience :: Other Audience',
21-
'Intended Audience :: Science/Research',
22-
'Intended Audience :: System Administrators',
23-
'Intended Audience :: Telecommunications Industry',
24-
'License :: OSI Approved :: MIT License',
25-
'Natural Language :: English',
26-
'Operating System :: MacOS',
27-
'Operating System :: MacOS :: MacOS X',
28-
'Operating System :: Microsoft',
29-
'Operating System :: Microsoft :: Windows',
30-
'Operating System :: OS Independent',
31-
'Operating System :: POSIX :: Linux',
32-
'Programming Language :: Python',
33-
'Programming Language :: Python :: 2',
34-
'Programming Language :: Python :: 2.7',
35-
'Programming Language :: Python :: 3',
36-
'Programming Language :: Python :: 3.4',
37-
'Programming Language :: Python :: 3.5',
38-
'Programming Language :: Python :: 3.6',
39-
'Topic :: Multimedia :: Graphics :: Capture :: Screen Capture'
9+
"Development Status :: 5 - Production/Stable",
10+
"Environment :: MacOS X",
11+
"Environment :: Win32 (MS Windows)",
12+
"Environment :: X11 Applications",
13+
"Intended Audience :: Customer Service",
14+
"Intended Audience :: Developers",
15+
"Intended Audience :: Information Technology",
16+
"Intended Audience :: Education",
17+
"Intended Audience :: End Users/Desktop",
18+
"Intended Audience :: Financial and Insurance Industry",
19+
"Intended Audience :: Healthcare Industry",
20+
"Intended Audience :: Other Audience",
21+
"Intended Audience :: Science/Research",
22+
"Intended Audience :: System Administrators",
23+
"Intended Audience :: Telecommunications Industry",
24+
"License :: OSI Approved :: MIT License",
25+
"Natural Language :: English",
26+
"Operating System :: MacOS",
27+
"Operating System :: MacOS :: MacOS X",
28+
"Operating System :: Microsoft",
29+
"Operating System :: Microsoft :: Windows",
30+
"Operating System :: OS Independent",
31+
"Operating System :: POSIX :: Linux",
32+
"Programming Language :: Python",
33+
"Programming Language :: Python :: 2",
34+
"Programming Language :: Python :: 2.7",
35+
"Programming Language :: Python :: 3",
36+
"Programming Language :: Python :: 3.4",
37+
"Programming Language :: Python :: 3.5",
38+
"Programming Language :: Python :: 3.6",
39+
"Programming Language :: Python :: 3.7",
40+
"Topic :: Multimedia :: Graphics :: Capture :: Screen Capture",
4041
]
4142
config = {
42-
'name': 'mss',
43-
'version': __version__,
44-
'author': 'Tiger-222',
45-
'author_email': '[email protected]',
46-
'maintainer': 'Tiger-222',
47-
'maintainer_email': '[email protected]',
48-
'url': 'https://github.com/BoboTiG/python-mss',
49-
'description': ('An ultra fast cross-platform multiple screenshots module '
50-
'in pure python using ctypes.'),
51-
'long_description': open('README.rst').read(),
52-
'classifiers': classifiers,
53-
'platforms': ['Darwin', 'Linux', 'Windows'],
54-
'packages': ['mss'],
55-
'entry_points': {'console_scripts': ['mss=mss.__main__:main']},
56-
'license': 'MIT',
43+
"name": "mss",
44+
"version": __version__,
45+
"author": "Tiger-222",
46+
"author_email": "[email protected]",
47+
"maintainer": "Tiger-222",
48+
"maintainer_email": "[email protected]",
49+
"url": "https://github.com/BoboTiG/python-mss",
50+
"description": (
51+
"An ultra fast cross-platform multiple screenshots module "
52+
"in pure python using ctypes."
53+
),
54+
"long_description": open("README.rst").read(),
55+
"classifiers": classifiers,
56+
"platforms": ["Darwin", "Linux", "Windows"],
57+
"packages": ["mss"],
58+
"entry_points": {"console_scripts": ["mss=mss.__main__:main"]},
59+
"license": "MIT",
5760
}
5861

5962
setup(**config)

tests/test_gnu_linux.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ def test_factory_systems(monkeypatch):
4141
with pytest.raises(ScreenShotError) as exc:
4242
mss.mss()
4343
monkeypatch.undo()
44-
if not PY3:
45-
error = exc.value[1]['self']
46-
else:
47-
error = exc.value.args[1]['self']
48-
assert isinstance(error, MSSBase)
44+
assert isinstance(exc.value.details['self'], MSSBase)
4945

5046
# Windows
5147
monkeypatch.setattr(platform, 'system', lambda: 'wInDoWs')
@@ -88,20 +84,20 @@ def find_lib(lib):
8884
It is a naive approach, but works for now.
8985
"""
9086

91-
if lib == "Xrandr":
87+
if lib == 'Xrandr':
9288
return None
9389
return x11
9490

9591
# No `Xrandr` library
96-
monkeypatch.setattr(ctypes.util, "find_library", find_lib)
92+
monkeypatch.setattr(ctypes.util, 'find_library', find_lib)
9793
with pytest.raises(ScreenShotError):
9894
mss.mss()
9995
monkeypatch.undo()
10096

10197
# Bad display data
10298
import mss.linux
10399

104-
monkeypatch.setattr(mss.linux, "Display", lambda: None)
100+
monkeypatch.setattr(mss.linux, 'Display', lambda: None)
105101
with pytest.raises(TypeError):
106102
mss.mss()
107103

0 commit comments

Comments
 (0)