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-8.2.2.tar.gz (18.9 kB view details)

Uploaded Source

Built Distributions

pyots-8.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (725.9 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyots-8.2.2-cp310-cp310-macosx_10_9_x86_64.whl (334.4 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pyots-8.2.2-cp310-cp310-macosx_10_9_universal2.whl (365.5 kB view details)

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

pyots-8.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (725.8 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyots-8.2.2-cp39-cp39-macosx_10_9_x86_64.whl (334.4 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyots-8.2.2-cp39-cp39-macosx_10_9_universal2.whl (365.5 kB view details)

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

pyots-8.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (726.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyots-8.2.2-cp38-cp38-macosx_10_9_x86_64.whl (334.4 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pyots-8.2.2-cp38-cp38-macosx_10_9_universal2.whl (365.5 kB view details)

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

pyots-8.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (725.5 kB view details)

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

pyots-8.2.2-cp37-cp37m-macosx_10_9_x86_64.whl (334.4 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyots-8.2.2.tar.gz
Algorithm Hash digest
SHA256 24e1cbc1d2dd8174312932155bbf82031a6017a448026fac6bf1553f1cbf934d
MD5 947134cf2a7db24464300fd6c1eac9ac
BLAKE2b-256 6c12a36a25d3aaae92d5bce104a13a43c20d9a4c02af5b610b323d447bb7d036

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7f205d42529a2ef3ed3e81b078e36c16272782948dd6540d2c2f5c4fa36eab4c
MD5 5caf961800e95a9be0cb251eb2ce363c
BLAKE2b-256 bcf32a89cee4d0d357937e2431a968e1cd0da89a18f78aa7b9e0c7a79c368c0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 232e81ae1411fe5ea93a44cb9b421dfcdca7a0e2c4dbb352672d6d91313add79
MD5 1ac54bb74165942388a8646bdcd9a01a
BLAKE2b-256 79d1f20ea5b6ee9d5f8721acfc778eee42c0a932d09037891397bd0212b3d6d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6338986a1247a392aecf73b00a483712c57ece1a063267718e3ab2664c531148
MD5 9a19e04fde33f8f3ae60d0e079ee34bf
BLAKE2b-256 6b528dee58eb318d97efc98cff0a923af57182431a4981b823e20515bac4c03e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d674db9139ed3e0f2e1dd4484490748bb07ff9f26d173f284f47a4430dc7b968
MD5 e577a807df85e61d5c59d4e565211390
BLAKE2b-256 6f6d4e75597fff598457bb3cec2d4a0a9ebddb5c4d5c741de2c652d172124b5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1bb283a816348c227f06a0158a79e133c3d01dcc046a5b3439572698c5426ef8
MD5 3e0b5c4e33ab8886818a5b62ae884e91
BLAKE2b-256 bcbf549d44b8830a56315505667d3e1d38c8e9813900a4ad0e6e17db024c41e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 561cd233976a7d993f787b3780ad46a00cafba4b67bb8ff7b7239525b74f50df
MD5 acba64de428cd5b0f3585480281f749d
BLAKE2b-256 68238a17e9c48dfef5ec96cde5f94449f9a96eba05b823c790b3f0d2bb3fbc46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a2c0d58e5bac0f24b1ec17ad9bed6699f3171969cd0bdd6580cea90ab89ec676
MD5 82f2ceedc02105117e5fe82188e50208
BLAKE2b-256 be25b764483f3d94727e5ee42e5af612330de161fa7096236ea4e073aa7a09a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cf0baed5eb56d971e2f7e96f4aafa859d4b84ba94b1e228568b2d0d7c9d9b8bc
MD5 bb964f980683dfa57bc268fdd5068dc8
BLAKE2b-256 200875fc1091fe5ab2ea6cf68a0ace0430c9c1820f48e25858843c2b86d2bed9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 28209c9e7888166dbf517cf72fc434da039d9594d2aa1fe0a7e3074e789caacf
MD5 63c770b17568b5bca372b14c716ebdd2
BLAKE2b-256 0c87cc06b90bed78e28ecfe07bc421e3baf1142c8e94bd6a3019f63666771090

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1edb72d30ace908677d14e931433b89d5c22951973333acc9ffdfc8c18d79b03
MD5 d829eb4c1571141568ae68e82036ff4c
BLAKE2b-256 ebc777ded3a2684494c0df1bd766adc5ff19e27a97faca7ccfc81998bafa9be1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyots-8.2.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7eb79e98028a29b868581d11cf3322553fc36f54e4642a58c4c480302a8e05d0
MD5 b218c216f94a65b933ff40a981f0cd5b
BLAKE2b-256 1e18af37ade2e5d8738d5dea5c00d76798073910fa7e83e896d689dec0dfce7c

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