Skip to content

Monkeypatch pkg_resources to always use _markerlib #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions requirements-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ if [[ $USE_OPTIONAL != "true" && $USE_OPTIONAL != "false" ]]; then
exit 1
fi

# Make sure we're running setuptools >= 18.5
pip install -U pip setuptools>=18.5

pip install -U -r requirements-test.txt

if [[ $USE_OPTIONAL == "true" ]]; then
Expand Down
1 change: 0 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ flake8
pytest
pytest-expect>=1.1,<2.0
mock
ordereddict ; python_version < '2.7'
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
six
webencodings
ordereddict ; python_version < '2.7'
setuptools>=18.5
53 changes: 48 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,54 @@
from setuptools import setup, find_packages, __version__ as setuptools_version
from pkg_resources import parse_version

if parse_version(setuptools_version) < parse_version("18.5"):
print("html5lib requires setuptools version 18.5 or above; "
"please upgrade before installing (you have %s)" % setuptools_version)
sys.exit(1)
import pkg_resources

try:
import _markerlib.markers
except ImportError:
_markerlib = None


# _markerlib.default_environment() obtains its data from _VARS
# and wraps it in another dict, but _markerlib_evaluate writes
# to the dict while it is iterating the keys, causing an error
# on Python 3 only.
# Replace _markerlib.default_environment to return a custom dict
# that has all the necessary markers, and ignores any writes.

class Python3MarkerDict(dict):

def __setitem__(self, key, value):
pass

def pop(self, i=-1):
return self[i]


if _markerlib and sys.version_info[0] == 3:
env = _markerlib.markers._VARS
for key in list(env.keys()):
new_key = key.replace('.', '_')
if new_key != key:
env[new_key] = env[key]

_markerlib.markers._VARS = Python3MarkerDict(env)

def default_environment():
return _markerlib.markers._VARS

_markerlib.default_environment = default_environment

# Avoid the very buggy pkg_resources.parser, which doesnt consistently
# recognise the markers needed by this setup.py
# Change this to setuptools 20.10.0 to support all markers.
if pkg_resources:
if parse_version(setuptools_version) < parse_version('18.5'):
MarkerEvaluation = pkg_resources.MarkerEvaluation

del pkg_resources.parser
pkg_resources.evaluate_marker = MarkerEvaluation._markerlib_evaluate
MarkerEvaluation.evaluate_marker = MarkerEvaluation._markerlib_evaluate

classifiers = [
'Development Status :: 5 - Production/Stable',
Expand Down Expand Up @@ -60,7 +104,6 @@
install_requires=[
'six',
'webencodings',
'setuptools>=18.5'
],
extras_require={
# A empty extra that only has a conditional marker will be
Expand Down