Skip to content

Commit

Permalink
Merge branch 'release-02'
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Nov 4, 2018
2 parents 6dc2ae8 + 6618a2a commit d834e6e
Show file tree
Hide file tree
Showing 30 changed files with 1,382 additions and 1,142 deletions.
6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
skip=.tox
not_skip=__init__.py
multi_line_output = 3
balanced_wrapping = 1
include_trailing_comma = 1
10 changes: 10 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[MASTER]
ignore=docs
disable=
missing-docstring,
wildcard-import,
unused-wildcard-import,
too-few-public-methods,
invalid-name,
arguments-differ,
too-many-instance-attributes,
13 changes: 5 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
sudo: false
language: python
sudo: required
dist: xenial
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6-dev"
- "3.6"
- "3.7"
cache:
directories:
- $HOME/.cache/pip
Expand All @@ -16,4 +13,4 @@ script:
- tox
after_success:
- coverage report
- codecov
- codecov
6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include LICENSE
include MANIFEST.in
graft typus
graft tests
global-exclude __pycache__
global-exclude *.py[co]
30 changes: 22 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ and let it handle all that formating headache:

Copy & paste this example to your rich text editor. Result may depend on
the font of your choice.
For instance, there is a tiny non-breakable space between ``A. A.`` you
For instance, there is a tiny non-breaking space between ``A. A.`` you
can see with Helvetica:

.. image:: https://raw.githubusercontent.com/byashimov/typus/develop/docs/example.png
Expand All @@ -42,7 +42,7 @@ Usage
-----

Currently Typus supports English and Russian languages only.
Which doesn't mean it can't handle more. I'm quite sure it covers Serbian
But it doesn't mean it can't handle more. I'm quite sure it covers Serbian
and Turkmen.

In fact, Typus doesn't make difference between languages. It works with text.
Expand Down Expand Up @@ -85,11 +85,12 @@ What it does
- Replaces vulgar fractions ``1/2`` with unicode characters: ``½``.
- Turns multiply symbol to a real one: ``3x3`` becomes ``3×3``.
- Replaces quotes with primes: ``2' 4"`` becomes ``2′ 4″``.
- Puts non-breakable spaces.
- Puts non-breaking spaces.
- Puts ruble symbol.
- Trims spaces at the end of lines.
- and much more.


Documentation
-------------

Expand All @@ -113,14 +114,27 @@ Compatibility
:alt: Codecov
:target: https://codecov.io/gh/byashimov/typus

Tested on Python 2.6, 2.7, 3.3, 3.4, 3.5, 3.6.
Tested on Python 3.6, 3.7.


Changelog
---------

0.2
~~~

- Python 3.6 and higher are supported only.
However should work on any 3.x branch. That's because 3.6 string formatting is
used in tests to make them easier to read and write.
- ``EnRuExpressions`` is no longer a mixin but processor.
- Better, cleaner tests with pytest.
- Minor fixes and improvements.

0.1
~~~

Todo
----
- Initial release.

- Rewrite tests, they are ugly as hell.
- Add missing doctests.

.. _demo: https://byashimov.com/typus/
.. _web-service: https://byashimov.com/typus/api/
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
# built documents.
#
# The short X.Y version.
version = '0.1'
version = '0.2'
# The full version, including alpha/beta/rc tags.
release = '0.1'
release = '0.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
18 changes: 8 additions & 10 deletions docs/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ that for you.
The anatomy
-----------

Typus uses :ref:`Processors` to do the job and :ref:`Mixins` as
those settings. And there is a :py:class:`typus.core.TypusCore`
class which makes all of them work together. Here is a quick example:
:py:class:`typus.core.TypusCore` runs :ref:`Processors` to do the job
which can be plugged in for desired configuration.
Here is a quick example:

.. testcode::

from typus.core import TypusCore
from typus.mixins import EnQuotes
from typus.processors import Quotes
from typus.processors import EnQuotes

