Skip to main content

Python wrapper for ot-sanitizer

Project description

pyots (PYthon OT Sanitizer)

Run Tests Build Python Wheels

PyPI PyPI

macOS ubuntu

Python wrapper for OpenType Sanitizer, also known as just "OTS". It is similar to and partially based on ots-python, but builds OTS as a Python C Extension (instead of as an executable and calling through subprocess as ots-python does).

NOTE: Although this package is similar to ots-python, it is not a drop-in replacement for it, as the Python API is different.

Requirements

The project builds pip-installable wheels for Python 3.7, 3.8, 3.9 or 3.10 under Mac or Linux. It is possible this project will build and run with other Pythons and other operating systems, but it has only been tested with the listed configurations.

Installation with pip

If you just want to use pyots, you can simply run python -m pip install -U pyots (in one of the supported platforms/Python versions) which will install pre-built, compiled, ready-to-use Python wheels. Then you can skip down to the Use section.

Installation/setup for developing pyots

If you'd like to tinker with the pyots code, you will want to get your local setup ready:

  • clone this repo
  • run python setup.py download to download the OTS source (which is not included in this project). You can modify the version value in setup.cfg under [download] to specify a different version of OTS. You'll also need to change the sha256 hash value that corresponds to the OTS tar.xz package. Note that this scheme has some limitations: OTS sources older than 8.1.3 might not build correctly since they used different build systems. Also, versions newer than the one specified in this repo might require adjustments in order to build correctly. What can we say, we're dependent on ots...
  • to build and install pyots after downloading OTS, you can run python setup.py install or python -m pip install .
  • while iterating changes, you will want to delete the temporary build and src/ots/build folders.

Testing

There is a test suite defined for exercising the Python extension. It makes use (and assumes the presence of) the downloaded OTS library source's test font data in src/ots so ensure you have run python setup.py download and have the ots folder under src. Invoke the tests with python -m pytest.

If you wish to run tests comparing results from ots-python against pyots, be sure to python -m pip install opentype-sanitizer first, otherwise that set of tests will be skipped.

Use

Simplest case:

import pyots
result = pyots.sanitize('/path/to/font/file.ttf')

result is an OTSResult object with 3 attributes:

  • sanitized Boolean indicating whether the file was successfully sanitized
  • modified Boolean indicating whether the file was modified* during sanitization
  • messages Tuple of message strings generated during sanitization (may be empty)
  • Note: currently the back-end OTS code can modify fonts that are successfully sanitized, even when no changes are performed. Thus modified can sometimes be True when sanitized is True. Usually the modification is only to the modification date and related checksums. Thus, it might be possible to devise a better detection of modification, i.e. ignoring head.modified and other inconsequential modifications, but that was out-of-scope for this work.

Example: sanitizing a folder of font files

# sanitize a folder of fonts. Print messages for any that were not successfully sanitized.
import pyots
from pathlib import Path

for filename in Path("src/ots/tests/fonts/good").rglob("*"):
    result = pyots.sanitize(filename.absolute())
    if not result.sanitized:
        print('{}:\n{}'.format(filename, "\n".join([m for m in result.messages])))

