Skip to content

Commit 5f555c1

Browse files
authored
Version 2.0.0b3 (#111)
- Adding #109 Halt on non-regular files like /dev/zero and /dev/random (thanks to Yuri Schaeffer) - Migrating to pyproject.toml from setup.py - Migrating to uv, and using only ruff instead of black and flake8
1 parent 55db71a commit 5f555c1

File tree

13 files changed

+820
-165
lines changed

13 files changed

+820
-165
lines changed

.github/workflows/pythonpublish.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v4
17+
1718
- name: Set up Python
1819
uses: actions/setup-python@v5
1920
with:
2021
python-version: '3.12'
22+
23+
- name: Install the latest version of uv and activate the environment
24+
uses: astral-sh/setup-uv@v6
25+
2126
- name: Install dependencies
22-
run: |
23-
python -m pip install --upgrade pip
24-
pip install setuptools wheel twine
27+
run: uv sync --frozen
28+
2529
- name: Build and publish
2630
env:
2731
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
2832
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
2933
run: |
30-
python setup.py sdist bdist_wheel
31-
twine upload dist/*
34+
uv build
35+
uv run twine upload dist/*

.github/workflows/tests.yml

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
os: [ubuntu-latest]
19-
python-version: ["3.12", "3.13"]
19+
python-version: ["3.12", "3.13", "3.14-dev"]
2020
include:
2121
- os: macos-latest
2222
python-version: '3.13'
@@ -31,33 +31,24 @@ jobs:
3131
with:
3232
python-version: ${{ matrix.python-version }}
3333
allow-prereleases: true
34-
cache: 'pip'
3534

36-
- name: Install dependencies
37-
run: |
38-
python -m pip install --upgrade pip
39-
pip install coveralls flake8 setuptools wheel twine
40-
pip install -r requirements-test.txt --upgrade
41-
pip install black==24.10.0
35+
- name: Install the latest version of uv and activate the environment
36+
uses: astral-sh/setup-uv@v6
4237

43-
- name: Verify Code with Black
44-
run: |
45-
black --check puremagic test
38+
- name: Install dependencies
39+
run: uv sync --frozen
4640

47-
- name: Lint with flake8
48-
run: |
49-
# stop the tests if there are linting errors
50-
flake8 puremagic --count --show-source --statistics
41+
- name: Verify Code with Ruff
42+
run: uv run ruff check
5143

5244
- name: Test with pytest
53-
run: |
54-
python -m pytest --cov=puremagic test/
45+
run: uv run pytest --cov=puremagic test/
5546

5647
- name: Check distribution log description
5748
shell: bash
5849
run: |
59-
python setup.py sdist bdist_wheel
60-
twine check dist/*
50+
uv build
51+
uv run twine check dist/*
6152
ls -lah "dist/"
6253
WHL=$(find dist -name *.whl -print -quit)
6354
echo ${WHL}

.pep8speaks.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,27 @@ repos:
3333
- id: end-of-file-fixer
3434
exclude: ^test/resources/.+
3535

36-
3736
- repo: https://github.com/astral-sh/ruff-pre-commit
38-
rev: v0.7.2
39-
hooks:
40-
- id: ruff
41-
42-
- repo: https://github.com/ambv/black
43-
rev: 24.10.0
37+
# Ruff version.
38+
rev: v0.12.2
4439
hooks:
45-
- id: black
40+
# Run the linter.
41+
- id: ruff-check
42+
args: [ --fix ]
43+
# Run the formatter.
44+
- id: ruff-format
4645

4746
- repo: https://github.com/pre-commit/mirrors-mypy
48-
rev: 'v1.13.0'
47+
rev: 'v1.16.1'
4948
hooks:
5049
- id: mypy
5150

5251
- repo: https://github.com/tox-dev/pyproject-fmt
53-
rev: v2.5.0
52+
rev: v2.6.0
5453
hooks:
5554
- id: pyproject-fmt
5655

5756
- repo: https://github.com/abravalheri/validate-pyproject
58-
rev: v0.22
57+
rev: v0.24.1
5958
hooks:
6059
- id: validate-pyproject

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ Version 2.0.0
66

77
- Adding deep scan for improved accuracy #102 #94 #70 #69 #12 #3
88
- Changing to full semantic versioning to be able to denote bugfixes vs minor features
9+
- Changing to use uv instead of requirements
910
- Removing support for python 3.7, 3.8, 3.9, 3.10 and 3.11 please stick to 1.x release chain to support older versions
1011

12+
Version 1.30
13+
------------
14+
15+
- Adding #109 Halt on non-regular files like /dev/zero and /dev/random (thanks to Yuri Schaeffer)
16+
1117
Version 1.29
1218
------------
1319

puremagic/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env python
2-
from puremagic.main import *
3-
from puremagic.main import __author__, __version__
2+
from puremagic.main import * # noqa: F403
3+
from puremagic.main import __author__, __version__ # noqa: F401

puremagic/main.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from puremagic.scanners import zip_scanner, pdf_scanner, text_scanner, json_scanner, python_scanner
2424

2525
__author__ = "Chris Griffith"
26-
__version__ = "2.0.0b2"
26+
__version__ = "2.0.0b3"
2727
__all__ = [
2828
"magic_file",
2929
"magic_string",
@@ -218,6 +218,8 @@ def _magic(header: bytes, footer: bytes, mime: bool, ext=None, filename=None) ->
218218

219219
def _file_details(filename: os.PathLike | str) -> tuple[bytes, bytes]:
220220
"""Grab the start and end of the file"""
221+
if not os.path.isfile(filename):
222+
raise PureError("Not a regular file")
221223
with open(filename, "rb") as fin:
222224
head = fin.read(max_head)
223225
try:
@@ -467,8 +469,8 @@ def _run_deep_scan(
467469

468470

469471
def command_line_entry(*args):
470-
import sys
471-
from argparse import ArgumentParser
472+
import sys # noqa: PLC0415
473+
from argparse import ArgumentParser # noqa: PLC0415
472474

473475
parser = ArgumentParser(
474476
description=(
@@ -530,14 +532,18 @@ def what(file: os.PathLike | str | None, h: bytes | None = None, imghdr_strict:
530532
```python
531533
# Replace...
532534
from imghdr import what
535+
533536
# with...
534537
from puremagic import what
538+
535539
# ---
536540
# Or replace...
537541
import imghdr
542+
538543
ext = imghdr.what(...)
539544
# with...
540545
import puremagic
546+
541547
ext = puremagic.what(...)
542548
```
543549
imghdr documentation: https://docs.python.org/3.12/library/imghdr.html

puremagic/scanners/zip_scanner.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def office_check(internal_files: list[str], zip_file: ZipFile, extension: str |
105105

106106

107107
def jar_check(internal_files: list[str], zip_file: ZipFile) -> Match | None:
108-
109108
if "META-INF/MANIFEST.MF" not in internal_files:
110109
return None
111110
if "version.json" not in internal_files:

pyproject.toml

Lines changed: 95 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,101 @@
1-
[tool.black]
2-
line-length = 120
3-
target-version = [
4-
'py312',
5-
'py313',
1+
[build-system]
2+
build-backend = "setuptools.build_meta"
3+
4+
requires = [ "setuptools", "setuptools-scm[toml]>=6.2", "wheel" ]
5+
6+
[project]
7+
name = "puremagic"
8+
description = "Pure python implementation of magic file detection"
9+
readme = "README.rst"
10+
license = "MIT"
11+
authors = [
12+
{ name = "Chris Griffith", email = "[email protected]" },
13+
]
14+
requires-python = ">=3.12"
15+
classifiers = [
16+
"Development Status :: 5 - Production/Stable",
17+
"Intended Audience :: Developers",
18+
"Natural Language :: English",
19+
"Operating System :: OS Independent",
20+
"Programming Language :: Python",
21+
"Programming Language :: Python :: 3 :: Only",
22+
"Programming Language :: Python :: 3.12",
23+
"Programming Language :: Python :: 3.13",
24+
"Programming Language :: Python :: Implementation :: PyPy",
25+
"Topic :: Utilities",
26+
]
27+
28+
dynamic = [ "version" ]
29+
urls.Homepage = "https://github.com/cdgriffith/puremagic"
30+
scripts.fastflix = "puremagic.__main__:command_line_entry"
31+
32+
[dependency-groups]
33+
dev = [
34+
"coverage>=7.9.2",
35+
"pre-commit>=4.2",
36+
"pytest>=8.4.1",
37+
"pytest-cov>=6.2.1",
38+
"ruff>=0.12.2",
39+
"setuptools>=80.9",
40+
"twine>=6.1",
41+
"wheel>=0.45.1",
642
]
7-
exclude = '''
8-
/(
9-
\.eggs
10-
| \.git
11-
| \.idea
12-
| \.pytest_cache
13-
| \.github
14-
| _build
15-
| build
16-
| dist
17-
| venv
18-
| test/resources
19-
)/
20-
'''
43+
44+
[tool.setuptools.packages.find]
45+
where = [ "." ]
46+
include = [ "puremagic*" ]
47+
48+
[tool.setuptools.package-data]
49+
"*" = [ '*.json' ]
50+
51+
[tool.setuptools.dynamic]
52+
version = { attr = "puremagic.main.__version__" }
2153

2254
[tool.ruff]
55+
target-version = "py312"
56+
2357
line-length = 120
58+
indent-width = 4
2459

25-
lint.select = [
26-
"ALL",
60+
# Exclude a variety of commonly ignored directories.
61+
exclude = [
62+
".direnv",
63+
".eggs",
64+
".git",
65+
".git-rewrite",
66+
".ipynb_checkpoints",
67+
".mypy_cache",
68+
".pytest_cache",
69+
".pytype",
70+
".ruff_cache",
71+
".venv",
72+
".vscode",
73+
"__pypackages__",
74+
"_build",
75+
"buck-out",
76+
"build",
77+
"dist",
78+
"venv",
2779
]
28-
lint.extend-ignore = [
29-
"ANN",
30-
"B008",
31-
"BLE001",
32-
"C408",
33-
"C901", # too complex
34-
"COM812",
35-
"D",
36-
"EM101",
37-
"EM103",
38-
"EXE001",
39-
"F401",
40-
"F403",
41-
"FA102",
42-
"FBT",
43-
"FIX002",
44-
"I001",
45-
"INP001",
46-
"N817",
47-
"PERF401",
48-
"PGH003",
49-
"PLR0911", # Too many return statements
50-
"PLR0912", # Too many branches
51-
"PLR0913", # Too many arguments in function definition
52-
"PLR2004",
53-
"PT",
54-
"PTH",
55-
"PYI024",
56-
"S101",
57-
"S110",
58-
"S112",
59-
"S314",
60-
"SLF001",
61-
"T201",
62-
"TCH003",
63-
"TD002",
64-
"TD003",
65-
"TRY003",
66-
"UP",
67-
]
68-
lint.pylint.allow-magic-value-types = [
69-
"float",
70-
"int",
71-
"str",
72-
]
73-
lint.pylint.max-branches = 13
80+
81+
# Like Black, indent with spaces, rather than tabs.
82+
format.indent-style = "space"
83+
# Like Black, use double quotes for strings.
84+
format.quote-style = "double"
85+
format.line-ending = "lf"
86+
# Like Black, respect magic trailing commas.
87+
format.skip-magic-trailing-comma = false
88+
# Set the line length limit used when formatting code snippets in
89+
# docstrings.
90+
#
91+
# This only has an effect when the `docstring-code-format` setting is
92+
# enabled.
93+
format.docstring-code-line-length = "dynamic"
94+
# Enable auto-formatting of code examples in docstrings. Markdown,
95+
# reStructuredText code/literal blocks and doctests are all supported.
96+
#
97+
# This is currently disabled by default, but it is planned for this
98+
# to be opt-out in the future.
99+
format.docstring-code-format = true
100+
lint.fixable = [ "F541" ]
101+
lint.unfixable = [ "F401" ]

0 commit comments

Comments
 (0)