class MyTypus(EnQuotes, TypusCore):
processors = (Quotes, )
class MyTypus(TypusCore):
processors = (EnQuotes, )

my_typus = MyTypus()
assert my_typus('"quoted text"') == '“quoted text”'

:py:class:`typus.core.TypusCore` runs :py:class:`typus.processors.Quotes`
processor which uses *quotes* configuration from
:py:class:`typus.mixins.EnQuotes`.
:py:class:`typus.core.TypusCore` runs :py:class:`typus.processors.EnQuotes`
processor which improves *quotes* only.
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Contents

get_started
processors
mixins
utils


Expand Down
9 changes: 0 additions & 9 deletions docs/mixins.rst

This file was deleted.

27 changes: 11 additions & 16 deletions docs/processors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,29 @@ In python:
from typus.processors import BaseProcessor, EscapeHtml

class MyTrimProcessor(BaseProcessor):
def __call__(self, func):
def inner(text, *args, **kwargs):
# When processor is initiated it gets typus instance
# as the first argument so you can access to it's configuration
# any time
if self.typus.trim:
trimmed = text.strip()
else:
trimmed = text
return func(trimmed, *args, **kwargs)
return inner
def run(self, text, **kwargs):
# When processor is initiated it gets typus instance
# as the first argument so you can access to it's configuration
# any time
if self.typus.trim:
trimmed = text.strip()
else:
trimmed = text
return self.run_other(trimmed, **kwargs)
class MyTypus(TypusCore):
# This becomes a single function. EscapeHtml goes first
processors = (EscapeHtml, MyTrimProcessor)

# Set it `False` to disable trimming
# Set it to `False` to disable trimming
trim = True

my_typus = MyTypus()
assert my_typus(' test ') == 'test'


Processors can be configured with :ref:`Mixins`.


Built-in processors
-------------------

.. automodule:: typus.processors
:members:
:members: EnQuotes, RuQuotes, EnRuExpressions, EscapeHtml, EscapePhrases
9 changes: 9 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[pytest]
addopts =
-v
-rs
--cov=typus
--cov-report=term-missing
--pylint
--doctest-modules
--isort
13 changes: 3 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

setup(
name='typus',
version='0.1',
description='Multilanguage language typographer',
version='0.2',
description='Multilanguage language typograph',
url='https://github.com/byashimov/typus',
author='Murad Byashimov',
author_email='byashimov@gmail.com',
packages=['typus'],
install_requires=['future'],
license='BSD',
classifiers=[
'Development Status :: 4 - Beta',
Expand All @@ -17,14 +16,8 @@
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
)
6 changes: 6 additions & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pytest==3.6.3
pytest-cov==2.5.1
pytest-pylint==0.11.0
pytest-mock==1.10.0
pytest-isort==0.2.0
Sphinx==1.7.6
32 changes: 13 additions & 19 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import pytest

from builtins import * # noqa

import mock
import unittest2
from typus import TypusCore, ru_typus


class TypusTest(unittest2.TestCase):
@mock.patch('typus.ru_typus.process')
def test_empty(self, mock_process):
self.assertEqual(ru_typus(''), '')
mock_process.assert_not_called()
def test_empty_string(mocker):
mocker.patch('typus.ru_typus.procs')
assert ru_typus('') == ''
ru_typus.procs.run.assert_not_called()


def test_debug(self):
self.assertEqual(ru_typus('2mm', debug=True), '2_mm')
def test_debug_true():
assert ru_typus('2mm', debug=True) == '2_mm'


class BaseTypusTest(unittest2.TestCase):
def test_empty(self):
class Testus(TypusCore):
pass
def test_no_processors():
class Testus(TypusCore):
pass

with self.assertRaises(AssertionError):
Testus()
with pytest.raises(AssertionError):
Testus()

0 comments on commit d834e6e

Please sign in to comment.