Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install the latest version of uv and activate the environment
uses: astral-sh/setup-uv@v6

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
run: uv sync --frozen

- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
uv build
uv run twine upload dist/*
29 changes: 10 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.12", "3.13"]
python-version: ["3.12", "3.13", "3.14-dev"]
include:
- os: macos-latest
python-version: '3.13'
Expand All @@ -31,33 +31,24 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: 'pip'

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

- name: Verify Code with Black
run: |
black --check puremagic test
- name: Install dependencies
run: uv sync --frozen

- name: Lint with flake8
run: |
# stop the tests if there are linting errors
flake8 puremagic --count --show-source --statistics
- name: Verify Code with Ruff
run: uv run ruff check

- name: Test with pytest
run: |
python -m pytest --cov=puremagic test/
run: uv run pytest --cov=puremagic test/

- name: Check distribution log description
shell: bash
run: |
python setup.py sdist bdist_wheel
twine check dist/*
uv build
uv run twine check dist/*
ls -lah "dist/"
WHL=$(find dist -name *.whl -print -quit)
echo ${WHL}
11 changes: 0 additions & 11 deletions .pep8speaks.yml

This file was deleted.

21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,27 @@ repos:
- id: end-of-file-fixer
exclude: ^test/resources/.+


- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
hooks:
- id: ruff

- repo: https://github.com/ambv/black
rev: 24.10.0
# Ruff version.
rev: v0.12.2
hooks:
- id: black
# Run the linter.
- id: ruff-check
args: [ --fix ]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.13.0'
rev: 'v1.16.1'
hooks:
- id: mypy

- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.5.0
rev: v2.6.0
hooks:
- id: pyproject-fmt

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.22
rev: v0.24.1
hooks:
- id: validate-pyproject
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ Version 2.0.0

- Adding deep scan for improved accuracy #102 #94 #70 #69 #12 #3
- Changing to full semantic versioning to be able to denote bugfixes vs minor features
- Changing to use uv instead of requirements
- 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

Version 1.30
------------

- Adding #109 Halt on non-regular files like /dev/zero and /dev/random (thanks to Yuri Schaeffer)

Version 1.29
------------

Expand Down
4 changes: 2 additions & 2 deletions puremagic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python
from puremagic.main import *
from puremagic.main import __author__, __version__
from puremagic.main import * # noqa: F403
from puremagic.main import __author__, __version__ # noqa: F401
12 changes: 9 additions & 3 deletions puremagic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from puremagic.scanners import zip_scanner, pdf_scanner, text_scanner, json_scanner, python_scanner

__author__ = "Chris Griffith"
__version__ = "2.0.0b2"
__version__ = "2.0.0b3"
__all__ = [
"magic_file",
"magic_string",
Expand Down Expand Up @@ -218,6 +218,8 @@ def _magic(header: bytes, footer: bytes, mime: bool, ext=None, filename=None) ->

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


def command_line_entry(*args):
import sys
from argparse import ArgumentParser
import sys # noqa: PLC0415
from argparse import ArgumentParser # noqa: PLC0415

parser = ArgumentParser(
description=(
Expand Down Expand Up @@ -530,14 +532,18 @@ def what(file: os.PathLike | str | None, h: bytes | None = None, imghdr_strict:
```python
# Replace...
from imghdr import what

# with...
from puremagic import what

# ---
# Or replace...
import imghdr

ext = imghdr.what(...)
# with...
import puremagic

ext = puremagic.what(...)
```
imghdr documentation: https://docs.python.org/3.12/library/imghdr.html
Expand Down
1 change: 0 additions & 1 deletion puremagic/scanners/zip_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def office_check(internal_files: list[str], zip_file: ZipFile, extension: str |


def jar_check(internal_files: list[str], zip_file: ZipFile) -> Match | None:

if "META-INF/MANIFEST.MF" not in internal_files:
return None
if "version.json" not in internal_files:
Expand Down
162 changes: 95 additions & 67 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,73 +1,101 @@
[tool.black]
line-length = 120
target-version = [
'py312',
'py313',
[build-system]
build-backend = "setuptools.build_meta"

requires = [ "setuptools", "setuptools-scm[toml]>=6.2", "wheel" ]

[project]
name = "puremagic"
description = "Pure python implementation of magic file detection"
readme = "README.rst"
license = "MIT"
authors = [
{ name = "Chris Griffith", email = "[email protected]" },
]
requires-python = ">=3.12"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Utilities",
]

dynamic = [ "version" ]
urls.Homepage = "https://github.com/cdgriffith/puremagic"
scripts.fastflix = "puremagic.__main__:command_line_entry"

[dependency-groups]
dev = [
"coverage>=7.9.2",
"pre-commit>=4.2",
"pytest>=8.4.1",
"pytest-cov>=6.2.1",
"ruff>=0.12.2",
"setuptools>=80.9",
"twine>=6.1",
"wheel>=0.45.1",
]
exclude = '''
/(
\.eggs
| \.git
| \.idea
| \.pytest_cache
| \.github
| _build
| build
| dist
| venv
| test/resources
)/
'''

[tool.setuptools.packages.find]
where = [ "." ]
include = [ "puremagic*" ]

[tool.setuptools.package-data]
"*" = [ '*.json' ]

[tool.setuptools.dynamic]
version = { attr = "puremagic.main.__version__" }

[tool.ruff]
target-version = "py312"

line-length = 120
indent-width = 4

lint.select = [
"ALL",
# Exclude a variety of commonly ignored directories.
exclude = [
".direnv",
".eggs",
".git",
".git-rewrite",
".ipynb_checkpoints",
".mypy_cache",
".pytest_cache",
".pytype",
".ruff_cache",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"venv",
]
lint.extend-ignore = [
"ANN",
"B008",
"BLE001",
"C408",
"C901", # too complex
"COM812",
"D",
"EM101",
"EM103",
"EXE001",
"F401",
"F403",
"FA102",
"FBT",
"FIX002",
"I001",
"INP001",
"N817",
"PERF401",
"PGH003",
"PLR0911", # Too many return statements
"PLR0912", # Too many branches
"PLR0913", # Too many arguments in function definition
"PLR2004",
"PT",
"PTH",
"PYI024",
"S101",
"S110",
"S112",
"S314",
"SLF001",
"T201",
"TCH003",
"TD002",
"TD003",
"TRY003",
"UP",
]
lint.pylint.allow-magic-value-types = [
"float",
"int",
"str",
]
lint.pylint.max-branches = 13

# Like Black, indent with spaces, rather than tabs.
format.indent-style = "space"
# Like Black, use double quotes for strings.
format.quote-style = "double"
format.line-ending = "lf"
# Like Black, respect magic trailing commas.
format.skip-magic-trailing-comma = false
# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
format.docstring-code-line-length = "dynamic"
# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
format.docstring-code-format = true
lint.fixable = [ "F541" ]
lint.unfixable = [ "F401" ]
Loading