Skip to content

Commit f303e21

Browse files
authored
Feature/british (#9)
* ignore tests * added british dialogue regex * added tests for british dialogue * added actions * removed 2.7, 3.6, and added 3.10 * reordered job dependencies * auto approved dependabot and davidlday * updated readme for british style * v1.1.0 * splitting out jobs * reuse community workflow * maybe just in workflows? * nope * try from a different repo * spelling matters * moved python-lint to community health repo * use reusables * use community testpub and pub * reusable autoapprove
1 parent e584fbb commit f303e21

10 files changed

Lines changed: 105 additions & 112 deletions

File tree

.github/dependabot.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
version: 2
22
updates:
3-
- package-ecosystem: pip
4-
directory: "/"
5-
schedule:
6-
interval: weekly
7-
day: friday
8-
time: "17:00"
9-
timezone: America/New_York
10-
open-pull-requests-limit: 10
11-
reviewers:
12-
- davidlday
3+
- package-ecosystem: pip
4+
directory: "/"
5+
schedule:
6+
interval: monthly
7+
timezone: America/New_York
8+
open-pull-requests-limit: 10
9+
reviewers:
10+
- davidlday
11+
- package-ecosystem: "github-actions"
12+
directory: "/"
13+
schedule:
14+
interval: monthly
15+
timezone: America/New_York
16+
open-pull-requests-limit: 10
17+
reviewers:
18+
- davidlday
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Dependabot auto-approve
2+
on: pull_request
3+
4+
permissions:
5+
pull-requests: write
6+
7+
jobs:
8+
dependabot:
9+
uses: prosegrinder/.github/.github/workflows/dependabot-autoapprove.yaml@main

.github/workflows/pypi-publish.yml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,5 @@ on:
55
types: [created]
66

77
jobs:
8-
deploy:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v2
12-
- name: Set up Python
13-
uses: actions/setup-python@v2
14-
with:
15-
python-version: "3.x"
16-
- name: Install dependencies
17-
run: |
18-
python -m pip install --upgrade pip
19-
pip install setuptools wheel twine build
20-
- name: Build Dists
21-
run: |
22-
python -m build
23-
- name: Publish to PyPI
24-
uses: pypa/gh-action-pypi-publish@release/v1
25-
with:
26-
user: __token__
27-
password: ${{ secrets.PYPI_API_TOKEN }}
8+
python-publish:
9+
uses: prosegrinder/.github/.github/workflows/python-publish.yaml@main

.github/workflows/pypi-test-publish.yml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,5 @@ on:
66
- "v*"
77

88
jobs:
9-
deploy:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v2
13-
- name: Set up Python
14-
uses: actions/setup-python@v2
15-
with:
16-
python-version: "3.x"
17-
- name: Install dependencies
18-
run: |
19-
python -m pip install --upgrade pip
20-
pip install setuptools wheel twine build
21-
- name: Build Dists
22-
run: |
23-
python -m build
24-
- name: Publish to PyPI
25-
uses: pypa/gh-action-pypi-publish@release/v1
26-
with:
27-
user: __token__
28-
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
29-
repository_url: https://test.pypi.org/legacy/
9+
python-test-publish:
10+
uses: prosegrinder/.github/.github/workflows/python-test-publish.yaml@main

.github/workflows/python-ci.yml

Lines changed: 14 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,21 @@
1-
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3-
41
name: Python CI
52

6-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
710

811
jobs:
912
lint:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- name: Check Out
13-
uses: actions/checkout@v2
14-
- name: Black
15-
uses: psf/black@stable
16-
- name: Pylint
17-
uses: cclauss/GitHub-Action-for-pylint@0.7.0
18-
with:
19-
args: pip install .; pylint src/**/*.py
13+
uses: prosegrinder/.github/.github/workflows/python-lint.yaml@main
2014

21-
test:
22-
runs-on: ubuntu-latest
23-
strategy:
24-
matrix:
25-
python-version: [2.7, 3.6, 3.7, 3.8, 3.9]
26-
steps:
27-
- uses: actions/checkout@v2
28-
- name: Set up Python ${{ matrix.python-version }}
29-
uses: actions/setup-python@v2
30-
with:
31-
python-version: ${{ matrix.python-version }}
32-
- name: Install dependencies
33-
run: |
34-
python -m pip install --upgrade pip
35-
- name: Install module
36-
run: |
37-
pip install -e .
38-
- name: Test with pytest
39-
run: |
40-
pip install pytest
41-
pytest
15+
check-build:
16+
uses: prosegrinder/.github/.github/workflows/python-check-build.yaml@main
17+
needs: lint
4218

43-
check_build:
44-
runs-on: ubuntu-latest
45-
steps:
46-
- name: Check Out
47-
uses: actions/checkout@v2
48-
- name: Set up Python
49-
uses: actions/setup-python@v2
50-
with:
51-
python-version: "3.x"
52-
- name: Install dependencies
53-
run: |
54-
python -m pip install --upgrade pip
55-
pip install setuptools wheel twine build
56-
- name: Build
57-
run: python -m build
58-
- name: Check
59-
run: twine check dist/*
19+
test:
20+
uses: prosegrinder/.github/.github/workflows/python-test.yaml@main
21+
needs: check-build

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ignore=CVS
1414

1515
# Add files or directories matching the regex patterns to the blacklist. The
1616
# regex matches against base names, not paths.
17-
ignore-patterns=
17+
ignore-patterns=test_
1818

1919
# Python code to execute, usually for sys.path manipulation such as
2020
# pygtk.require().

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ $ python setup.py install
2727

2828
## Usage
2929

30-
`narrative` splits a piece of prose into narrative and dialogue
31-
components. The main function `split()` will return a dict containing
32-
both `narrative` and `dialogue` components:
30+
`narrative` splits a piece of prose into narrative and dialogue components. The
31+
main function `split()` will return a dict containing both `narrative` and
32+
`dialogue` components:
3333

3434
```python
3535
>>> import narrative
@@ -50,11 +50,29 @@ There are two other helper functions as well.
5050
`get_narrative()` returns only the narrative components:
5151

5252
```python
53-
>>> narrative.get_dialogue(text)
53+
>>> narrative.get_narrative(text)
5454
['', ' he said. ', '']
5555
```
5656

57-
Note: The empty strings are a feature of Python's `split()` function.
58-
See [Why are empty strings returned in split()
59-
results?](https://stackoverflow.com/questions/2197451/why-are-empty-strings-returned-in-split-results#2197493)
57+
Note: The empty strings are a feature of Python's `split()` function. See
58+
[Why are empty strings returned in split() results?](https://stackoverflow.com/questions/2197451/why-are-empty-strings-returned-in-split-results#2197493)
6059
for an explanation.
60+
61+
### British Style
62+
63+
Each function accepts a second parameter of a regular expression used to parse
64+
out the dialogue. This defaults to `narrative.DIALOGUE_RE`, which follows the
65+
American standard of using double quotes for initial quotes. `narrative` now
66+
includes a second regular expression, `narrative.BRITISH_DIALOGUE_RE`, which
67+
follows the British style of using single quotes for initial quotes. Simply use
68+
it as the second parameter for any function:
69+
70+
```python
71+
>>> import narrative
72+
>>> narrative.split(text, narrative.BRITISH_DIALOGUE_RE)
73+
>>>
74+
>>> narrative.get_dialogue(text, narrative.BRITISH_DIALOGUE_RE)
75+
>>>
76+
>>> narrative.get_narrative(text, narrative.BRITISH_DIALOGUE_RE)
77+
>>>
78+
```

src/narrative/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1
1+
1.1.0

src/narrative/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# DIALOGUE_RE = r'[\"“]((?:.(?![\"“]))*.?)[\"”\\n]'
2424
DIALOGUE_RE = re.compile(r"[\"“](?:.(?![\"“]))*.?[\"”\\n]", re.MULTILINE)
2525

26+
BRITISH_DIALOGUE_RE = re.compile(r"['‘](?:.(?!['‘]))*.?['’\n]", re.MULTILINE)
27+
2628

2729
def get_dialogue(text, dialogue_regex=DIALOGUE_RE):
2830
"""Get the dialogue fragments from a piece of text

tests/test_narrative.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
import narrative
44

5+
BRITISH_EXCERPT = """‘Economic systems’, according to Professor White, ‘are an inevitable byproduct of civilization, and are, as John Doe said, “with us whether we want them or not”’.
6+
"""
7+
# https://www.thepunctuationguide.com/british-versus-american-style.html
8+
9+
BRITISH_DIALOGUE = [
10+
"‘Economic systems’",
11+
"‘are an inevitable byproduct of civilization, and are, as John Doe said, “with us whether we want them or not”’.\n",
12+
]
13+
14+
BRITISH_NARRATIVE = ["", ", according to Professor White, ", ""]
15+
16+
517
EXCERPT = """Some one recklessly lifted the veil. By one breath of an uttered word he destroyed the serene charm, and uncovered the truth in its ugly nakedness. No thought was clearly defined in his mind, when his lips smilingly asked: "Why do you not tell us, Lazarus, what was There?" And all became silent, struck with the question. Only now it seemed to have occurred to them that for three days Lazarus had been dead; and they looked with curiosity, awaiting an answer. But Lazarus remained silent.
618
719
"You will not tell us?" wondered the inquirer. "Is it so terrible there?"
@@ -35,3 +47,24 @@ def test_parse():
3547
"narrative": NARRATIVE,
3648
"dialogue": DIALOGUE,
3749
} # nosec
50+
51+
52+
def test_get_dialogue_british():
53+
assert (
54+
narrative.get_dialogue(BRITISH_EXCERPT, narrative.BRITISH_DIALOGUE_RE)
55+
== BRITISH_DIALOGUE
56+
) # nosec
57+
58+
59+
def test_get_narrative_british():
60+
assert (
61+
narrative.get_narrative(BRITISH_EXCERPT, narrative.BRITISH_DIALOGUE_RE)
62+
== BRITISH_NARRATIVE
63+
) # nosec
64+
65+
66+
def test_parse_british():
67+
assert narrative.split(BRITISH_EXCERPT, narrative.BRITISH_DIALOGUE_RE) == {
68+
"narrative": BRITISH_NARRATIVE,
69+
"dialogue": BRITISH_DIALOGUE,
70+
} # nosec

0 commit comments

Comments
 (0)