Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. set 3.9 as lowest python version 2. migrated to pyproject.toml 3. migrated to pytest 4. migrated to ruff and ruff-format 5. add publish github action 6. migrated readme to markdown
- Loading branch information
Showing
15 changed files
with
474 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
- [ ] Closes # (insert issue number) | ||
- [ ] Executed ``pre-commit run --all-files`` with no errors | ||
- [ ] Executed `pre-commit run --all-files` with no errors | ||
- [ ] The change is fully covered by automated unit tests | ||
- [ ] Documented in docs/ as appropriate | ||
- [ ] Added an entry to the CHANGES file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Build and publish to PyPI | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: python -m pip install build | ||
|
||
- name: Build package | ||
run: python -m build | ||
|
||
- name: Publish to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
[![Latest Version](https://img.shields.io/pypi/v/stringparser.svg)](https://pypi.python.org/pypi/stringparser) | ||
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black) | ||
[![License](https://img.shields.io/pypi/l/stringparser.svg)](https://pypi.python.org/pypi/stringparser) | ||
[![Python Versions](https://img.shields.io/pypi/pyversions/stringparser.svg)](https://pypi.python.org/pypi/stringparser) | ||
[![CI](https://github.com/hgrecco/stringparser/workflows/CI/badge.svg)](https://github.com/hgrecco/stringparser/actions?query=workflow%3ACI) | ||
[![LINTER](https://github.com/hgrecco/stringparser/workflows/Lint/badge.svg)](https://github.com/hgrecco/stringparser/actions?query=workflow%3ALint) | ||
[![Coverage](https://coveralls.io/repos/github/hgrecco/stringparser/badge.svg?branch=master)](https://coveralls.io/github/hgrecco/stringparser?branch=master) | ||
|
||
# Motivation | ||
|
||
The `stringparser` module provides a simple way to match patterns and | ||
extract information within strings. As patterns are given using the | ||
familiar format string specification `3101`{.interpreted-text | ||
role="pep"}, writing them is much easier than writing regular | ||
expressions (albeit less powerful). | ||
|
||
Just install it using: | ||
|
||
```bash | ||
pip install stringparser | ||
``` | ||
|
||
# Examples | ||
|
||
You can build a reusable parser object: | ||
|
||
```python | ||
>>> parser = Parser('The answer is {:d}') | ||
>>> parser('The answer is 42') | ||
42 | ||
>>> parser('The answer is 54') | ||
54 | ||
``` | ||
|
||
Or directly: | ||
|
||
```python | ||
>>> Parser('The answer is {:d}')('The answer is 42') | ||
42 | ||
``` | ||
|
||
You can retrieve many fields: | ||
|
||
```python | ||
>>> Parser('The {:s} is {:d}')('The answer is 42') | ||
('answer', 42) | ||
``` | ||
|
||
And you can use numbered fields to order the returned tuple: | ||
|
||
```python | ||
>>> Parser('The {1:s} is {0:d}')('The answer is 42') | ||
(42, 'answer') | ||
``` | ||
|
||
Or named fields to return an OrderedDict: | ||
|
||
```python | ||
>>> Parser('The {a:s} is {b:d}')('The answer is 42') | ||
OrderedDict([('a', 'answer'), ('b', 42)]) | ||
``` | ||
|
||
You can ignore some fields using _ as a name: | ||
|
||
```python | ||
>>> Parser('The {_:s} is {:d}')('The answer is 42') | ||
42 | ||
``` | ||
|
||
# Limitations | ||
|
||
- From the format string: | ||
\[\[\[fill\]align\]\[sign\]\[#\]\[0\]\[minimumwidth\]\[.precision\]\[type\]\]{.title-ref} | ||
only \[type\]{.title-ref}, \[sign\]{.title-ref} and \[#\]{.title-ref} are | ||
currently implemented. This might cause trouble to match certain | ||
notation like: | ||
- decimal: '-4' written as '- 4' | ||
- etc | ||
- Lines are matched from beginning to end. {:d} will NOT return all | ||
the numbers in the string. Use regex for that. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[project] | ||
name = "stringparser" | ||
authors = [ | ||
{name="Hernan E. Grecco", email="hernan.grecco@gmail.com"} | ||
] | ||
license = "BSD-3-Clause" | ||
description = "Easy to use pattern matching and information extraction" | ||
keywords = ["string", "parsing", "PEP3101", "regex"] | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Intended Audience :: Developers", | ||
"License :: OSI Approved :: BSD License", | ||
"Operating System :: MacOS :: MacOS X", | ||
"Operating System :: Microsoft :: Windows", | ||
"Operating System :: POSIX", | ||
"Programming Language :: Python", | ||
"Topic :: Software Development :: Libraries", | ||
"Topic :: Text Processing", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
] | ||
requires-python = ">=3.9" | ||
dynamic = ["dependencies", "optional-dependencies", "version"] | ||
|
||
[project.readme] | ||
file = "README.md" | ||
content-type = "text/markdown" | ||
|
||
[build-system] | ||
requires = ["setuptools", "setuptools-scm"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools] | ||
py-modules = ["stringparser"] | ||
|
||
[tool.setuptools.dynamic] | ||
dependencies = {file = "requirements.txt"} | ||
optional-dependencies.test = {file = "requirements.test.txt"} | ||
|
||
[project.urls] | ||
"Homepage" = "https://github.com/hgrecco/stringparser" | ||
"Bug Tracker" = "https://github.com/hgrecco/stringparser/issues" | ||
|
||
[tool.setuptools_scm] | ||
|
||
[tool.pytest.ini_options] | ||
addopts = "--import-mode=importlib" | ||
pythonpath = "." | ||
|
||
[tool.ruff] | ||
select = ["E", "F", "I"] | ||
extend-include = ["*.ipynb"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest |
Empty file.
Oops, something went wrong.