<commit_before>from __future__ import absolute_import

from units import unit, scaled_unit, named_unit
import units.predefined

units.predefined.define_units()

Percentage = unit('%')
Meter = unit('m')
Kilometer = scaled_unit('m', 'km', 1000)
Hour = unit('h')
KilometersPerHour = unit('km') / unit('h')
RotationsPerMinute = unit('rotations') / unit('m')
Litre = unit('L')
Degree = unit('deg')
NewtonMeter = named_unit("Nm", ["N", "m"], [])
MetersPerSecondSquared = unit('m') / (pow(unit('s'), 2))
Undefined = unit('undef')
<commit_msg>Monkeypatch the units library so it works in Python 3.<commit_after>from __future__ import absolute_import

import sys
from units import unit, scaled_unit, named_unit
import units.predefined


def monkey_patch_units():
    """The units library doesn't support Python3 out of the box, but it's really
    close. This function monkey patches a few things that make it compatible,
    and it can be phased out when the units library is updated.
    """
    from units.leaf_unit import LeafUnit
    from units.named_composed_unit import NamedComposedUnit
    # Division changed in Python 3 so there are now two methods that can be
    # overridden, __truediv__ for the "/" operator and __floordiv__ for "//".
    LeafUnit.__truediv__ = LeafUnit.__div__
    NamedComposedUnit.__truediv__ = NamedComposedUnit.__div__

    # Previously, objects without a __cmp__ method could be implicitly compared
    # by their ids. It gave a consistent order for 1 program runtime. The __lt__
    # method is now required for sorting, and here we just use the identity
    # which should have the same effect.
    def less_than_by_id(self, other):
        return id(self) < id(other)
    LeafUnit.__lt__ = less_than_by_id


    # Again, no more __cmp__
    from units.quantity import Quantity
    Quantity.__lt__ = Quantity.__cmp__


    # No more cmp function either, so these must be redefined
    def cmp(a, b):
        return (a > b) - (a < b)

    import units.quantity
    units.quantity.cmp = cmp

if sys.version_info[:2] >= (3, 0):
    monkey_patch_units()

units.predefined.define_units()

Percentage = unit('%')
Meter = unit('m')
Kilometer = scaled_unit('m', 'km', 1000)
Hour = unit('h')
KilometersPerHour = unit('km') / unit('h')
RotationsPerMinute = unit('rotations') / unit('m')
Litre = unit('L')
Degree = unit('deg')
NewtonMeter = named_unit("Nm", ["N", "m"], [])
MetersPerSecondSquared = unit('m') / (pow(unit('s'), 2))
Undefined = unit('undef')


{'fraction_non_alphanumeric': 0.11788453774727493, 'fraction_numerical': 0.006863140896245458, 'mean_word_length': 4.216842105263158, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '456592', 'n_tokens_mistral': 837, 'n_tokens_neox': 786, 'n_words': 258}