Skip to content

Commit

Permalink
Merge pull request #20 from amjith/pyproject
Browse files Browse the repository at this point in the history
Pyproject
  • Loading branch information
amjith authored Sep 8, 2024
2 parents 5c62cb6 + 4450da8 commit 23098da
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 230 deletions.
21 changes: 0 additions & 21 deletions .editorconfig

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: fuzzyfinder

on:
pull_request:
paths-ignore:
- '**.rst'
- 'docs'

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v1
with:
version: "latest"

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

- name: Run unit tests
run: uvx tox -e py${{ matrix.python-version }}

- name: Run Style Checks
run: uvx tox -e style
77 changes: 77 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Publish Python Package

on:
release:
types: [created]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v1
with:
version: "latest"

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

- name: Run unit tests
run: uvx tox -e py${{ matrix.python-version }}

- name: Run Style Checks
run: uvx tox -e style

build:
runs-on: ubuntu-latest
needs: [test]

steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v1
with:
version: "latest"

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies
run: uv sync -p 3.12

- name: Build
run: uv build

- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-packages
path: dist/

publish:
name: Publish to PyPI
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [build]
environment: release
permissions:
id-token: write
steps:
- name: Download distribution packages
uses: actions/download-artifact@v4
with:
name: python-packages
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Changelog
---------

2.2.0 (2024-09-08)
---------------------

* Modernize the codebase.
* Add a parameter to enable/disable case insensitivity.


2.0.0 (2017-01-25)
---------------------

Expand Down
18 changes: 5 additions & 13 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,21 @@ Ready to contribute? Here's how to set up `fuzzyfinder` for local development.

$ git clone [email protected]:your_name_here/fuzzyfinder.git

3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development::

$ mkvirtualenv fuzzyfinder
$ cd fuzzyfinder/
$ pip install -r dev-requirements.txt

4. Create a branch for local development::
3. Create a branch for local development::

$ git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally.

5. When you're done making changes, check that your changes pass the tests. This project uses py.test for testing and tox for running the tests on multiple versions of python::
4. When you're done making changes, check that your changes pass the tests.
This project uses tox for running the tests on multiple versions of python::

$ py.test
$ tox

To get tox, just pip install tox into your virtualenv.

6. Commit your changes and push your branch to GitHub::
5. Commit your changes and push your branch to GitHub::

$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature

7. Submit a pull request through the GitHub website.
6. Submit a pull request through the GitHub website.
32 changes: 1 addition & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ help:
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
@echo "clean-test - remove test and coverage artifacts"
@echo "lint - check style with flake8"
@echo "test - run tests quickly with the default Python"
@echo "test-all - run tests on every Python version with tox"
@echo "coverage - check code coverage quickly with the default Python"
@echo "test - run tests on every Python version with tox"
@echo "docs - generate Sphinx HTML documentation, including API docs"
@echo "release - package and upload a release"
@echo "dist - package"
@echo "install - install the package to the active Python's site-packages"

clean: clean-build clean-pyc clean-test

Expand All @@ -34,37 +28,13 @@ clean-test:
rm -f .coverage
rm -fr htmlcov/

lint:
flake8 fuzzyfinder tests

test:
py.test

test-all:
tox

coverage:
py.test --cov fuzzyfinder tests
coverage report -m
coverage html
open htmlcov/index.html

docs:
rm -f docs/fuzzyfinder.rst
rm -f docs/modules.rst
sphinx-apidoc -o docs/ fuzzyfinder
$(MAKE) -C docs clean
$(MAKE) -C docs html
open docs/_build/html/index.html

release: clean
python setup.py sdist upload
python setup.py bdist_wheel upload

dist: clean
python setup.py sdist
python setup.py bdist_wheel
ls -l dist

install: clean
python setup.py install
8 changes: 0 additions & 8 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,3 @@ At the command line::

$ pip install fuzzyfinder

Or::
$ easy_install fuzzyfinder
Or, if you have virtualenvwrapper installed::

$ mkvirtualenv fuzzyfinder
$ pip install fuzzyfinder
8 changes: 4 additions & 4 deletions fuzzyfinder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
# ruff: noqa

__author__ = 'Amjith Ramanujam'
__email__ = '[email protected]'
__version__ = '2.1.0'
__version__ = "2.1.0"

__all__ = []


def export(defn):
"""Decorator to explicitly mark functions that are exposed in a lib."""
globals()[defn.__name__] = defn
__all__.append(defn.__name__)
return defn


from . import main
11 changes: 5 additions & 6 deletions fuzzyfinder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import re
from . import export


@export
def fuzzyfinder(
input, collection, accessor=lambda x: x, sort_results=True, ignore_case=True
):
def fuzzyfinder(input, collection, accessor=lambda x: x, sort_results=True, ignore_case=True):
"""
Args:
input (str): A partial string which is typically entered by a user.
Expand All @@ -30,13 +29,13 @@ def fuzzyfinder(
"""
suggestions = []
input = str(input) if not isinstance(input, str) else input
pat = '.*?'.join(map(re.escape, input))
pat = '(?=({0}))'.format(pat) # lookahead regex to manage overlapping matches
pat = ".*?".join(map(re.escape, input))
pat = "(?=({0}))".format(pat) # lookahead regex to manage overlapping matches
regex = re.compile(pat, re.IGNORECASE if ignore_case else 0)
for item in collection:
r = list(regex.finditer(accessor(item)))
if r:
best = min(r, key=lambda x: len(x.group(1))) # find shortest match
best = min(r, key=lambda x: len(x.group(1))) # find shortest match
suggestions.append((len(best.group(1)), best.start(), accessor(item), item))

if sort_results:
Expand Down
29 changes: 29 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[project]
name = "fuzzyfinder"
dynamic = ["version"]
description = "Fuzzy Finder implemented in Python."
readme = "README.rst"
requires-python = ">=3.8"
license = {text = "BSD"}
authors = [
{name = "Amjith Ramanujam", email = "[email protected]"}
]
urls = { "homepage" = "https://github.com/amjith/fuzzyfinder" }

[project.optional-dependencies]
dev = [
"coverage>=7.2.7",
"pytest>=7.4.4",
"pytest-cov>=4.1.0",
"pdbpp>=0.10.3",
]

[tool.setuptools.packages.find]
exclude = ["screenshots"]

[tool.setuptools.dynamic]
version = {attr = "fuzzyfinder.__version__"}

[tool.ruff]
line-length = 140
exclude = ["docs"]
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

Loading

0 comments on commit 23098da

Please sign in to comment.