Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,30 @@ on:
# Run by default Sunday morning at 3:30:
# Scheduled workflows run on the latest commit on the default or base branch.
# (from https://help.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule)
#
# GitHub disables a scheduled workflow after 60 days without a commit to the
# repository, and disabling it stops the push and pull_request triggers too.
# If the badge goes stale, re-enable it on the Actions tab; workflow_dispatch
# below gives a way to run it by hand.
- cron: "30 3 * * 0"
workflow_dispatch:

jobs:
lint:
name: Lint ubuntu-latest Py3.8
name: Lint ubuntu-latest Py3.12
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Additional info about the build
shell: bash
run: |
uname -a
df -h
ulimit -a
# More info on options: https://github.com/conda-incubator/setup-miniconda
- uses: conda-incubator/setup-miniconda@v2
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: 3.8
python-version: "3.12"
environment-file: devtools/conda-envs/test_env.yaml
activate-environment: test
auto-update-conda: false
Expand All @@ -45,8 +51,9 @@ jobs:
- name: Run linters
shell: bash -l {0}
run: |
flake8 reference_handler
yapf --diff --recursive reference_handler
black --extend-exclude '_version.py' --check --diff \
reference_handler reference_handler/tests
flake8 --color never reference_handler reference_handler/tests

test:
name: Test ${{ matrix.os }} Py${{ matrix.python-version }}
Expand All @@ -55,16 +62,16 @@ jobs:
strategy:
matrix:
os: [macOS-latest, ubuntu-latest]
python-version: [3.7, 3.8]
python-version: ["3.11", "3.12"]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Additional info about the build
shell: bash
run: |
uname -a
df -h
ulimit -a
- uses: conda-incubator/setup-miniconda@v2
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
environment-file: devtools/conda-envs/test_env.yaml
Expand All @@ -82,7 +89,7 @@ jobs:
run: |
pytest -v --cov=reference_handler --cov-report=xml --color=yes reference_handler/tests/
- name: CodeCov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
Expand Down
50 changes: 20 additions & 30 deletions .github/workflows/Release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.8]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Additional info about the build
shell: bash
Expand All @@ -30,7 +30,7 @@ jobs:
ulimit -a

# More info on options: https://github.com/conda-incubator/setup-miniconda
- uses: conda-incubator/setup-miniconda@v2
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
environment-file: devtools/conda-envs/test_env.yaml
Expand All @@ -56,8 +56,9 @@ jobs:
shell: bash -l {0}

run: |
flake8 reference_handler reference_handler/tests
yapf --diff --recursive reference_handler
black --extend-exclude '_version.py' --check --diff \
reference_handler reference_handler/tests
flake8 --color never reference_handler reference_handler/tests

test:
name: Test ${{ matrix.os }} Py${{ matrix.python-version }}
Expand All @@ -66,10 +67,10 @@ jobs:
strategy:
matrix:
os: [macOS-latest, ubuntu-latest]
python-version: [3.7, 3.8]
python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Additional info about the build
shell: bash
Expand All @@ -80,7 +81,7 @@ jobs:


# More info on options: https://github.com/conda-incubator/setup-miniconda
- uses: conda-incubator/setup-miniconda@v2
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
environment-file: devtools/conda-envs/test_env.yaml
Expand All @@ -107,7 +108,7 @@ jobs:
pytest -v --cov=reference_handler --cov-report=xml --color=yes reference_handler/tests/

- name: CodeCov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
Expand All @@ -119,27 +120,25 @@ jobs:
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags')
runs-on: ${{ matrix.os }}
needs: [lint, test]

# Trusted publishing: PyPI checks this token against the publisher registered
# for the project, so there is no API token to store or rotate.
permissions:
id-token: write
contents: read
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.8]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install package

# conda setup requires this special shell
shell: bash -l {0}
run: |
python -m pip install . --no-deps
conda list

- name: Install pypa/build
run: |
python -m pip install build --user
Expand All @@ -149,14 +148,5 @@ jobs:
python -m build --sdist --wheel --outdir dist/
ls -l dist/

- name: Publish distribution 馃摝 to Test PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.test_pypi_password }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true

