Skip to content

Commit

Permalink
monkey patch pkg_resources.safe_name to overcome problem with undersc…
Browse files Browse the repository at this point in the history
…ores in platform namtes
  • Loading branch information
vojtapolasek committed Feb 1, 2022
1 parent 9d89407 commit 9fcf5e2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ssg/boolean_expression.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .ext.boolean import boolean
from pkg_resources import Requirement
import pkg_resources
import re


# We don't support ~= to avoid confusion with boolean operator NOT (~)
Expand All @@ -16,6 +17,12 @@
'<=': 'le_or_eq',
}

# monkeypatch pkg_resources.safe_name function to keep underscores in tact
# it is overcoming this issue: https://github.com/pypa/setuptools/issues/2522
def safe_name(name):
return re.sub('[^A-Za-z0-9_.]+', '-', name)

pkg_resources.safe_name = safe_name

class Function(boolean.Function):
"""
Expand Down Expand Up @@ -64,7 +71,7 @@ class Symbol(boolean.Symbol):

def __init__(self, obj):
super(Symbol, self).__init__(obj)
self.spec = Requirement.parse(obj)
self.spec = pkg_resources.Requirement.parse(obj)
self.obj = self.spec

def __call__(self, **kwargs):
Expand Down

0 comments on commit 9fcf5e2

Please sign in to comment.