Skip to content

Commit

Permalink
feat: use ruff (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoboTiG committed Feb 27, 2024
1 parent b989347 commit 20a24c5
Show file tree
Hide file tree
Showing 42 changed files with 599 additions and 671 deletions.
11 changes: 6 additions & 5 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#
# Small script to ensure quality checks pass before submitting a commit/PR.
#
python -m isort docs src
python -m black --line-length=120 docs src
python -m flake8 docs src
python -m pylint src/mss
set -eu

python -m ruff --fix docs src
python -m ruff format docs src

# "--platform win32" to not fail on ctypes.windll (it does not affect the overall check on other OSes)
python -m mypy --platform win32 --exclude src/tests src docs/source/examples
python -m mypy --platform win32 src docs/source/examples
46 changes: 4 additions & 42 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,29 @@

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

from mss import __author__, __date__, __version__ # noqa
import mss

# -- General configuration ------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ["sphinx.ext.intersphinx"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ".rst"

# The master toctree document.
master_doc = "index"

# General information about the project.
project = "Python MSS"
copyright = f"{__date__}, {__author__} & contributors"
author = "Tiger-222"
copyright = f"{mss.__date__}, {mss.__author__} & contributors" # noqa:A001
author = mss.__author__
version = mss.__version__

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = __version__

# The full version, including alpha/beta/rc tags.
release = "latest"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = "sphinx"

todo_include_todos = True


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = "default"

# Output file base name for HTML help builder.
htmlhelp_basename = "PythonMSSdoc"


Expand Down
10 changes: 3 additions & 7 deletions docs/source/examples/callback.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
Screenshot of the monitor 1, with callback.
"""
Expand All @@ -11,10 +10,7 @@


def on_exists(fname: str) -> None:
"""
Callback example when we try to overwrite an existing screenshot.
"""

"""Callback example when we try to overwrite an existing screenshot."""
if os.path.isfile(fname):
newfile = f"{fname}.old"
print(f"{fname} -> {newfile}")
Expand Down
8 changes: 3 additions & 5 deletions docs/source/examples/custom_cls_image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
Screenshot of the monitor 1, using a custom class to handle the data.
"""
Expand All @@ -12,8 +11,7 @@


class SimpleScreenShot(ScreenShot):
"""
Define your own custom method to deal with screen shot raw data.
"""Define your own custom method to deal with screen shot raw data.
Of course, you can inherit from the ScreenShot class and change
or add new methods.
"""
Expand Down
12 changes: 5 additions & 7 deletions docs/source/examples/fps.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
Simple naive benchmark to compare with:
https://pythonprogramming.net/game-frames-open-cv-python-plays-gta-v/
"""
import time

import cv2
import numpy

import mss
import numpy as np


def screen_record() -> int:
Expand All @@ -27,7 +25,7 @@ def screen_record() -> int:
last_time = time.time()

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

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

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

cv2.imshow(title, img)
Expand Down
5 changes: 2 additions & 3 deletions docs/source/examples/fps_multiprocessing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
Example using the multiprocessing module to speed-up screen capture.
https://github.com/pythonlessons/TensorFlow-object-detection-tutorial
Expand Down
5 changes: 2 additions & 3 deletions docs/source/examples/from_pil_tuple.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
Use PIL bbox style and percent values.
"""
Expand Down
5 changes: 2 additions & 3 deletions docs/source/examples/linux_display_keyword.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
Usage example with a specific display.
"""
Expand Down
10 changes: 4 additions & 6 deletions docs/source/examples/opencv_numpy.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
OpenCV/Numpy example.
"""
import time

import cv2
import numpy

import mss
import numpy as np

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

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

# Display the picture
cv2.imshow("OpenCV/Numpy normal", img)
Expand Down
5 changes: 2 additions & 3 deletions docs/source/examples/part_of_screen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
Example to capture part of the screen.
"""
Expand Down
5 changes: 2 additions & 3 deletions docs/source/examples/part_of_screen_monitor_2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
Example to capture part of the screen of the monitor 2.
"""
Expand Down
8 changes: 3 additions & 5 deletions docs/source/examples/pil.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
PIL example using frombytes().
"""
from PIL import Image

import mss
from PIL import Image

with mss.mss() as sct:
# Get rid of the first, as it represents the "All in One" monitor:
Expand Down
8 changes: 3 additions & 5 deletions docs/source/examples/pil_pixels.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""
This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss
"""This is part of the MSS Python's module.
Source: https://github.com/BoboTiG/python-mss.
PIL examples to play with pixels.
"""
from PIL import Image

import mss
from PIL import Image

with mss.mss() as sct:
# Get a screenshot of the 1st monitor
Expand Down
72 changes: 41 additions & 31 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ test = [
"sphinx",
]
dev = [
"black",
"build",
"flake8-pyproject",
"mypy",
"pylint",
"ruff",
"twine",
"wheel",
]
Expand All @@ -108,26 +106,6 @@ packages = [
"src/mss",
]

[tool.black]
target-version = ["py38"]
line-length = 120
safe = true

[tool.flake8]
max-line-length = 120
ignore = [
"E203", # Whitespace before ':', but it's not PEP 8 compliant
"W503", # Line break before binary operator, but it's not PEP 8 compliant
]

[tool.isort]
py_version = 38
line_length = 120
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true

[tool.mypy]
# Ensure we know what we do
warn_redundant_casts = true
Expand All @@ -149,14 +127,6 @@ disallow_untyped_calls = true

strict_equality = true

[tool.pylint."MESSAGES CONTROL"]
disable = "locally-disabled,too-few-public-methods,too-many-instance-attributes,duplicate-code"

[tool.pylint.REPORTS]
max-line-length = 120
output-format = "colorized"
reports = "no"

[tool.pytest.ini_options]
pythonpath = "src"
addopts = """
Expand All @@ -167,3 +137,43 @@ addopts = """
--cov=src/mss
--cov-report=term-missing
"""

[tool.ruff]
exclude = [
".git",
".mypy_cache",
".pytest_cache",
".ruff_cache",
"venv",
]
line-length = 120
indent-width = 4
target-version = "py38"

[tool.ruff.lint]
extend-select = ["ALL"]
ignore = [
"ANN101",
"ANN401",
"C90",
"COM812",
"D", # TODO
"ERA",
"FBT",
"INP001",
"ISC001",
"PTH",
"PL",
"S",
"SIM117", # TODO: remove wen dropping Python 3.8 support
"SLF",
"T201",
"UP006", # TODO: remove wen dropping Python 3.8 support
]
fixable = ["ALL"]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
9 changes: 4 additions & 5 deletions src/mss/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
An ultra fast cross-platform multiple screenshots module in pure python
"""An ultra fast cross-platform multiple screenshots module in pure python
using ctypes.
This module is maintained by Mickaël Schoentgen <contact@tiger-222.fr>.
Expand All @@ -8,11 +7,11 @@
https://github.com/BoboTiG/python-mss
If that URL should fail, try contacting the author.
"""
from .exception import ScreenShotError
from .factory import mss
from mss.exception import ScreenShotError
from mss.factory import mss

__version__ = "9.0.2"
__author__ = "Mickaël 'Tiger-222' Schoentgen"
__author__ = "Mickaël Schoentgen"
__date__ = "2013-2024"
__copyright__ = f"""
Copyright (c) {__date__}, {__author__}
Expand Down

0 comments on commit 20a24c5

Please sign in to comment.