Skip to content

Commit 20a24c5

Browse files
authored
feat: use ruff (#275)
1 parent b989347 commit 20a24c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+599
-671
lines changed

check.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#
33
# Small script to ensure quality checks pass before submitting a commit/PR.
44
#
5-
python -m isort docs src
6-
python -m black --line-length=120 docs src
7-
python -m flake8 docs src
8-
python -m pylint src/mss
5+
set -eu
6+
7+
python -m ruff --fix docs src
8+
python -m ruff format docs src
9+
910
# "--platform win32" to not fail on ctypes.windll (it does not affect the overall check on other OSes)
10-
python -m mypy --platform win32 --exclude src/tests src docs/source/examples
11+
python -m mypy --platform win32 src docs/source/examples

docs/source/conf.py

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,29 @@
66

77
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "src"))
88

9-
from mss import __author__, __date__, __version__ # noqa
9+
import mss
1010

1111
# -- General configuration ------------------------------------------------
1212

13-
# Add any Sphinx extension module names here, as strings. They can be
14-
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
15-
# ones.
1613
extensions = ["sphinx.ext.intersphinx"]
17-
18-
# Add any paths that contain templates here, relative to this directory.
1914
templates_path = ["_templates"]
20-
21-
# The suffix(es) of source filenames.
22-
# You can specify multiple suffix as a list of string:
23-
#
24-
# source_suffix = ['.rst', '.md']
2515
source_suffix = ".rst"
26-
27-
# The master toctree document.
2816
master_doc = "index"
2917

3018
# General information about the project.
3119
project = "Python MSS"
32-
copyright = f"{__date__}, {__author__} & contributors"
33-
author = "Tiger-222"
20+
copyright = f"{mss.__date__}, {mss.__author__} & contributors" # noqa:A001
21+
author = mss.__author__
22+
version = mss.__version__
3423

35-
# The version info for the project you're documenting, acts as replacement for
36-
# |version| and |release|, also used in various other places throughout the
37-
# built documents.
38-
#
39-
# The short X.Y version.
40-
version = __version__
41-
42-
# The full version, including alpha/beta/rc tags.
4324
release = "latest"
44-
45-
# The language for content autogenerated by Sphinx. Refer to documentation
46-
# for a list of supported languages.
47-
#
48-
# This is also used if you do content translation via gettext catalogs.
49-
# Usually you set "language" from the command line for these cases.
5025
language = "en"
51-
52-
# List of patterns, relative to source directory, that match files and
53-
# directories to ignore when looking for source files.
54-
# This patterns also effect to html_static_path and html_extra_path
55-
exclude_patterns = []
56-
57-
# The name of the Pygments (syntax highlighting) style to use.
58-
pygments_style = "sphinx"
59-
6026
todo_include_todos = True
6127

6228

6329
# -- Options for HTML output ----------------------------------------------
6430

65-
# The theme to use for HTML and HTML Help pages. See the documentation for
66-
# a list of builtin themes.
6731
html_theme = "default"
68-
69-
# Output file base name for HTML help builder.
7032
htmlhelp_basename = "PythonMSSdoc"
7133

7234

docs/source/examples/callback.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
This is part of the MSS Python's module.
3-
Source: https://github.com/BoboTiG/python-mss
1+
"""This is part of the MSS Python's module.
2+
Source: https://github.com/BoboTiG/python-mss.
43
54
Screenshot of the monitor 1, with callback.
65
"""
@@ -11,10 +10,7 @@
1110

1211

1312
def on_exists(fname: str) -> None:
14-
"""
15-
Callback example when we try to overwrite an existing screenshot.
16-
"""
17-
13+
"""Callback example when we try to overwrite an existing screenshot."""
1814
if os.path.isfile(fname):
1915
newfile = f"{fname}.old"
2016
print(f"{fname} -> {newfile}")