- name: Publish distribution 馃摝 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
uses: pypa/gh-action-pypi-publish@release/v1
7 changes: 4 additions & 3 deletions devtools/conda-envs/test_env.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
name: test

channels:
- conda-forge

dependencies:
# Base depends
- python
- pip

# Testing
- black
- codecov
- coverage
- flake8
Expand All @@ -16,7 +20,4 @@ dependencies:
# Pip-only installs
- pip:
- bibtexparser<2

# Testing
- yapf

4 changes: 2 additions & 2 deletions reference_handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
from ._version import get_versions

versions = get_versions()
__version__ = versions['version']
__git_revision__ = versions['full-revisionid']
__version__ = versions["version"]
__git_revision__ = versions["full-revisionid"]
del get_versions, versions
93 changes: 45 additions & 48 deletions reference_handler/latex_utf8.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,54 +70,53 @@
import typing
import unicodedata

alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

# LaTeX characters in accent macros of form \<char>{<letter>}, i.e. \"{u}
accent = {
'"': '\N{Combining Diaeresis}',
"'": '\N{Combining Acute Accent}',
'.': '\N{Combining Dot Above}',
'=': '\N{Combining Macron}',
'^': '\N{Combining Circumflex Accent}',
'`': '\N{Combining Grave Accent}',
'|': '\N{Combining Vertical Line Above}',
'~': '\N{Combining Tilde}',
'b': '\N{Combining Macron Below}',
'c': '\N{Combining Cedilla}',
'C': '\N{Combining Double Grave Accent}',
'd': '\N{Combining Dot Below}',
'f': '\N{Combining Inverted Breve}',
'h': '\N{Combining Hook Above}',
'H': '\N{Combining Double Acute Accent}',
'k': '\N{Combining Ogonek}',
'r': '\N{Combining Ring Above}',
't': '\N{Combining Double Inverted Breve}',
'u': '\N{Combining Breve}',
'U': '\N{Combining Double Vertical Line Above}',
'v': '\N{Combining Caron}'
'"': "\N{COMBINING DIAERESIS}",
"'": "\N{COMBINING ACUTE ACCENT}",
".": "\N{COMBINING DOT ABOVE}",
"=": "\N{COMBINING MACRON}",
"^": "\N{COMBINING CIRCUMFLEX ACCENT}",
"`": "\N{COMBINING GRAVE ACCENT}",
"|": "\N{COMBINING VERTICAL LINE ABOVE}",
"~": "\N{COMBINING TILDE}",
"b": "\N{COMBINING MACRON BELOW}",
"c": "\N{COMBINING CEDILLA}",
"C": "\N{COMBINING DOUBLE GRAVE ACCENT}",
"d": "\N{COMBINING DOT BELOW}",
"f": "\N{COMBINING INVERTED BREVE}",
"h": "\N{COMBINING HOOK ABOVE}",
"H": "\N{COMBINING DOUBLE ACUTE ACCENT}",
"k": "\N{COMBINING OGONEK}",
"r": "\N{COMBINING RING ABOVE}",
"t": "\N{COMBINING DOUBLE INVERTED BREVE}",
"u": "\N{COMBINING BREVE}",
"U": "\N{COMBINING DOUBLE VERTICAL LINE ABOVE}",
"v": "\N{COMBINING CARON}",
}

# The regexp to detect the LaTeX accent commands. The two added characters
# are the dotless i and j.
accent_re = re.compile(
r'\\([' + ''.join(accent.keys()) + r']){([a-zA-Z\u0131\u0237])}'
)
accent_re = re.compile(r"\\([" + "".join(accent.keys()) + r"]){([a-zA-Z\u0131\u0237])}")