Options for sanitize()

  • Specify keyword output=<path_to_output_file> to the sanitize() command and the sanitized file will be saved to that location
  • Use quiet=True for sanitize() to suppress messages
  • Specify font_index=<index_in_TTC> when sanitizing a Collection (OTC/TTC) file and you want to sanitize only a particular index within the Collection (otherwise all will be sanitized per OTS's default behavior)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyots-9.0.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distributions

pyots-9.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (737.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyots-9.0.0-cp310-cp310-macosx_10_9_x86_64.whl (343.3 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pyots-9.0.0-cp310-cp310-macosx_10_9_universal2.whl (374.2 kB view details)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

pyots-9.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (737.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyots-9.0.0-cp39-cp39-macosx_10_9_x86_64.whl (343.3 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyots-9.0.0-cp39-cp39-macosx_10_9_universal2.whl (374.1 kB view details)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

pyots-9.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (737.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyots-9.0.0-cp38-cp38-macosx_10_9_x86_64.whl (343.3 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pyots-9.0.0-cp38-cp38-macosx_10_9_universal2.whl (374.2 kB view details)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

pyots-9.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (737.2 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pyots-9.0.0-cp37-cp37m-macosx_10_9_x86_64.whl (343.2 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file pyots-9.0.0.tar.gz.

File metadata

  • Download URL: pyots-9.0.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for pyots-9.0.0.tar.gz
Algorithm Hash digest
SHA256 2025cad958557da1b5802ef9ec3e174f122949dbea553bd7457f982cf80e567f
MD5 673042a432e1e9f66f1d02e0d377b71b
BLAKE2b-256 e187300137cbf8af3b849bfe081707482900c3c64b035ccd2d81044a649fb132

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 562e8061eb0bbf157372cb746dbd5876d97597266a6451cede9430ec0e6917df
MD5 5157a137ed0f556502ea14cf89dc741d
BLAKE2b-256 45d3677573e06c9f61096c00e7ec32be56e9fbb08679489f6d3296fd2d69d6a9

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f26f897739fcab0f7ea4651e33af53dbd3a5d5c8becd0c4b299b65ebf277097f
MD5 a6d069c6ae53753459e4e0133b602e46
BLAKE2b-256 94b2724061fdd008f66b4d20cb1543cb72b48d9c778389ea90b2864d58a407f6

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ab2a6a64cd50cdf4120959b55c50ac10205f30c65a63f30375b4b38aea2ee4f9
MD5 11654611294f62ad08a32033b5381e48
BLAKE2b-256 972a4932ded95187690c4f5e76e8ec6c7ea7dae15c93139c2ec46cbba0b8d773

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a63ed659b178a332deb29e269ed70e26224123d614ac98c24de3ec24ba8e9f4
MD5 545c4bf0ef47bd96db9469b9a431931a
BLAKE2b-256 4d6e341c011aeb9ead4a8f9baad5b834ccb786b6703581b3206dd944f57a6263

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4b233eb0d3035fd6b928a94e7c318010622e2452d664551c3f089ce09c6a458d
MD5 04fa5ffcb7e4cfa6799e86f177d6e2ef
BLAKE2b-256 ac03d4b78ce3ca534b05b111eeb4b82dbb894ae1695f0dd742427d364e021e61

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3b68d8a63c6df5e264a089dd911dd2a831fdb4654f6c3122a56132dc64a0b8ca
MD5 3f33164ffecff59b53b6d4bb12d7eeaa
BLAKE2b-256 3f55fd021d2b2c4f65346bbee58a9eaf26a7cffa9ca0aa7356277c19470d0ddd

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 206f3d2520824a7c8a42ee0c1a4e7aa74cc2ae95fdd8cd71a5d09dd7a5bd70aa
MD5 56935fc6e2e621a6de1f1ed03698650a
BLAKE2b-256 a2e586695e43b2c81532dd9565a7b6b658485f0db9ba42ff58e0391823fd89f5

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6c538a68fe48173712a7f5bc3864e7f20fbe8f8d23f02482f540d57dbf066a36
MD5 1f066d8a286e939f97903afdfde4e2e4
BLAKE2b-256 45acbf7dcfe429463dcd47a9dedba24a336441299d0427558b74d5d5651ed70c

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp38-cp38-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 5d1b4d39984614eb8411913120e6a1beef065e0d30aaeb9143f2e61a4c4ce8c9
MD5 fe6aac8a6fab5b978e4c060c270824c3
BLAKE2b-256 57b3d5a6ca4493a3d5a55f032130a45406fc9a514cf6b0782a56585d410b0808

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 80757ddd42d983b9472ff7cfb91abeca103bb4da7fd8e11fea0593978a372a9d
MD5 2fa44bfb20f8307c08f04fb7a159d2d7
BLAKE2b-256 51cdca56422d9dbf7e2f5b9d0367ffeacb863d0f79c65ab7059e836b3c1ec076

See more details on using hashes here.

File details

Details for the file pyots-9.0.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for pyots-9.0.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 da79b40a09197d1abb908fa2daf905929c9d530328b932f3d7228e4e192b6bdc
MD5 d420f68c0e6d6a13dd4f98c7eceb4a34
BLAKE2b-256 88bbc4fe645add7bf80ae4fd1fbefe09184082e26ee35341ed169e8c54f86ab5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page