docs/source/examples/custom_cls_image.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
This is part of the MSS Python's module.
3-
Source: https://github.com/BoboTiG/python-mss
1+
"""This is part of the MSS Python's module.
2+
Source: https://github.com/BoboTiG/python-mss.
43
54
Screenshot of the monitor 1, using a custom class to handle the data.
65
"""
@@ -12,8 +11,7 @@
1211

1312

1413
class SimpleScreenShot(ScreenShot):
15-
"""
16-
Define your own custom method to deal with screen shot raw data.
14+
"""Define your own custom method to deal with screen shot raw data.
1715
Of course, you can inherit from the ScreenShot class and change
1816
or add new methods.
1917
"""

docs/source/examples/fps.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
"""
2-
This is part of the MSS Python's module.
3-
Source: https://github.com/BoboTiG/python-mss
1+
"""This is part of the MSS Python's module.
2+
Source: https://github.com/BoboTiG/python-mss.
43
54
Simple naive benchmark to compare with:
65
https://pythonprogramming.net/game-frames-open-cv-python-plays-gta-v/
76
"""
87
import time
98

109
import cv2
11-
import numpy
12-
1310
import mss
11+
import numpy as np
1412

1513

1614
def screen_record() -> int:
@@ -27,7 +25,7 @@ def screen_record() -> int:
2725
last_time = time.time()
2826

2927
while time.time() - last_time < 1:
30-
img = numpy.asarray(ImageGrab.grab(bbox=mon))
28+
img = np.asarray(ImageGrab.grab(bbox=mon))
3129
fps += 1
3230

3331
cv2.imshow(title, cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
@@ -48,7 +46,7 @@ def screen_record_efficient() -> int:
4846
last_time = time.time()
4947

5048
while time.time() - last_time < 1:
51-
img = numpy.asarray(sct.grab(mon))
49+
img = np.asarray(sct.grab(mon))
5250
fps += 1
5351

5452
cv2.imshow(title, img)

docs/source/examples/fps_multiprocessing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
This is part of the MSS Python's module.
3-
Source: https://github.com/BoboTiG/python-mss
1+
"""This is part of the MSS Python's module.
2+
Source: https://github.com/BoboTiG/python-mss.
43
54
Example using the multiprocessing module to speed-up screen capture.
65
https://github.com/pythonlessons/TensorFlow-object-detection-tutorial

docs/source/examples/from_pil_tuple.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
This is part of the MSS Python's module.
3-
Source: https://github.com/BoboTiG/python-mss
1+
"""This is part of the MSS Python's module.
2+
Source: https://github.com/BoboTiG/python-mss.
43
54
Use PIL bbox style and percent values.
65
"""

docs/source/examples/linux_display_keyword.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
This is part of the MSS Python's module.
3-
Source: https://github.com/BoboTiG/python-mss
1+
"""This is part of the MSS Python's module.
2+
Source: https://github.com/BoboTiG/python-mss.
43
54
Usage example with a specific display.
65
"""

docs/source/examples/opencv_numpy.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
"""
2-
This is part of the MSS Python's module.
3-
Source: https://github.com/BoboTiG/python-mss
1+
"""This is part of the MSS Python's module.
2+
Source: https://github.com/BoboTiG/python-mss.
43
54
OpenCV/Numpy example.
65
"""
76
import time
87

98
import cv2
10-
import numpy
11-
129
import mss
10+
import numpy as np
1311

1412
with mss.mss() as sct:
1513
# Part of the screen to capture
@@ -19,7 +17,7 @@
1917
last_time = time.time()
2018

2119
# Get raw pixels from the screen, save it to a Numpy array
22-
img = numpy.array(sct.grab(monitor))
20+
img = np.array(sct.grab(monitor))
2321

2422
# Display the picture
2523
cv2.imshow("OpenCV/Numpy normal", img)

docs/source/examples/part_of_screen.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
This is part of the MSS Python's module.
3-
Source: https://github.com/BoboTiG/python-mss
1+
"""This is part of the MSS Python's module.
2+
Source: https://github.com/BoboTiG/python-mss.
43
54
Example to capture part of the screen.
65
"""

0 commit comments

Comments
 (0)