Skip to content

Commit

Permalink
Modernize project infrastructure
Browse files Browse the repository at this point in the history
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
hgrecco committed Nov 12, 2023
1 parent ec4323b commit 464f408
Show file tree
Hide file tree
Showing 15 changed files with 474 additions and 473 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
@@ -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
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Expand Up @@ -7,8 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10", "3.11"]
# python-version: [2.7, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10", "3.11"]
python-version: [3.9, "3.10", "3.11", "3.12"]
runs-on: ubuntu-latest

env:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
@@ -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 }}
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Expand Up @@ -5,16 +5,12 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.240'
rev: v0.1.5
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
Expand Down
2 changes: 1 addition & 1 deletion CHANGES
@@ -1,7 +1,7 @@
0.7 (unreleased)
----------------

- Nothing changed yet.
- Migrated project to modern framework.


0.6 (2022-10-26)
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
@@ -1,4 +1,4 @@
include README.rst LICENSE CHANGES
include README.md LICENSE CHANGES
include stringparser.py
exclude .editorconfig bors.toml pull_request_template.md requirements_docs.txt version.py
exclude .coveragerc .pre-commit-config.yaml tests/*
Expand Down
80 changes: 80 additions & 0 deletions README.md
@@ -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.
105 changes: 0 additions & 105 deletions README.rst

This file was deleted.

54 changes: 54 additions & 0 deletions pyproject.toml
@@ -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"]
1 change: 1 addition & 0 deletions requirements.test.txt
@@ -0,0 +1 @@
pytest
Empty file added requirements.txt
Empty file.
67 changes: 0 additions & 67 deletions setup.cfg

This file was deleted.

5 changes: 0 additions & 5 deletions setup.py

This file was deleted.

0 comments on commit 464f408

Please sign in to comment.