Git Product home page Git Product logo

ufonormalizer's Introduction

Coverage Status Python Versions PyPI Version

ufoNormalizer

Provides a standard formatting so that there are meaningful diffs in version control rather than formatting noise.

Examples of formatting applied by ufoNormalizer include:

  • Changing floating-point numbers to integers where it doesn't alter the value (e.g. x="95.0" becomes x="95" )
  • Rounding floating-point numbers to 10 digits
  • Formatting XML with tabs rather than spaces

Usage in RoboFont

RoboFont comes with ufoNormalizer pre-installed, and you can set a preference to normalize UFOs on save.

Simply open the Scripting Window and run the following code:

from mojo.UI import setDefault, getDefault

setDefault("shouldNormalizeOnSave", True)

print("shouldNormalizeOnSave is set to " + str(getDefault("shouldNormalizeOnSave")))

Advanced usage

Installation

Install these tools using the pip package hosted on PyPI:

pip install --upgrade ufonormalizer

Command line

Use on the command line:

ufonormalizer <path>/font.ufo

To view all arguments, run:

ufonormalizer --help

Note: if you are working on a UFO within RoboFont and run ufoNormalizer on that UFO, RoboFont will notify you that the UFO has been updated externally. Simply accept this by selecting "Update."

Automating via Git hooks

Beyond basic command-line usage, ufoNormalizer can be used in an automated manner.

Of course, you can automate it to run from a shell script or a Python script. One useful possibility is using it within a Git hook.

Git hooks are scripts that Git executes before or after events such as: commit, push, and receive. Git hooks are a built-in feature - no need to download anything. Git hooks are run locally. โ€“ from Git Hooks

It's easy to set up a git hook that will normalize ufos in a project immediately before each commit, ensuring that you only ever commit clean UFO data.

In a Git project, navigate to /.git/hooks and replace pre-commit.sample with the following code, then remove the file extension:

#!/bin/sh

# A hook script to verify what is about to be committed.
# Called by "git commit" with no arguments.
#
# Uses bash syntax to call arguments as needed.
#
# To enable this hook, save this to <your_project>/.git/hooks/pre-commit (with no file extension)

set -e

for ufo in ./*.ufo; do
    ufonormalizer "$ufo"
done

Now, each time you commit, all .ufos in your Git project will be normalized before being recorded by Git.

Because this hook is setup within the immediate project, this configuration will only apply to the immediate project. You will need to update each project to use this Git hook if you wish to normalize UFOs elsewhere. If you want this hook to be added to all future git projects, you can configure a global git template. However, this approach probably doesn't make sense if you also work on projects that don't involve UFO files.

ufonormalizer's People

Contributors

anthrotype avatar belluzj avatar benkiel avatar cmyr avatar colinmford avatar frankrolf avatar josh-hadley avatar khaledhosny avatar madig avatar miguelsousa avatar moyogo avatar readroberts avatar thundernixon avatar typesupply avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.