Repository navigation
5.0.2.post2: restore methods lxml 5.0 removed; static link fix; postN version - #3
Conversation
lxml 5.0 removed XPath.evaluate() (XPath, ETXPath, XPathEvaluator), parser.setElementClassLookup() and XSLT.apply(), all deprecated since lxml 2.0. Code written against lxml 4.x that still calls them fails with AttributeError after an upgrade to 5.0. Bring them back verbatim from lxml 4.9.2: each is a thin alias of the supported call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lxml links a fixed list (xslt exslt xml2 rt z m) and takes only the -L directories from xml2-config/xslt-config --libs. Against static libxml2.a and libxslt.a, which carry no DT_NEEDED entries, that drops libxml2's own dependencies: with GNU libiconv, etree.so and objectify.so are left with undefined libiconv/libiconv_open/libiconv_close and fail on import. Append every -l the config tools report that is not already listed. With shared libraries this is harmless. The ActiveState Platform has carried this as an inventory patch on 5.0.2.1; it now lives in the source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
__unpackDottedVersion() left an unknown suffix as a string, so a post release would give LXML_VERSION = (5, 0, 2, 'post2'), which raises TypeError when compared with an all-integer tuple on Python 3. Read postN as the number N: 5.0.2.post2 -> (5, 0, 2, 2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Version string: 5.0.2.post2 Git tag: 5.0.2.2 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ezequielp-activestate
left a comment
There was a problem hiding this comment.
Approve: 0 blockers.
🔴 Blockers: None
📋 Checked
- The restored methods are an exact revert of the upstream removal. Upstream removed exactly these three methods in lxml commit 59ccc8c ("Remove redundant and long deprecated methods"), and the 5.0.0 changelog lists no others.
XPath.evaluate(),setElementClassLookup()andXSLT.apply()here matchlxml-4.9.2line for line. - Built and tested in place on Python 2.7.18 (python:2.7 image, Cython 3.0.11, libxml2 2.9.4, libxslt 1.1.32), with
AS_DEPENDENCIES_DIR=/:- Base
5.0.2.1with the new test file copied in:test.pyran 1974 tests with 2 failures and 6 errors. The 8 are the 7 new tests plustest_etree.test_version. - This PR: the same 1974 tests all pass.
- The customer's
ETXPath(...).evaluate()raisesAttributeErroron the base and works here.
- Base
LXML_VERSIONis(5, 0, u'2+security', 1)on the base and(5, 0, 2, 2)here.- The package version is right:
setup.py --versionandversioninfo.version()both give5.0.2.post2. - The link fix works when setup finds libxml2 through
xml2-config. I pointed it at a stubxml2-configthat reports-lxml2 -liconv -lz -lm. Baselibraries()gives[xslt, exslt, xml2, rt, z, m], and the PR gives the same list plusiconv.
🟡 The link fix does nothing when setup finds libxml2 through pkg-config. get_library_versions() (setupinfo.py:507) tries pkg-config before xml2-config, and pkg-config --libs leaves out Libs.private: on Debian, pkg-config --libs libxml-2.0 prints only -lxml2, while --static --libs also gives -licu… -lz -llzma -lm. On that path libraries() is unchanged; I ran it on both trees and got identical lists. It's fine as long as the Platform builder has no pkg-config that finds our libxml2, and since patch d4d217d2 worked on 5.0.2.1, it probably doesn't. Before dropping the patch from the 5.0.2.2 import, check that the first Platform build log has -liconv on the etree.so link line.
⚪ For the customer: their move from 4.9 to 5.0 also changes the default to resolve_entities='internal', so external entities (XXE) are no longer expanded (5.0.0 changelog, LP#1742885). That change is intended and this PR rightly leaves it alone, but it's the next difference they may run into.
- I didn't compare the code against inventory patch d4d217d2.
- I didn't do a real static link against
libxml2.awith GNU libiconv. - I didn't run Python 3 or Windows builds.
|
Thanks for the thorough review. 🟡 pkg-config path. I checked this on the Platform builder. The current Forsta x86 build (commit c92e1eb0) builds lxml 5.0.2.1 with inventory patch d4d217d2, which is the same So on the builder, the libraries a static libxml2 needs ( ⚪ XXE default. Agreed. The |
lxml 5.0.2.post2, on top of 5.0.2+security.1 (tag
5.0.2.1). New base branch5.0.2.x= 4009508 (the 5.0.2.1 release commit).Why
A customer moving a Python 2.7 runtime from lxml 4.9 to our 5.0.2.1 hit
AttributeError: 'lxml.etree.ETXPath' object has no attribute 'evaluate'. Upstream lxml 5.0 removed three methods that had been deprecated since 2.0:XPath.evaluate(),parser.setElementClassLookup()andXSLT.apply(). These are Py2-era runtimes that won't move to newer lxml, so the fork keeps them.Commits
xpath.pxi,parser.pxi,xslt.pxi), and each method is a thin alias of the supported call. New test module:tests/test_deprecated_aliases.py.setupinfo.pyfix the Platform has carried as inventory patch d4d217d2 on 5.0.2.1. Staticlibxml2.aneeds-liconv, and without itetree.sofails to import. With the fix in the source, 5.0.2.post2 needs no inventory patch..postNsuffix inLXML_VERSION. Without this,5.0.2.post2would unpack to(5, 0, 2, 'post2'), which breaks tuple comparisons on Python 3. It now gives(5, 0, 2, 2). This also fixes upstream'stest_etree.test_version, which fails on 5.0.2.1 becauseLXML_VERSIONis(5, 0, '2+security', 1).__version__and CHANGES.txt.Testing
Built in place on Python 2.7.18 with Cython 3.0.11, libxml2 2.15.3 and libxslt 1.1.45:
test_deprecated_aliases: 7/7 pass.test.py: the failure set is the same as on 5.0.2.1, minustest_version, which now passes. The remaining 21 failures and 20 errors are host artifacts (libxml2 2.15 against tests written for 2.12, plus network tests) and fail identically on both.After merge: tag
5.0.2.2, create a GitHub release, import into the inventory as lxml 5.0.2.2 (copy of 5.0.2.1 without patch d4d217d2), then run Platform builds and QA.