Skip to content

Replace GPL fuzzywuzzy with MIT thefuzz and drop python-Levenshtein - #576

Open
Alan Meadows (alanmeadows) wants to merge 1 commit into
Azure:devfrom
alanmeadows:replace-fuzzywuzzy-with-thefuzz
Open

Alan Meadows (alanmeadows) wants to merge 1 commit into
Azure:devfrom
alanmeadows:replace-fuzzywuzzy-with-thefuzz

Conversation

@alanmeadows

Copy link
Copy Markdown

Summary

Replaces fuzzywuzzy with thefuzz and removes the python-Levenshtein requirement.

fuzzywuzzy and python-Levenshtein (with its Levenshtein dependency) are GPL-licensed. License-compliance tooling flags them for downstream consumers that install aaz-dev. thefuzz is the renamed, MIT-licensed successor of fuzzywuzzy from the same maintainers. It is backed by rapidfuzz, which is also MIT, so no separate Levenshtein extension is needed.

fuzz.partial_ratio in Resource.get_operation_group_name is the only use.

Behaviour

rapidfuzz computes partial_ratio with an optimal alignment, while fuzzywuzzy with python-Levenshtein uses a matching-blocks heuristic. A plain import swap therefore changes some operation group choices. To keep the selection stable, the sort key now:

  • compares nm.lower() against the resource id, which is already lower-cased, so case differences no longer affect the score;
  • breaks ties by (len(nm), nm). Previously a tie picked whichever name came first when iterating a set, which depends on hash randomization.

I compared the old and new selection on every path in the stable ARM specs of azure-rest-api-specs. I used aaz-dev's own swagger_resource_path_to_resource_id and _parse_operation_group_name, and kept only paths whose operations map to more than one operation group, since only those reach partial_ratio.

Variant Multi-group paths Choice differs from fuzzywuzzy 0.18.0 + python-Levenshtein
thefuzz, unchanged key 39 3
thefuzz, this PR's key 39 1

The one remaining difference is
Microsoft.ApiManagement/service/{}/apis/{}/issues/{}/comments/{}: it now picks ApiIssueComment over ApiIssuComment, a group name that is misspelled in the spec's operation ids.

Testing

  • In a fresh Python 3.12 venv: pip install -r requirements.txt resolves, and neither fuzzywuzzy nor any Levenshtein package is installed.
  • The patched module imports thefuzz.fuzz, and the spec-wide comparison above was run against the patched get_operation_group_name.
  • Generated az CLI output for a downstream TypeSpec/Swagger workspace is identical before and after the change.

fuzzywuzzy and python-Levenshtein are GPL-licensed. thefuzz is the MIT-licensed
successor of fuzzywuzzy and is backed by rapidfuzz (MIT), so it needs no
separate Levenshtein extension.

Resource.get_operation_group_name now compares the lower-cased operation group
name against the lower-cased resource id and breaks ties by length and name.
Previously, a tie depended on set iteration order.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e15bfd2f-39e6-4d7f-97ec-4733ad80e9ad

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant