Skip to content

Commit 25bf76f

Browse files
authored
Merge pull request #84 from brocksam/re-regex
CI test re and regex
2 parents 56a10b1 + 017f13c commit 25bf76f

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

.github/workflows/test.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: test
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build-with-required-deps:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Setup Python
11+
uses: actions/setup-python@v2
12+
with:
13+
python-version: "3.9"
14+
- name: Install
15+
run: python setup.py install
16+
- name: Tests
17+
run: |
18+
pip install nose
19+
nosetests
20+
21+
build-with-optional-deps:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v2
25+
- name: Setup Python
26+
uses: actions/setup-python@v2
27+
with:
28+
python-version: "3.9"
29+
- name: Install with optional dependencies
30+
run: |
31+
pip install regex
32+
python setup.py install
33+
- name: Tests
34+
run: |
35+
pip install nose
36+
nosetests

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ python:
77
- "3.6"
88
- "3.7"
99
- "3.8"
10+
- "3.9"
1011

1112
install: pip install tox-travis regex coveralls nose
1213
script: tox

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def read_version(rel_path):
3232
"Programming Language :: Python :: 3.6",
3333
"Programming Language :: Python :: 3.7",
3434
"Programming Language :: Python :: 3.8",
35+
"Programming Language :: Python :: 3.9",
3536
"Programming Language :: Python :: Implementation :: CPython",
3637
"License :: OSI Approved :: MIT License",
3738
"Natural Language :: English",
@@ -45,8 +46,8 @@ def read_version(rel_path):
4546
packages=find_packages(),
4647
include_package_data=True,
4748
zip_safe=False,
48-
tests_require=['nose>=1.0', 'regex>=2020.4.4'],
49-
extras_requires=['regex>=2020.4.4'],
49+
extras_require={'test': 'nose>=1.0',
50+
'regex': 'regex>=2020.4.4'},
5051
test_suite="titlecase.tests",
5152
entry_points = {
5253
'console_scripts': [

titlecase/__init__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import regex
1919
except ImportError:
2020
import re as regex
21+
REGEX_AVAILABLE = False
22+
else:
23+
REGEX_AVAILABLE = True
2124

2225
__all__ = ['titlecase']
2326
__version__ = '2.1.0'
@@ -26,17 +29,27 @@
2629
PUNCT = r"""!"“#$%&'‘()*+,\-–‒—―./:;?@[\\\]_`{|}~"""
2730

2831
SMALL_WORDS = regex.compile(r'^(%s)$' % SMALL, regex.I)
29-
INLINE_PERIOD = regex.compile(r'[\p{Letter}][.][\p{Letter}]', regex.I)
30-
UC_ELSEWHERE = regex.compile(r'[%s]*?[\p{Letter}]+[\p{Uppercase_Letter}]+?' % PUNCT)
31-
CAPFIRST = regex.compile(r"^[%s]*?([\p{Letter}])" % PUNCT)
32+
3233
SMALL_FIRST = regex.compile(r'^([%s]*)(%s)\b' % (PUNCT, SMALL), regex.I)
3334
SMALL_LAST = regex.compile(r'\b(%s)[%s]?$' % (SMALL, PUNCT), regex.I)
3435
SUBPHRASE = regex.compile(r'([:.;?!\-–‒—―][ ])(%s)' % SMALL)
35-
APOS_SECOND = regex.compile(r"^[dol]{1}['‘]{1}[\p{Letter}]+(?:['s]{2})?$", regex.I)
36-
UC_INITIALS = regex.compile(r"^(?:[\p{Uppercase_Letter}]{1}\.{1}|[\p{Uppercase_Letter}]{1}\.{1}[\p{Uppercase_Letter}]{1})+$")
3736
MAC_MC = regex.compile(r"^([Mm]c|MC)(\w.+)")
3837
MR_MRS_MS_DR = regex.compile(r"^((m((rs?)|s))|Dr)$", regex.I)
3938

39+
if REGEX_AVAILABLE:
40+
INLINE_PERIOD = regex.compile(r'[\p{Letter}][.][\p{Letter}]', regex.I)
41+
UC_ELSEWHERE = regex.compile(r'[%s]*?[\p{Letter}]+[\p{Uppercase_Letter}]+?' % PUNCT)
42+
CAPFIRST = regex.compile(r"^[%s]*?([\p{Letter}])" % PUNCT)
43+
APOS_SECOND = regex.compile(r"^[dol]{1}['‘]{1}[\p{Letter}]+(?:['s]{2})?$", regex.I)
44+
UC_INITIALS = regex.compile(r"^(?:[\p{Uppercase_Letter}]{1}\.{1}|[\p{Uppercase_Letter}]{1}\.{1}[\p{Uppercase_Letter}]{1})+$")
45+
else:
46+
INLINE_PERIOD = regex.compile(r'[\w][.][\w]', regex.I)
47+
UC_ELSEWHERE = regex.compile(r'[%s]*?[a-zA-Z]+[A-Z]+?' % PUNCT)
48+
CAPFIRST = regex.compile(r"^[%s]*?([\w])" % PUNCT)
49+
APOS_SECOND = regex.compile(r"^[dol]['‘][\w]+(?:['s]{2})?$", regex.I)
50+
UC_INITIALS = regex.compile(r"^(?:[A-Z]\.|[A-Z]\.[A-Z])+$")
51+
52+
4053
class Immutable(object):
4154
pass
4255

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# and then run "tox" from this directory.
55

66
[tox]
7-
envlist = py34, py35, py36, py37, py38
7+
envlist = py34, py35, py36, py37, py38, py39
88
# Doesn't seem to work on jython currently; some unicode issue
99
# pypy breaks on Travis, something from a pulled dep: https://travis-ci.org/ppannuto/python-titlecase/jobs/308106681
1010

0 commit comments

Comments
 (0)