Skip to content

Commit

Permalink
Add ruff linter to pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed May 22, 2024
1 parent 5608e1b commit 57c4ae6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
15 changes: 11 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
# Identify invalid files
- id: check-ast
Expand All @@ -17,7 +17,6 @@ repos:
- id: check-docstring-first
- id: debug-statements
- id: requirements-txt-fixer
- id: fix-encoding-pragma
- id: fix-byte-order-marker
# General quality checks
- id: mixed-line-ending
Expand All @@ -29,12 +28,20 @@ repos:
- id: check-executables-have-shebangs
- id: end-of-file-fixer
exclude: ^test/resources/.+

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
args: [--extend-ignore, "F401,F403"]

- repo: https://github.com/ambv/black
rev: 24.1.1
rev: 24.4.2
hooks:
- id: black
args: [--config=.black.toml]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.8.0'
rev: 'v1.10.0'
hooks:
- id: mypy
28 changes: 14 additions & 14 deletions puremagic/magic_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,13 @@
["00010002", 2, ".rgb", "image/x-rgb", "Silicon Graphics RGB Bitmap (Uncompressed, 1bpc, 2D Image)"],
["01010002", 2, ".rgb", "image/x-rgb", "Silicon Graphics RGB Bitmap (RLE compressed, 1bpc, 2D Image)"],
["00020002", 2, ".rgb", "image/x-rgb", "Silicon Graphics RGB Bitmap (Uncompressed, 2bpc, 2D Image)"],
["01020002", 2, ".rgb", "image/x-rgb", "Silicon Graphics RGB Bitmap (RLE compressed, 2bpc, Multiple 2D Images)"],
["01020002", 2, ".rgb", "image/x-rgb", "Silicon Graphics RGB Bitmap (RLE compressed, 2bpc, Multiple 2D Images)"],
["00010003", 2, ".rgb", "image/x-rgb", "Silicon Graphics RGB Bitmap (Uncompressed, 1bpc, Multiple 2D Images)"],
["01010003", 2, ".rgb", "image/x-rgb", "Silicon Graphics RGB Bitmap (RLE compressed, 1bpc, Multiple 2D Images)"],
["00020003", 2, ".rgb", "image/x-rgb", "Silicon Graphics RGB Bitmap (Uncompressed, 2bpc, Multiple 2D Images)"],
["01020003", 2, ".rgb", "image/x-rgb", "Silicon Graphics RGB Bitmap (RLE compressed, 2bpc, Multiple 2D Images)"]
],
"59a66a95" : [
"59a66a95" : [
["00000000", 22, ".sun", "image/x-sun-raster", "Sun raster image (Old, No color map)"],
["00010000", 22, ".sun", "image/x-sun-raster", "Sun raster image (Standard, No color map)"],
["00020000", 22, ".sun", "image/x-sun-raster", "Sun raster image (Byte-Encoded, No color map)"],
Expand All @@ -415,7 +415,7 @@
["00040002", 22, ".sun", "image/x-sun-raster", "Sun raster image (TIFF format, RAW color map)"],
["00050002", 22, ".sun", "image/x-sun-raster", "Sun raster image (IFF format, RAW color map)"],
["FFFF0002", 22, ".sun", "image/x-sun-raster", "Sun raster image (Experimental, RAW color map)"]
],
],
"716f6966" : [
["0300", 12, ".qoi", "", "Quite OK image (RGB, sRGB with linear alpha)"],
["0301", 12, ".qoi", "", "Quite OK image (RGB, All channels alpha)"],
Expand All @@ -431,7 +431,7 @@
["0a23", 2, ".pbm", "image/x-portable-bitmap", "PBM image (Ascii)"],
["0d23", 2, ".pbm", "image/x-portable-bitmap", "PBM image (Ascii)"],
["0923", 2, ".pbm", "image/x-portable-bitmap", "PBM image (Ascii)"]
],
],
"5034" : [
["20", 2, ".pbm", "image/x-portable-bitmap", "PBM image (Binary)"],
["0a", 2, ".pbm", "image/x-portable-bitmap", "PBM image (Binary)"],
Expand All @@ -441,7 +441,7 @@
["0a23", 2, ".pbm", "image/x-portable-bitmap", "PBM image (Binary)"],
["0d23", 2, ".pbm", "image/x-portable-bitmap", "PBM image (Binary)"],
["0923", 2, ".pbm", "image/x-portable-bitmap", "PBM image (Binary)"]
],
],
"5032" : [
["20", 2, ".pgm", "image/x-portable-graymap", "PGM image (Ascii)"],
["0a", 2, ".pgm", "image/x-portable-graymap", "PGM image (Ascii)"],
Expand All @@ -451,7 +451,7 @@
["0a23", 2, ".pgm", "image/x-portable-graymap", "PGM image (Ascii)"],
["0d23", 2, ".pgm", "image/x-portable-graymap", "PGM image (Ascii)"],
["0923", 2, ".pgm", "image/x-portable-graymap", "PGM image (Ascii)"]
],
],
"5035" : [
["20", 2, ".pgm", "image/x-portable-graymap", "PGM image (Binary)"],
["0a", 2, ".pgm", "image/x-portable-graymap", "PGM image (Binary)"],
Expand All @@ -471,7 +471,7 @@
["0a23", 2, ".ppm", "image/x-portable-pixmap", "PPM image (Ascii)"],
["0d23", 2, ".ppm", "image/x-portable-pixmap", "PPM image (Ascii)"],
["0923", 2, ".ppm", "image/x-portable-pixmap", "PPM image (Ascii)"]
],
],
"5036" : [
["20", 2, ".ppm", "image/x-portable-pixmap", "PPM image (Binary)"],
["0a", 2, ".ppm", "image/x-portable-pixmap", "PPM image (Binary)"],
Expand All @@ -484,24 +484,24 @@
],
"5046" : [
["0a", 2, ".pfm", "", "Portable Float Map (Colour)"],
["0d", 2, ".pbm", "", "Portable Float Map (Colour)"]
["0d", 2, ".pbm", "", "Portable Float Map (Colour)"]
],
"5066" : [
["0a", 2, ".pfm", "", "Portable Float Map (Greyscale)"],
["0d", 2, ".pfm", "", "Portable Float Map (Greyscale)"]
],
["0d", 2, ".pfm", "", "Portable Float Map (Greyscale)"]
],
"504634" : [
["0a", 3, ".pfm", "", "Augmented Portable Float Map"],
["0d", 3, ".pfm", "", "Augmented Portable Float Map"]
],
["0d", 3, ".pfm", "", "Augmented Portable Float Map"]
],
"5037" : [
["0a", 2, ".pam", "image/x-portable-arbitrarymap", "Portable Arbitrary Map"],
["0d", 2, ".pam", "image/x-portable-arbitrarymap", "Portable Arbitrary Map"],
["0a5749445448", 2, ".pam", "image/x-portable-arbitrarymap", "Portable Arbitrary Map"],
["0d5749445448", 2, ".pam", "image/x-portable-arbitrarymap", "Portable Arbitrary Map"],
["0a484549474854", 2, ".pam", "image/x-portable-arbitrarymap", "Portable Arbitrary Map"],
["0d484549474854", 2, ".pam", "image/x-portable-arbitrarymap", "Portable Arbitrary Map"]
]
["0d484549474854", 2, ".pam", "image/x-portable-arbitrarymap", "Portable Arbitrary Map"]
]
},
"footers": [
["54525545564953494f4e2d5846494c452e00", -18, ".tga", "image/tga", "Truevision Targa Graphic file"],
Expand Down
13 changes: 6 additions & 7 deletions test/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from binascii import unhexlify
from pathlib import Path
from sys import version_info
from warnings import filterwarnings
Expand Down Expand Up @@ -70,14 +69,14 @@ def test_what_from_file_none(file="test/resources/fake_file", h=None):
("ppm", b"P6\r"),
("ppm", b"P6\t"),
("rast", b"\x59\xA6\x6A\x95"),
("rgb", b"\001\332"),
# ("tiff", b"II"), # unhexlify(b'4949')
# ("tiff", b"I I"), # unhexlify(b'492049')
("tiff", b"II*\x00"), # unhexlify(b'49492a00')
("tiff", b"II\\x2a\\x00"), # unhexlify(b'49495c7832615c783030')
("tiff", b"MM\x00*"), # unhexlify(b'4d4d002a')
("tiff", b"MM\x00+"), # unhexlify(b'4d4d002b')
("tiff", b"MM\\x00\\x2a"), # unhexlify(b'4d4d5c7830305c783261')
("webp", b"RIFF____WEBP"),
("xbm", b"#define "),
(None, "decafbad"),
(None, b"decafbad"),
]
Expand All @@ -104,7 +103,7 @@ def test_what_from_string_py311(expected, h):
These tests fail with imghdr on Python < 3.11.
"""
if isinstance(h, str): # In imgdir.what() h must be bytes, not str.
h = unhexlify(h) # bytes.fromhex(h)
h = bytes.fromhex(h)
assert what(None, h) == expected
if version_info < (3, 11): # TODO: Document these imghdr fails
expected = None
Expand All @@ -115,12 +114,12 @@ def test_what_from_string_py311(expected, h):
@pytest.mark.parametrize(
"expected, h",
[
("jpeg", b"______JFIF"),
("jpeg", b"______Exif"),
("rgb", b"\001\332"),
("jpeg", b"______JFIF"),
("tiff", b"II"),
("tiff", b"II\\x2a\\x00"), # unhexlify(b'49495c7832615c783030')
("tiff", b"MM"),
("xbm", b"#define "),
("tiff", b"MM\\x00\\x2a"), # unhexlify(b'4d4d5c7830305c783261')
],
)
def test_what_from_string_todo(expected, h):
Expand Down

0 comments on commit 57c4ae6

Please sign in to comment.