graphemeu 0.7.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ # This workflow will install Python dependencies, run tests and lint with a single version of Python
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3
+
4
+ name: Python package
5
+
6
+ on:
7
+ push:
8
+ branches: [ "master" ]
9
+ pull_request:
10
+ branches: [ "master" ]
11
+
12
+ permissions:
13
+ contents: read
14
+
15
+ jobs:
16
+ build:
17
+ runs-on: ubuntu-latest
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - name: Install uv
25
+ uses: astral-sh/setup-uv@v2
26
+ with:
27
+ enable-cache: true
28
+ - name: Set up Python ${{ matrix.python-version }}
29
+ run: uv python install ${{ matrix.python-version }}
30
+ - name: Install the project
31
+ run: uv sync --all-extras --dev
32
+ - name: Lint with ruff
33
+ run: uvx ruff check .
34
+ - name: Format with ruff
35
+ run: uvx ruff format --check .
36
+ - name: Test with unittest
37
+ run: uv run --extra dev -m pytest
@@ -0,0 +1,61 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+
5
+ # C extensions
6
+ *.so
7
+
8
+ # Distribution / packaging
9
+ .Python
10
+ env/
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ lib/
17
+ lib64/
18
+ parts/
19
+ sdist/
20
+ var/
21
+ *.egg-info/
22
+ .installed.cfg
23
+ *.egg
24
+
25
+ # PyInstaller
26
+ # Usually these files are written by a python script from a template
27
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
28
+ *.manifest
29
+ *.spec
30
+
31
+ # Installer logs
32
+ pip-log.txt
33
+ pip-delete-this-directory.txt
34
+
35
+ # Unit test / coverage reports
36
+ htmlcov/
37
+ .tox/
38
+ .coverage
39
+ .cache
40
+ nosetests.xml
41
+ coverage.xml
42
+
43
+ # Translations
44
+ *.mo
45
+ *.pot
46
+
47
+ # Django stuff:
48
+ *.log
49
+
50
+ # Sphinx documentation
51
+ docs/_build/
52
+
53
+ # PyBuilder
54
+ target/
55
+
56
+ # OS X
57
+ .DS_Store
58
+
59
+ # Other
60
+ .python-version
61
+ .pytest_cache
@@ -0,0 +1,31 @@
1
+ # Read the Docs configuration file
2
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3
+
4
+ # Required
5
+ version: 2
6
+
7
+ # Set the OS, Python version and other tools you might need
8
+ build:
9
+ os: ubuntu-22.04
10
+ tools:
11
+ python: "3.12"
12
+ # You can also specify other tool versions:
13
+ # nodejs: "19"
14
+ # rust: "1.64"
15
+ # golang: "1.19"
16
+
17
+ # Build documentation in the "docs/" directory with Sphinx
18
+ sphinx:
19
+ configuration: docs/conf.py
20
+
21
+ # Optionally build your docs in additional formats such as PDF and ePub
22
+ # formats:
23
+ # - pdf
24
+ # - epub
25
+
26
+ # Optional but recommended, declare the Python requirements required
27
+ # to build your documentation
28
+ # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
29
+ # python:
30
+ # install:
31
+ # - requirements: docs/requirements.txt
@@ -0,0 +1,15 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Python Debugger: Current File",
9
+ "type": "debugpy",
10
+ "request": "launch",
11
+ "program": "${file}",
12
+ "console": "integratedTerminal"
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "python.analysis.typeCheckingMode": "basic"
3
+ }
@@ -0,0 +1,51 @@
1
+ ## 0.7.2
2
+ Fix bug #2 found by alwaysmpe.
3
+ No API changes.
4
+
5
+ ## 0.7.1
6
+ Fix bug #1 found by alwaysmpe.
7
+ No API changes.
8
+
9
+ ## 0.7.0
10
+ Added support for Unicode 16.
11
+ Drops support for python 3.6. Now tested on python 3.7 - 3.12.
12
+ No API changes.
13
+
14
+ ## 0.6.0
15
+ Added support for Unicode 13.
16
+
17
+ Drops support for python 3.4 & 3.5. Now tested on python 3.6 - 3.8.
18
+ No API changes
19
+
20
+ ## 0.5.0
21
+ Added support for Unicode 12.
22
+
23
+ No API changes
24
+
25
+ ## 0.4.0
26
+ Added support for Unicode 11.
27
+
28
+ Added `grapheme.UNICODE_VERSION`.
29
+
30
+ No other API changes
31
+
32
+ ## 0.3.0
33
+ Added a few new functions:
34
+
35
+ * `grapheme.safe_split_index`, which can find the highest grapheme boundary index in a given string without traversing the full grapheme sequence.
36
+ * `grapheme.startswith`, which tests that a given string starts with the same grapheme sequence as a given prefix.
37
+ * `grapheme.endswith`, which tests that a given string ends with the same grapheme sequence as a given suffix.
38
+
39
+ ## 0.2.1
40
+ Performance improvements
41
+
42
+ No new functionality, but noticably better performance.
43
+
44
+ ## 0.2.0
45
+ * Adds `grapheme.contains`
46
+ * Bugfix for empty strings
47
+
48
+ ## 0.1.0
49
+ Initial release
50
+
51
+ Basic support for getting graphemes, grapheme string lengths and grapheme based slicing.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 The Python Packaging Authority (PyPA)
2
+ Copyright (c) 2014 Mapbox
3
+ Copyright (c) 2017 Alvin Lindstam
4
+ Copyright (c) 2025 Timendum
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,191 @@
1
+ Metadata-Version: 2.4
2
+ Name: graphemeu
3
+ Version: 0.7.2
4
+ Summary: Unicode grapheme helpers
5
+ Project-URL: Homepage, https://github.com/timendum/grapheme
6
+ Project-URL: Documentation, https://graphemeu.readthedocs.io/
7
+ Author-email: Alvin Lindstam <alvin.lindstam@gmail.com>
8
+ Maintainer: Timendum
9
+ License: Copyright (c) 2017 The Python Packaging Authority (PyPA)
10
+ Copyright (c) 2014 Mapbox
11
+ Copyright (c) 2017 Alvin Lindstam
12
+ Copyright (c) 2025 Timendum
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENSE
32
+ Keywords: grapheme,unicode
33
+ Classifier: Development Status :: 4 - Beta
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: Programming Language :: Python
36
+ Requires-Python: >=3.7
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest; extra == 'dev'
39
+ Provides-Extra: docs
40
+ Requires-Dist: sphinx; extra == 'docs'
41
+ Requires-Dist: sphinx-autobuild; extra == 'docs'
42
+ Description-Content-Type: text/x-rst
43
+
44
+ grapheme
45
+ ========
46
+
47
+ A Python package for working with user perceived characters. More specifically,
48
+ string manipulation and calculation functions for working with grapheme cluster
49
+ groups (graphemes) as defined by the `Unicode Standard Annex #29 <http://unicode.org/reports/tr29/>`_.
50
+
51
+ `documentation <https://graphemeu.readthedocs.io/>`_
52
+
53
+ .. code-block:: console
54
+
55
+ pip install graphemeu
56
+
57
+ Or similar.
58
+
59
+ The currently supported version of Unicode: 16.0.0.
60
+
61
+ This package is a fork of `grapheme <https://github.com/alvinlindstam/grapheme>`_ by Alvin Lindstam.
62
+
63
+ What? Why?
64
+ ==========
65
+
66
+ Unicode strings are made up of a series of unicode characters, but a unicode character does not
67
+ always map to a user perceived character. Some human perceived characters are represented as two
68
+ or more unicode characters.
69
+
70
+ However, all built in python string functions and string methods work with single unicode characters
71
+ without considering their connection to each other.
72
+
73
+ .. code-block:: python
74
+
75
+ >>> string = 'u̲n̲d̲e̲r̲l̲i̲n̲e̲d̲'
76
+ >>> len(string)
77
+ 20
78
+ >>> grapheme.length(string)
79
+ 10
80
+ >>> string[:3]
81
+ 'u̲n'
82
+ >>> grapheme.slice(string, 0, 3)
83
+ 'u̲n̲d̲'
84
+
85
+ This library implements the unicode default rules for extended grapheme clusters, and provides
86
+ a set of functions for string manipulation based on graphemes.
87
+
88
+ Documentation
89
+ =============
90
+
91
+ See `<https://graphemeu.readthedocs.io/en/latest/>`_.
92
+
93
+ When should I consider graphemes instead of unicode characters?
94
+ ===============================================================
95
+
96
+ You should consider working with graphemes over unicode code points when:
97
+
98
+ * You wish to count characters as perceived by users.
99
+ * You wish to split or truncate text at some user perceived lengths.
100
+ * You wish to split or truncate text without risk of corrupting the characters.
101
+ * Formatting text by length, such as creating text based tables in monospaced fonts
102
+
103
+ You should work with normal python string functions when:
104
+
105
+ * You wish to count or split by unicode codepoints for compliance with storage
106
+ limitations (such as database maximum length)
107
+ * When working with systems that put limits on strings by unicode character
108
+ lengths
109
+ * When you prioritize performance over correctness (see performance notes below)
110
+ * When working with very long strings (see performance notes below)
111
+ * If simplicity is more important than accuracy
112
+
113
+ Performance
114
+ ===========
115
+
116
+ Calculating graphemes require traversing the string and checking each character
117
+ against a set of rules and the previous character(s). Because of this, all
118
+ functions in this module will scale linearly to the string length.
119
+
120
+ Whenever possible, they will only traverse the string for as long as needed and return
121
+ early as soon as the requested output is generated. For example, the `grapheme.slice`
122
+ function only has to traverse the string until the last requested grapheme is found, and
123
+ does not care about the rest of the string.
124
+
125
+ You should probably only use this package for testing/manipulating fairly short strings
126
+ or with the beginning of long strings.
127
+
128
+ When testing with a string of 10 000 ascii characters, and a 3.1 GHz processor, the execution
129
+ time for some possible calls is roughly:
130
+
131
+ ================================================================ ==========================
132
+ Code Approximate execution time
133
+ ================================================================ ==========================
134
+ `len(long_ascii_string)` 3.0e-10 seconds
135
+ `grapheme.length(long_ascii_string)` 4.3e-05 seconds
136
+ `grapheme.length(long_ascii_string, 500)` 2.6e-06 seconds
137
+ `long_ascii_string[0:100]` 1.3e-09 seconds
138
+ `grapheme.slice(long_ascii_string, 0, 100)` 6.3e-07 seconds
139
+ `long_ascii_string[:100] in long_ascii_string` 7.8e-09 seconds
140
+ `grapheme.contains(long_ascii_string, long_ascii_string[:100])` 9.9e-07 seconds
141
+ `long_ascii_string[-100:] in long_ascii_string` 2.0e-08 seconds
142
+ `grapheme.contains(long_ascii_string, long_ascii_string[-100:])` 6.9e-05 seconds
143
+ ================================================================ ==========================
144
+
145
+ Execution times may improve in later releases, but calculating graphemes is and will continue
146
+ to be notably slower than just counting unicode code points.
147
+
148
+ Examples of grapheme cluster groups
149
+ ===================================
150
+
151
+ This is not a complete list, but a some examples of when graphemes use multiple
152
+ characters:
153
+
154
+ * CR+LF
155
+ * Hangul (korean)
156
+ * Emoji with modifiers
157
+ * Combining marks
158
+ * Zero Width Join
159
+
160
+ Development quick start
161
+ =======================
162
+
163
+ If you wish to contribute or edit this package, create a fork and clone it.
164
+
165
+ Then install and run the tests.
166
+
167
+ .. code-block:: console
168
+
169
+ uv run --extra dev -m pytest
170
+
171
+ For the documentation, use:
172
+
173
+ .. code-block:: console
174
+
175
+ uv run --extra docs sphinx-autobuild docs dist/www
176
+
177
+ Unicode version upgrade
178
+ -----------------------
179
+
180
+ The library will issue a new release for each new unicode version.
181
+
182
+ The steps necessary for this:
183
+
184
+ 1. Verify that there has been no material changes to the rulesets in Unicode
185
+ `Annex #29 <http://unicode.org/reports/tr29/>`_ (see modifications).
186
+ 2. Download the `data files <http://www.unicode.org/Public/>`_ from unicode into the unicode-data folder.
187
+ For the given version, some are in `ucd` and some are in `ucd/auxiliary`.
188
+ 3. Run `make process-data-files` to parse those files (will update the
189
+ `grapheme_break_property.json` and `derived_core_property.json` files).
190
+ 4. Update the unicode version in the documentation and in the source code.
191
+ 5. Bump the version.
@@ -0,0 +1,148 @@
1
+ grapheme
2
+ ========
3
+
4
+ A Python package for working with user perceived characters. More specifically,
5
+ string manipulation and calculation functions for working with grapheme cluster
6
+ groups (graphemes) as defined by the `Unicode Standard Annex #29 <http://unicode.org/reports/tr29/>`_.
7
+
8
+ `documentation <https://graphemeu.readthedocs.io/>`_
9
+
10
+ .. code-block:: console
11
+
12
+ pip install graphemeu
13
+
14
+ Or similar.
15
+
16
+ The currently supported version of Unicode: 16.0.0.
17
+
18
+ This package is a fork of `grapheme <https://github.com/alvinlindstam/grapheme>`_ by Alvin Lindstam.
19
+
20
+ What? Why?
21
+ ==========
22
+
23
+ Unicode strings are made up of a series of unicode characters, but a unicode character does not
24
+ always map to a user perceived character. Some human perceived characters are represented as two
25
+ or more unicode characters.
26
+
27
+ However, all built in python string functions and string methods work with single unicode characters
28
+ without considering their connection to each other.
29
+
30
+ .. code-block:: python
31
+
32
+ >>> string = 'u̲n̲d̲e̲r̲l̲i̲n̲e̲d̲'
33
+ >>> len(string)
34
+ 20
35
+ >>> grapheme.length(string)
36
+ 10
37
+ >>> string[:3]
38
+ 'u̲n'
39
+ >>> grapheme.slice(string, 0, 3)
40
+ 'u̲n̲d̲'
41
+
42
+ This library implements the unicode default rules for extended grapheme clusters, and provides
43
+ a set of functions for string manipulation based on graphemes.
44
+
45
+ Documentation
46
+ =============
47
+
48
+ See `<https://graphemeu.readthedocs.io/en/latest/>`_.
49
+
50
+ When should I consider graphemes instead of unicode characters?
51
+ ===============================================================
52
+
53
+ You should consider working with graphemes over unicode code points when:
54
+
55
+ * You wish to count characters as perceived by users.
56
+ * You wish to split or truncate text at some user perceived lengths.
57
+ * You wish to split or truncate text without risk of corrupting the characters.
58
+ * Formatting text by length, such as creating text based tables in monospaced fonts
59
+
60
+ You should work with normal python string functions when:
61
+
62
+ * You wish to count or split by unicode codepoints for compliance with storage
63
+ limitations (such as database maximum length)
64
+ * When working with systems that put limits on strings by unicode character
65
+ lengths
66
+ * When you prioritize performance over correctness (see performance notes below)
67
+ * When working with very long strings (see performance notes below)
68
+ * If simplicity is more important than accuracy
69
+
70
+ Performance
71
+ ===========
72
+
73
+ Calculating graphemes require traversing the string and checking each character
74
+ against a set of rules and the previous character(s). Because of this, all
75
+ functions in this module will scale linearly to the string length.
76
+
77
+ Whenever possible, they will only traverse the string for as long as needed and return
78
+ early as soon as the requested output is generated. For example, the `grapheme.slice`
79
+ function only has to traverse the string until the last requested grapheme is found, and
80
+ does not care about the rest of the string.
81
+
82
+ You should probably only use this package for testing/manipulating fairly short strings
83
+ or with the beginning of long strings.
84
+
85
+ When testing with a string of 10 000 ascii characters, and a 3.1 GHz processor, the execution
86
+ time for some possible calls is roughly:
87
+
88
+ ================================================================ ==========================
89
+ Code Approximate execution time
90
+ ================================================================ ==========================
91
+ `len(long_ascii_string)` 3.0e-10 seconds
92
+ `grapheme.length(long_ascii_string)` 4.3e-05 seconds
93
+ `grapheme.length(long_ascii_string, 500)` 2.6e-06 seconds
94
+ `long_ascii_string[0:100]` 1.3e-09 seconds
95
+ `grapheme.slice(long_ascii_string, 0, 100)` 6.3e-07 seconds
96
+ `long_ascii_string[:100] in long_ascii_string` 7.8e-09 seconds
97
+ `grapheme.contains(long_ascii_string, long_ascii_string[:100])` 9.9e-07 seconds
98
+ `long_ascii_string[-100:] in long_ascii_string` 2.0e-08 seconds
99
+ `grapheme.contains(long_ascii_string, long_ascii_string[-100:])` 6.9e-05 seconds
100
+ ================================================================ ==========================
101
+
102
+ Execution times may improve in later releases, but calculating graphemes is and will continue
103
+ to be notably slower than just counting unicode code points.
104
+
105
+ Examples of grapheme cluster groups
106
+ ===================================
107
+
108
+ This is not a complete list, but a some examples of when graphemes use multiple
109
+ characters:
110
+
111
+ * CR+LF
112
+ * Hangul (korean)
113
+ * Emoji with modifiers
114
+ * Combining marks
115
+ * Zero Width Join
116
+
117
+ Development quick start
118
+ =======================
119
+
120
+ If you wish to contribute or edit this package, create a fork and clone it.
121
+
122
+ Then install and run the tests.
123
+
124
+ .. code-block:: console
125
+
126
+ uv run --extra dev -m pytest
127
+
128
+ For the documentation, use:
129
+
130
+ .. code-block:: console
131
+
132
+ uv run --extra docs sphinx-autobuild docs dist/www
133
+
134
+ Unicode version upgrade
135
+ -----------------------
136
+
137
+ The library will issue a new release for each new unicode version.
138
+
139
+ The steps necessary for this:
140
+
141
+ 1. Verify that there has been no material changes to the rulesets in Unicode
142
+ `Annex #29 <http://unicode.org/reports/tr29/>`_ (see modifications).
143
+ 2. Download the `data files <http://www.unicode.org/Public/>`_ from unicode into the unicode-data folder.
144
+ For the given version, some are in `ucd` and some are in `ucd/auxiliary`.
145
+ 3. Run `make process-data-files` to parse those files (will update the
146
+ `grapheme_break_property.json` and `derived_core_property.json` files).
147
+ 4. Update the unicode version in the documentation and in the source code.
148
+ 5. Bump the version.
@@ -0,0 +1,20 @@
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line.
5
+ SPHINXOPTS =
6
+ SPHINXBUILD = python -msphinx
7
+ SPHINXPROJ = grapheme
8
+ SOURCEDIR = .
9
+ BUILDDIR = _build
10
+
11
+ # Put it first so that "make" without argument is like "make help".
12
+ help:
13
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
+
15
+ .PHONY: help Makefile
16
+
17
+ # Catch-all target: route all unknown targets to Sphinx using the new
18
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
+ %: Makefile
20
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)