Skip to content

Commit f60eab8

Browse files
authored
Merge branch 'master' into patch-1
2 parents ed9624a + a2634a0 commit f60eab8

38 files changed

+715
-58
lines changed

.coveragerc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[run]
2+
branch = True
3+
4+
omit =
5+
examples/*
6+
tests/*
7+
8+
source = filetype
9+
10+
[report]
11+
exclude_lines =
12+
# Don't complain if non-runnable code isn't run:
13+
if __name__ == ['"]+__main__['"]+:
14+
if ['"]+__main__['"]+ == __name__:

.github/workflows/test.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: CI
5+
6+
on:
7+
push:
8+
branches: [ master ]
9+
pull_request:
10+
branches: [ master ]
11+
12+
jobs:
13+
14+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
15+
16+
release_test:
17+
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ ubuntu-latest ]
23+
python-version: ["3.9"]
24+
25+
steps:
26+
27+
- name: Checkout
28+
uses: actions/checkout@v2
29+
with:
30+
fetch-depth: 0
31+
ref: ${{ github.event.pull_request.head.sha }}
32+
33+
- name: Set up Python ${{ matrix.python-version }}
34+
uses: actions/setup-python@v2
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
38+
- name: Upgrade PIP
39+
run: python -m pip install --upgrade pip
40+
41+
- name: Install application with ML
42+
run: python -m pip install .
43+
44+
- name: CLI tool check
45+
run: filetype --help
46+
47+
- name: Install test framework dependencies
48+
run: python -m pip install tox
49+
50+
- name: Run tox pipeline
51+
run: tox
52+
53+
- name: HTML coverage reports
54+
if: always()
55+
uses: actions/upload-artifact@v2
56+
with:
57+
name: coverage_${{ matrix.python-version }}
58+
path: coverage
59+

History.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,68 @@
11

2+
v1.2.0 / 2022-11-02
3+
===================
4+
5+
* chore(version): bump minor
6+
* Merge pull request #147 from sayanarijit/fix-146
7+
* Add tests for m4a
8+
* Try matching audio before video
9+
* Merge pull request #145 from RSabet/master
10+
* update README to include avif
11+
* added image filetype avif
12+
* Update __init__.py
13+
* Merge pull request #141 from ferstar/master
14+
* test: remove unused imported(F401)
15+
* refactor: duck-typing reading magic string and try to restore the reader position if possible
16+
* test: fix E275 missing whitespace after keyword
17+
* test: Use tox pipeline instead of pytest
18+
* test: ignore E501 error for flake8 check
19+
* fix: CLI params parser
20+
* Merge pull request #137 from ferstar/master
21+
* fix: guess ".docx" func and add another doc file test case
22+
* fix: guess ".doc" func and add another doc file test case
23+
* test: skip benchmark test in tox config
24+
* fix: restore reader position after retrieving signature bytes
25+
* Merge pull request #136 from ferstar/master
26+
* test: no need to skip zstd test case
27+
* Merge pull request #135 from ferstar/master
28+
* fix: regression for file-like obj file type detection
29+
* Merge pull request #134 from babenek/actions
30+
* Merge pull request #129 from ferstar/master
31+
* Merge branch 'master' into master
32+
* Merge pull request #133 from magbyr/master
33+
* Merge pull request #131 from babenek/master
34+
* CI workflow in github actions
35+
* Changed to if statements in matching method
36+
* Changed return method because of coverage calculation problems
37+
* Extra line at EOF
38+
* Extra line at EOF
39+
* Extra line at EOF
40+
* Apply suggestions from code review
41+
* README changes
42+
* Linter changes
43+
* Added document filetypes for doc, docx, odt, xls, xlsx, ods, ppt, pptx and odp. Added tests and sample documents for document filetypes
44+
* Fix undocumented exception
45+
* style: Simplify binary to integer method
46+
* feat: add zstd skippable frames support
47+
* test: fix the tox config and missing test sample files
48+
* test: fix the zst test sample file
49+
* fix(readme): rst syntax wtf
50+
51+
v1.1.0 / 2022-07-12
52+
===================
53+
54+
* feat(version): bump minor
55+
* Merge pull request #127 from ferstar/master
56+
* Merge pull request #123 from levrik/patch-1
57+
* Merge pull request #126 from babenek/master
58+
* docs: add zstd type
59+
* fix: remove unnecessary duck-typing try
60+
* feat: add zst(d) type
61+
* chore: fix lint errors
62+
* test: fix memoryview test cases
63+
* BugFix for uncaught exceptions
64+
* Support PDF with BOM
65+
266
v1.0.13 / 2022-04-21
367
====================
468

README.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Image
7777
- **psd** - ``image/vnd.adobe.photoshop``
7878
- **ico** - ``image/x-icon``
7979
- **heic** - ``image/heic``
80+
- **avif** - ``image/avif``
8081

8182
Video
8283
^^^^^
@@ -122,7 +123,6 @@ Archive
122123
- **pdf** - ``application/pdf``
123124
- **exe** - ``application/x-msdownload``
124125
- **swf** - ``application/x-shockwave-flash``
125-
126126
- **rtf** - ``application/rtf``
127127
- **eot** - ``application/octet-stream``
128128
- **ps** - ``application/postscript``
@@ -136,6 +136,20 @@ Archive
136136
- **lzo** - ``application/x-lzop``
137137
- **lz** - ``application/x-lzip``
138138
- **lz4** - ``application/x-lz4``
139+
- **zstd** - ``application/zstd``
140+
141+
Document
142+
^^^^^^^^
143+
144+
- **doc** - ``application/msword``
145+
- **docx** - ``application/vnd.openxmlformats-officedocument.wordprocessingml.document``
146+
- **odt** - ``application/vnd.oasis.opendocument.text``
147+
- **xls** - ``application/vnd.ms-excel``
148+
- **xlsx** - ``application/vnd.openxmlformats-officedocument.spreadsheetml.sheet``
149+
- **ods** - ``application/vnd.oasis.opendocument.spreadsheet``
150+
- **ppt** - ``application/vnd.ms-powerpoint``
151+
- **pptx** - ``application/vnd.openxmlformats-officedocument.presentationml.presentation``
152+
- **odp** - ``application/vnd.oasis.opendocument.presentation``
139153

140154
Font
141155
^^^^

filetype/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
from .match import * # noqa
88

99
# Current package semver version
10-
__version__ = version = '1.0.13'
10+
__version__ = version = '1.2.0'

filetype/__main__.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import filetype
24

35

@@ -12,17 +14,23 @@ def guess(path):
1214
def main():
1315
import argparse
1416

15-
parser = argparse.ArgumentParser(description='Determine type of FILEs.')
16-
parser.add_argument("file", nargs='+')
17-
parser.add_argument('-v', '--version', action='store_true',
18-
help='output version information and exit')
17+
parser = argparse.ArgumentParser(
18+
prog='filetype', description='Determine type of FILEs.'
19+
)
20+
parser.add_argument('-f', '--file', nargs='+')
21+
parser.add_argument(
22+
'-v', '--version', action='version',
23+
version='%(prog)s ' + filetype.version,
24+
help='output version information and exit'
25+
)
26+
1927
args = parser.parse_args()
28+
if len(sys.argv) < 2:
29+
parser.print_help()
30+
sys.exit(1)
2031

21-
if args.version:
22-
print(filetype.version)
23-
else:
24-
for i in args.file:
25-
guess(i)
32+
for i in args.file:
33+
guess(i)
2634

2735

2836
if __name__ == '__main__':

filetype/filetype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def guess(obj):
1414
Infers the type of the given input.
1515
1616
Function is overloaded to accept multiple types in input
17-
and peform the needed type inference based on it.
17+
and perform the needed type inference based on it.
1818
1919
Args:
2020
obj: path to file, bytes or bytearray.

filetype/helpers.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import absolute_import
44
from .types import TYPES
55
from .match import (
6-
image_match, font_match,
6+
image_match, font_match, document_match,
77
video_match, audio_match, archive_match
88
)
99

@@ -122,3 +122,19 @@ def is_font(obj):
122122
TypeError: if obj is not a supported type.
123123
"""
124124
return font_match(obj) is not None
125+
126+
127+
def is_document(obj):
128+
"""
129+
Checks if a given input is a supported type document.
130+
131+
Args:
132+
obj: path to file, bytes or bytearray.
133+
134+
Returns:
135+
True if obj is a valid document. Otherwise False.
136+
137+
Raises:
138+
TypeError: if obj is not a supported type.
139+
"""
140+
return document_match(obj) is not None

filetype/match.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .types import ARCHIVE as archive_matchers
66
from .types import AUDIO as audio_matchers
77
from .types import APPLICATION as application_matchers
8+
from .types import DOCUMENT as document_matchers
89
from .types import FONT as font_matchers
910
from .types import IMAGE as image_matchers
1011
from .types import VIDEO as video_matchers
@@ -135,3 +136,20 @@ def application_match(obj):
135136
TypeError: if obj is not a supported type.
136137
"""
137138
return match(obj, application_matchers)
139+
140+
141+
def document_match(obj):
142+
"""
143+
Matches the given input against the available
144+
document type matchers.
145+
146+
Args:
147+
obj: path to file, bytes or bytearray.
148+
149+
Returns:
150+
Type instance if matches. Otherwise None.
151+
152+
Raises:
153+
TypeError: if obj is not a supported type.
154+
"""
155+
return match(obj, document_matchers)

filetype/types/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from . import archive
66
from . import audio
77
from . import application
8+
from . import document
89
from . import font
910
from . import image
1011
from . import video
@@ -28,6 +29,7 @@
2829
image.Ico(),
2930
image.Heic(),
3031
image.Dcm(),
32+
image.Avif(),
3133
)
3234

3335
# Supported video types
@@ -90,13 +92,27 @@
9092
archive.Lz(),
9193
archive.Elf(),
9294
archive.Lz4(),
95+
archive.Zstd(),
9396
)
9497

9598
# Supported archive container types
9699
APPLICATION = (
97100
application.Wasm(),
98101
)
99102

103+
# Supported document types
104+
DOCUMENT = (
105+
document.Doc(),
106+
document.Docx(),
107+
document.Odt(),
108+
document.Xls(),
109+
document.Xlsx(),
110+
document.Ods(),
111+
document.Ppt(),
112+
document.Pptx(),
113+
document.Odp(),
114+
)
115+
100116

101117
# Expose supported type matchers
102-
TYPES = list(VIDEO + IMAGE + AUDIO + FONT + ARCHIVE + APPLICATION)
118+
TYPES = list(IMAGE + AUDIO + VIDEO + FONT + DOCUMENT + ARCHIVE + APPLICATION)

0 commit comments

Comments
 (0)