pre-commit/identify — 297★ on GitHub (Python). File identification library for Python
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
identify also has an api for determining what type of license is contained
in a file. This routine is roughly based on the approaches used by
licensee (the ruby gem that github uses to figure out the license for a
repo).
The approach that identify uses is as follows:
Strip the copyright line
Normalize all whitespace
Return any exact matches
Return the closest by edit distance (where edit distance < 5%)
To use the api, install via pip install identify[license]
>>> from identify import identify
>>> identify.license_id('LICENSE')
'MIT'
The return value of the license_id function is an SPDX id. Currently
licenses are sourced from choosealicense.com.
How it works
A call to tags_from_path does this:
What is the type: file, symlink, directory? If it's not file, stop here.
Is it executable? Add the appropriate tag.
Do we recognize the file extension? If so, add the appropriate tags, stop
here. These tags would include binary/text.
Peek at the first X bytes of the file. Use these to determine whether it is
binary or text, add the appropriate tag.
If identified as text above, try to read and interpret the shebang, and add
appropriate tags.
By design, this means we don't need to partially read files where we recognize
the file extension.
Yes — pre-commit/identify ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/pre-commit/identify.
What is pre-commit/identify?
pre-commit/identify (pre-commit/identify) is a Python project on GitHub. From the project's own README: File identification library for Python
Where do I read more about pre-commit/identify?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/pre-commit/identify is the definitive source.
Read full README in the tab above.
Still deciding about identify?
One click hands the question to an AI along with this page — see what it says about identify.