# Invert the accent dictionary for each letter in the alphabet to make
# a dictionary of LaTeX encodings.
encoding = {}
for key, val in accent.items():
for char in list(alphabet):
encoding[char + val] = '\\' + key + '{' + char + '}'
encoding[char + val] = "\\" + key + "{" + char + "}"
# handle any precombined versions of the character
string = unicodedata.normalize('NFC', char + val)
string = unicodedata.normalize("NFC", char + val)
if len(string) == 1:
encoding[string] = encoding[char + val]
for char in [
'\N{Latin Small Letter Dotless I}', '\N{Latin Small Letter Dotless J}'
"\N{LATIN SMALL LETTER DOTLESS I}",
"\N{LATIN SMALL LETTER DOTLESS J}",
]:
encoding[char + val] = r'\%s{%s}' % (key, char)
string = unicodedata.normalize('NFC', char + val)
encoding[char + val] = r"\%s{%s}" % (key, char)
string = unicodedata.normalize("NFC", char + val)
# These characters have no precombined versions, but check anyway
if len(string) == 1:
encoding[string] = encoding[char + val]
Expand All @@ -137,20 +136,20 @@ def _decode_latex_accent(match: typing.Match) -> str:

# LaTeX single character symbols
symbol = {
'i': '\N{Latin Small Letter Dotless I}',
'j': '\N{Latin Small Letter Dotless J}',
'l': '\N{Latin Small Letter L With Stroke}',
'L': '\N{Latin Capital Letter L With Stroke}',
'o': '\N{Latin Small Letter O With Stroke}',
'O': '\N{Latin Capital Letter O With Stroke}'
"i": "\N{LATIN SMALL LETTER DOTLESS I}",
"j": "\N{LATIN SMALL LETTER DOTLESS J}",
"l": "\N{LATIN SMALL LETTER L WITH STROKE}",
"L": "\N{LATIN CAPITAL LETTER L WITH STROKE}",
"o": "\N{LATIN SMALL LETTER O WITH STROKE}",
"O": "\N{LATIN CAPITAL LETTER O WITH STROKE}",
}

# The regexp to detect the LaTeX commands for special characters
symbol_re = re.compile(r'\\([' + ''.join(symbol.keys()) + '])')
symbol_re = re.compile(r"\\([" + "".join(symbol.keys()) + "])")

# Invert the symbol dictionary to make a dictionary of LaTeX encodings.
for key, val in symbol.items():
encoding[val] = '\\' + key
encoding[val] = "\\" + key


def _decode_latex_symbol(match: typing.Match) -> str:
Expand All @@ -166,10 +165,10 @@ def _decode_latex_symbol(match: typing.Match) -> str:


# LaTeX dashes
dash = {'--': '\N{EN Dash}', '---': '\N{EM Dash}'}
dash = {"--": "\N{EN DASH}", "---": "\N{EM DASH}"}

# The regexp to detect the LaTeX commands for dashes
dash_re = re.compile(r'([^-]?)(-{2,3})([^-]?)')
dash_re = re.compile(r"([^-]?)(-{2,3})([^-]?)")

# Invert the dictionary tomake a dictionary of LaTeX encodings.
for key, val in dash.items():
Expand Down Expand Up @@ -205,13 +204,11 @@ def decode_latex(text: str) -> str:
"""

return brace_re.sub(
r'\1',
r"\1",
accent_re.sub(
_decode_latex_accent,
symbol_re.sub(
_decode_latex_symbol, dash_re.sub(_decode_latex_dash, text)
)
)
symbol_re.sub(_decode_latex_symbol, dash_re.sub(_decode_latex_dash, text)),
),
)


Expand All @@ -228,7 +225,7 @@ def encode_latex(text: str) -> str:
"""

# Map the double character representations
text2 = ''
text2 = ""
char1 = text[0]
i = 1
len_text = len(text)
Expand All @@ -250,7 +247,7 @@ def encode_latex(text: str) -> str:
text2 += char1

# Map the single characters representations
result = ''
result = ""
for char in list(text2):
if char in encoding:
result += encoding[char]
Expand All @@ -260,7 +257,7 @@ def encode_latex(text: str) -> str:
return result


if __name__ == '__main__': # pragma: no cover
if __name__ == "__main__": # pragma: no cover
text = r"""
(Vorlova_2015) Barbora Vorlov{\'{a}} and Dana Nachtigallov{\'{a}} and Jana
Jir{\'{a}}skov{\'{a}}-Van{\'{\i}}{\v{c}}kov{\'{a}} and Haresh Ajani and Petr
Expand Down
Loading
Loading