Skip to content

Commit

Permalink
Add support for past tense "was/were" and other cleanup (#6)
Browse files Browse the repository at this point in the history
This commit involves some cleanup:

* Sort lists of exceptions
* Add past tense "was" and "were"
* Make the Makefile more useful
* Enforce order in the Actions
* Rebuild the documentation

Signed-off-by: Brian Warner <[email protected]>
  • Loading branch information
brianwarner authored Oct 8, 2024
1 parent c7b84b4 commit 3b1817a
Show file tree
Hide file tree
Showing 43 changed files with 488 additions and 137 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
pytest
build:
name: Build and generate documentation
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
pytest
pypi-publish:
name: Upload release to PyPI and update documentation
needs: test
runs-on: ubuntu-latest
environment: release
permissions:
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
clean:

rm -rf \
__pycache__ \
src/talkgooder/__pycache__ \
tests/__pycache__ \
.pytest_cache \
dist \
_version.py \
src/*.egg-info \
docsrc/_doctrees

test:
pytest

build: clean test
python3 -m build

html: build
sphinx-build -b html docsrc docs -E -d "docsrc/_doctrees"
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: d3775153b19b07eed8a6918b6fa9de0f
config: cfee92e6764fd6783006a9379d7eb90c
tags: 645f666f9bcd5a90fca523b33c5a78b7
23 changes: 9 additions & 14 deletions docs/_modules/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@


<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Overview: module code &mdash; talkGooder 0.0.post1.dev1+gdebd171 documentation</title>
<title>Overview: module code &mdash; talkGooder 0.0.post1.dev1+ge624e3d documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=7ab3649f" />


<!--[if lt IE 9]>
<script src="../_static/js/html5shiv.min.js"></script>
<![endif]-->

<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=80a157c8"></script>
<script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=3c956434"></script>
<script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
Expand All @@ -35,9 +33,6 @@
<a href="../index.html" class="icon icon-home">
talkGooder
</a>
<div class="version">
0.0.post1.dev1+gdebd171
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
Expand Down
108 changes: 74 additions & 34 deletions docs/_modules/talkgooder.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@


<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>talkgooder &mdash; talkGooder 0.0.post1.dev1+gdebd171 documentation</title>
<title>talkgooder &mdash; talkGooder 0.0.post1.dev1+ge624e3d documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=7ab3649f" />


<!--[if lt IE 9]>
<script src="../_static/js/html5shiv.min.js"></script>
<![endif]-->

<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=80a157c8"></script>
<script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=3c956434"></script>
<script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
Expand All @@ -35,9 +33,6 @@
<a href="../index.html" class="icon icon-home">
talkGooder
</a>
<div class="version">
0.0.post1.dev1+gdebd171
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
Expand Down Expand Up @@ -148,30 +143,30 @@ <h1>Source code for talkgooder</h1><div class="highlight"><pre>

<span class="c1"># Same singular as plural, can be extended via addl_same parameter</span>
<span class="n">en_us_same</span> <span class="o">=</span> <span class="p">[</span>
<span class="s2">&quot;sheep&quot;</span><span class="p">,</span>
<span class="s2">&quot;fish&quot;</span><span class="p">,</span>
<span class="s2">&quot;salmon&quot;</span><span class="p">,</span>
<span class="s2">&quot;aircraft&quot;</span><span class="p">,</span>
<span class="s2">&quot;buffalo&quot;</span><span class="p">,</span>
<span class="s2">&quot;deer&quot;</span><span class="p">,</span>
<span class="s2">&quot;fish&quot;</span><span class="p">,</span>
<span class="s2">&quot;goose&quot;</span><span class="p">,</span>
<span class="s2">&quot;hovercraft&quot;</span><span class="p">,</span>
<span class="s2">&quot;moose&quot;</span><span class="p">,</span>
<span class="s2">&quot;salmon&quot;</span><span class="p">,</span>
<span class="s2">&quot;sheep&quot;</span><span class="p">,</span>
<span class="s2">&quot;shrimp&quot;</span><span class="p">,</span>
<span class="s2">&quot;spacecraft&quot;</span><span class="p">,</span>
<span class="s2">&quot;trout&quot;</span><span class="p">,</span>
<span class="s2">&quot;aircraft&quot;</span><span class="p">,</span>
<span class="s2">&quot;watercraft&quot;</span><span class="p">,</span>
<span class="s2">&quot;hovercraft&quot;</span><span class="p">,</span>
<span class="s2">&quot;spacecraft&quot;</span><span class="p">,</span>
<span class="s2">&quot;deer&quot;</span><span class="p">,</span>
<span class="s2">&quot;goose&quot;</span><span class="p">,</span>
<span class="p">]</span> <span class="o">+</span> <span class="n">addl_same</span>

<span class="c1"># Doesn&#39;t follow other rules, plural is always s, can be extended via addl_special_s</span>
<span class="n">en_us_special_s</span> <span class="o">=</span> <span class="p">[</span>
<span class="s2">&quot;roof&quot;</span><span class="p">,</span>
<span class="s2">&quot;proof&quot;</span><span class="p">,</span>
<span class="s2">&quot;spoof&quot;</span><span class="p">,</span>
<span class="s2">&quot;piano&quot;</span><span class="p">,</span>
<span class="s2">&quot;cello&quot;</span><span class="p">,</span>
<span class="s2">&quot;hello&quot;</span><span class="p">,</span>
<span class="s2">&quot;photo&quot;</span><span class="p">,</span>
<span class="s2">&quot;piano&quot;</span><span class="p">,</span>
<span class="s2">&quot;proof&quot;</span><span class="p">,</span>
<span class="s2">&quot;roof&quot;</span><span class="p">,</span>
<span class="s2">&quot;spoof&quot;</span><span class="p">,</span>
<span class="s2">&quot;zero&quot;</span><span class="p">,</span>
<span class="p">]</span> <span class="o">+</span> <span class="n">addl_special_s</span>

Expand All @@ -180,16 +175,16 @@ <h1>Source code for talkgooder</h1><div class="highlight"><pre>
<span class="nb">list</span><span class="p">(</span>
<span class="p">{</span>
<span class="s2">&quot;child&quot;</span><span class="p">:</span> <span class="s2">&quot;children&quot;</span><span class="p">,</span>
<span class="s2">&quot;criterion&quot;</span><span class="p">:</span> <span class="s2">&quot;criteria&quot;</span><span class="p">,</span>
<span class="s2">&quot;die&quot;</span><span class="p">:</span> <span class="s2">&quot;dice&quot;</span><span class="p">,</span>
<span class="s2">&quot;louse&quot;</span><span class="p">:</span> <span class="s2">&quot;lice&quot;</span><span class="p">,</span>
<span class="s2">&quot;man&quot;</span><span class="p">:</span> <span class="s2">&quot;men&quot;</span><span class="p">,</span>
<span class="s2">&quot;mouse&quot;</span><span class="p">:</span> <span class="s2">&quot;mice&quot;</span><span class="p">,</span>
<span class="s2">&quot;ox&quot;</span><span class="p">:</span> <span class="s2">&quot;oxen&quot;</span><span class="p">,</span>
<span class="s2">&quot;person&quot;</span><span class="p">:</span> <span class="s2">&quot;people&quot;</span><span class="p">,</span>
<span class="s2">&quot;phenomenon&quot;</span><span class="p">:</span> <span class="s2">&quot;phenomena&quot;</span><span class="p">,</span>
<span class="s2">&quot;tooth&quot;</span><span class="p">:</span> <span class="s2">&quot;teeth&quot;</span><span class="p">,</span>
<span class="s2">&quot;ox&quot;</span><span class="p">:</span> <span class="s2">&quot;oxen&quot;</span><span class="p">,</span>
<span class="s2">&quot;mouse&quot;</span><span class="p">:</span> <span class="s2">&quot;mice&quot;</span><span class="p">,</span>
<span class="s2">&quot;man&quot;</span><span class="p">:</span> <span class="s2">&quot;men&quot;</span><span class="p">,</span>
<span class="s2">&quot;woman&quot;</span><span class="p">:</span> <span class="s2">&quot;women&quot;</span><span class="p">,</span>
<span class="s2">&quot;louse&quot;</span><span class="p">:</span> <span class="s2">&quot;lice&quot;</span><span class="p">,</span>
<span class="s2">&quot;die&quot;</span><span class="p">:</span> <span class="s2">&quot;dice&quot;</span><span class="p">,</span>
<span class="s2">&quot;phenomenon&quot;</span><span class="p">:</span> <span class="s2">&quot;phenomena&quot;</span><span class="p">,</span>
<span class="s2">&quot;criterion&quot;</span><span class="p">:</span> <span class="s2">&quot;criteria&quot;</span><span class="p">,</span>
<span class="p">}</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
<span class="p">)</span>
<span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="n">addl_irregular</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
Expand Down Expand Up @@ -403,7 +398,7 @@ <h1>Source code for talkgooder</h1><div class="highlight"><pre>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Given a quanity, determine if article should be ``is`` or ``are``.</span>

<span class="sd"> Given a quantity of nouns or noun-equivalents, determine whether the most article should be</span>
<span class="sd"> Given a quantity of nouns or noun-equivalents, determine whether the article should be</span>
<span class="sd"> ``is`` or ``are``. For example, &quot;there is one cat,&quot; and &quot;there are two cats.&quot;</span>

<span class="sd"> **Supported locales:**</span>
Expand Down Expand Up @@ -440,6 +435,51 @@ <h1>Source code for talkgooder</h1><div class="highlight"><pre>



<div class="viewcode-block" id="wasWere">
<a class="viewcode-back" href="../index.html#talkgooder.wasWere">[docs]</a>
<span class="k">def</span> <span class="nf">wasWere</span><span class="p">(</span>
<span class="n">number</span><span class="p">:</span> <span class="nb">int</span> <span class="o">|</span> <span class="nb">float</span><span class="p">,</span>
<span class="n">language</span><span class="o">=</span><span class="s2">&quot;en-US&quot;</span><span class="p">,</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Given a quanity, determine if article should be ``ws`` or ``were``.</span>

<span class="sd"> Given a quantity of nouns or noun-equivalents, determine whether the article should be</span>
<span class="sd"> ``was`` or ``were``. For example, &quot;there was one cat,&quot; and &quot;there were two cats.&quot;</span>

<span class="sd"> **Supported locales:**</span>

<span class="sd"> * ``en-US``: American English</span>

<span class="sd"> Args:</span>
<span class="sd"> number (int | float):</span>
<span class="sd"> Quantity of items.</span>
<span class="sd"> language (str):</span>
<span class="sd"> Which language rules to apply, specified by locale (default ``en-US``).</span>

<span class="sd"> Returns:</span>
<span class="sd"> String:</span>
<span class="sd"> ``was`` or ``were``, as appropriate.</span>

<span class="sd"> Raises:</span>
<span class="sd"> TypeError: number must be an int or float.</span>
<span class="sd"> ValueError: language must be a supported locale.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">number</span><span class="p">,</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">)):</span>
<span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;Number must be an int or a float.&quot;</span><span class="p">)</span>

<span class="k">if</span> <span class="n">language</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;en-us&quot;</span><span class="p">:</span>
<span class="c1"># Anything other than integer 1 (even 1.0) uses &quot;were&quot;</span>
<span class="k">if</span> <span class="n">number</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">number</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
<span class="k">return</span> <span class="s2">&quot;was&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;were&quot;</span>

<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Language must be a supported locale.&quot;</span><span class="p">)</span></div>



<div class="viewcode-block" id="aAn">
<a class="viewcode-back" href="../index.html#talkgooder.aAn">[docs]</a>
<span class="k">def</span> <span class="nf">aAn</span><span class="p">(</span>
Expand Down
Loading

0 comments on commit 3b1817a

Please sign in to comment.