sissaschool / xmlschema

XML Schema validator and data conversion library for Python
MIT License
411 stars 74 forks source link

Python 3.12 support #342

Closed bluetech closed 1 year ago

bluetech commented 1 year ago

Hi, I'm a pytest dev working on adding initial support for Python 3.12 alpha to pytest. pytest uses xmlschema in its testsuite. Importing xmlschema fails on 3.12:

testing/test_junitxml.py:13: in <module>
    import xmlschema
.tox/py312/lib/python3.12/site-packages/xmlschema/__init__.py:21: in <module>
    from .dataobjects import DataElement, DataElementConverter, DataBindingConverter
.tox/py312/lib/python3.12/site-packages/xmlschema/dataobjects.py:24: in <module>
    from . import validators
.tox/py312/lib/python3.12/site-packages/xmlschema/validators/__init__.py:38: in <module>
    from .schemas import XMLSchemaMeta, XMLSchemaBase, XMLSchema, XMLSchema10, XMLSchema11
.tox/py312/lib/python3.12/site-packages/xmlschema/validators/schemas.py:2183: in <module>
    class XMLSchema10(XMLSchemaBase):
.tox/py312/lib/python3.12/site-packages/xmlschema/validators/schemas.py:134: in __new__
    meta_schema = meta_schema_class.create_meta_schema(meta_schema_file)
.tox/py312/lib/python3.12/site-packages/xmlschema/validators/schemas.py:768: in create_meta_schema
    meta_schema = meta_schema_class(source, XSD_NAMESPACE, defuse='never', build=False)
.tox/py312/lib/python3.12/site-packages/xmlschema/validators/schemas.py:345: in __init__
    self.source = XMLResource(source, base_url, allow, defuse, timeout)
.tox/py312/lib/python3.12/site-packages/xmlschema/resources.py:470: in __init__
    self.parse(source, lazy)
.tox/py312/lib/python3.12/site-packages/xmlschema/resources.py:728: in parse
    url = normalize_url(source, self._base_url)
.tox/py312/lib/python3.12/site-packages/xmlschema/resources.py:144: in normalize_url
    path = _PurePath.from_uri(url)
.tox/py312/lib/python3.12/site-packages/xmlschema/resources.py:65: in from_uri
    return cls(uri)
.tox/py312/lib/python3.12/site-packages/xmlschema/resources.py:54: in __new__
    return cast('_PurePath', cls._from_parts(args))
E   AttributeError: type object '_PurePosixPath' has no attribute '_from_parts'. Did you mean: '_load_parts'?

Looks like pathlib removed the private _from_parts function.

I tried running the xmlschema testsuite on py3.12, however that currently fails because xmlschema's testsuite depends on lxml which fails to compile on py3.12 (because of cython). So might need to wait for lxml/cython here.

brunato commented 1 year ago

Hi, the pathlib.PurePath class has many changes in Python 3.12, so I have to check deeply the new code to update _PurePath in xmlschema. Unfortunately I cannot avoid to use protected methods because the library needs to manage also relative file URIs.

brunato commented 1 year ago

Release v2.2.3 is available. Reworked _PurePath removing the use of PurePath internals, now xmlschema should work also with Python 3.12.

bluetech commented 1 year ago

Thank you! Can confirm that the problem is fixed.