Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6cd93c8

Browse files
committed
Monkeypatch pkg_resources to always use _markerlib
Prior to setuptools 20.10.0 there is patchy support for environment markers,and setup.py fails while parsing them.html5lib requires at least setuptools 18.5 for its environment markers.However,@gsnedders developed a way to monkey patch pkg_resourcesso that it always uses _markerlib, which allows all environment markersto be used for any version of setuptools. Some patching of _markerlibis also required so that it works on Python 3 also.On removing the dependency for setuptools>=18.5, pip partially fails onPython 2.6 with an error `Double requirement given: ordereddict`and does not install the requirements.txt.Fixed by removing ordereddict from requirements-test.txt
1 parent14d4851 commit6cd93c8

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

‎requirements-install.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ if [[ $USE_OPTIONAL != "true" && $USE_OPTIONAL != "false" ]]; then
55
exit 1
66
fi
77

8-
# Make sure we're running setuptools >= 18.5
9-
pip install -U pip setuptools>=18.5
10-
118
pip install -U -r requirements-test.txt
129

1310
if [[$USE_OPTIONAL=="true" ]];then

‎requirements-test.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ flake8
44
pytest
55
pytest-expect>=1.1,<2.0
66
mock
7-
ordereddict ; python_version < '2.7'

‎requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
six
22
webencodings
33
ordereddict ;python_version<'2.7'
4-
setuptools>=18.5

‎setup.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,54 @@
88
fromsetuptoolsimportsetup,find_packages,__version__assetuptools_version
99
frompkg_resourcesimportparse_version
1010

11-
ifparse_version(setuptools_version)<parse_version("18.5"):
12-
print("html5lib requires setuptools version 18.5 or above; "
13-
"please upgrade before installing (you have %s)"%setuptools_version)
14-
sys.exit(1)
11+
importpkg_resources
12+
13+
try:
14+
import_markerlib.markers
15+
exceptImportError:
16+
_markerlib=None
17+
18+
19+
# _markerlib.default_environment() obtains its data from _VARS
20+
# and wraps it in another dict, but _markerlib_evaluate writes
21+
# to the dict while it is iterating the keys, causing an error
22+
# on Python 3 only.
23+
# Replace _markerlib.default_environment to return a custom dict
24+
# that has all the necessary markers, and ignores any writes.
25+
26+
classPython3MarkerDict(dict):
27+
28+
def__setitem__(self,key,value):
29+
pass
30+
31+
defpop(self,i=-1):
32+
returnself[i]
33+
34+
35+
if_markerlibandsys.version_info[0]==3:
36+
env=_markerlib.markers._VARS
37+
forkeyinlist(env.keys()):
38+
new_key=key.replace('.','_')
39+
ifnew_key!=key:
40+
env[new_key]=env[key]
41+
42+
_markerlib.markers._VARS=Python3MarkerDict(env)
43+
44+
defdefault_environment():
45+
return_markerlib.markers._VARS
46+
47+
_markerlib.default_environment=default_environment
48+
49+
# Avoid the very buggy pkg_resources.parser, which doesnt consistently
50+
# recognise the markers needed by this setup.py
51+
# Change this to setuptools 20.10.0 to support all markers.
52+
ifpkg_resources:
53+
ifparse_version(setuptools_version)<parse_version('18.5'):
54+
MarkerEvaluation=pkg_resources.MarkerEvaluation
55+
56+
delpkg_resources.parser
57+
pkg_resources.evaluate_marker=MarkerEvaluation._markerlib_evaluate
58+
MarkerEvaluation.evaluate_marker=MarkerEvaluation._markerlib_evaluate
1559

1660
classifiers= [
1761
'Development Status :: 5 - Production/Stable',
@@ -60,7 +104,6 @@
60104
install_requires=[
61105
'six',
62106
'webencodings',
63-
'setuptools>=18.5'
64107
],
65108
extras_require={
66109
# A empty extra that only has a conditional marker will be

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp