Skip to content

Commit 2784104

Browse files
authored
Merge pull request #18 from Princeton-CDH/chore/17-revert-xmlmap
Export names from the top level of `xmlmap` (#17)
2 parents a6401bf + 8550716 commit 2784104

21 files changed

Lines changed: 685 additions & 870 deletions

MIGRATION.rst

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,8 @@
11
Migration from ``eulxml``
22
-------------------------
33

4-
A convenience script called ``migrate-eulxml`` has been included in order
5-
to migrate your project from ``eulxml`` to ``neuxml``, which will replace
6-
any usage of the package name in all ``.py`` files in the passed directory
7-
and subdirectories. After upgrading to Python 3.10+ and installing the
8-
updated package, you can run the script::
9-
10-
migrate-eulxml /path/to/your/project
11-
12-
Or you can run the script directly without installing the package::
13-
14-
python neuxml/utils/migrate_eulxml.py /path/to/your/project
15-
16-
In addition to renaming the package from ``eulxml`` to ``neuxml``, the usage
17-
of indirect imports from ``neuxml.xmlmap`` has been removed, and definitions
18-
must be imported directly from its submodules instead. The migration script
19-
will also attempt to make these changes automatically, but may not work in
20-
all cases, so be sure to check your imports manually as well.
21-
22-
For example, imports have changed from this style:
23-
24-
.. code-block:: python
25-
26-
from neuxml import xmlmap
27-
28-
xmlmap.XmlObject
29-
xmlmap.Field
30-
31-
to this style:
32-
33-
.. code-block:: python
34-
35-
from neuxml.xmlmap import core, fields
36-
37-
core.XmlObject
38-
fields.Field
39-
40-
Class and function imports are also acceptable (e.g. ``from neuxml.xmlmap.core
41-
import XmlObject``).
42-
43-
----
44-
45-
If you would like to automatically replace all instances of ``eulxml`` with
46-
``neuxml`` but otherwise complete the import migration manually, you may use
47-
the following one-line shell script.
4+
To ease migration by automatically replacing all instances of ``eulxml`` with
5+
``neuxml``, you may use the following one-line shell script.
486

497
On MacOS:
508

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ python classes to access, update, and create XML content as standard Python type
2121

2222
**neuxml.xmlmap** makes it possible to map XML content to Python objects in a
2323
pythonic and object-oriented way, which is easier to use than typical DOM access.
24-
With the `neuxml.xmlmap.core.XmlObject` class, XML can be read, modified, and even
24+
With the `neuxml.xmlmap.XmlObject` class, XML can be read, modified, and even
2525
created from scratch in some cases, as long as the configured XPath can
2626
be used to construct new nodes.
2727

doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ neuxml
44
neuxml is an extensible library for reading and writing XML documents in
55
idiomatic Python. It allows developers to `map predictable XML node
66
structures <xmlmap.html#general-usage>`_ to
7-
:class:`~neuxml.xmlmap.core.XmlObject` subclasses, using field definitions to map
7+
:class:`~neuxml.xmlmap.XmlObject` subclasses, using field definitions to map
88
`XPath <http://www.w3.org/TR/xpath/>`_ expressions directly to Python
99
attributes. neuxml also includes an XPath parser in :mod:`neuxml.xpath`.
1010

doc/xmlmap.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ Python integer and the second ``<baz>`` as a string value. We also want to
4444
access all of them (there may be lots on another ``<foo>``) as a big list of
4545
integers. We can create an object to map these fields like this::
4646

47-
from neuxml.xmlmap import core, fields
47+
from neuxml import xmlmap
4848

49-
class Foo(core.XmlObject):
50-
first_baz = fields.IntegerField('bar[1]/baz')
51-
second_baz = fields.StringField('bar[2]/baz')
52-
qux = fields.StringListField('qux')
49+
class Foo(xmlmap.XmlObject):
50+
first_baz = xmlmap.IntegerField('bar[1]/baz')
51+
second_baz = xmlmap.StringField('bar[2]/baz')
52+
qux = xmlmap.StringListField('qux')
5353
5454
:attr:`first_baz`, :attr:`second_baz`, and :attr:`all_baz` here are
5555
attributes of the :class:`Foo` object. We can access them in later code like
5656
this::
5757

58-
>>> foo = xmlmap.core.load_xmlobject_from_file(foo_path, xmlclass=Foo)
58+
>>> foo = xmlmap.load_xmlobject_from_file(foo_path, xmlclass=Foo)
5959
>>> foo.first_baz
6060
42
6161
>>> foo.second_baz
@@ -82,7 +82,7 @@ Concepts
8282
--------
8383

8484
:mod:`~neuxml.xmlmap` simplifies access to XML data in Python. Programs
85-
can define new :class:`~neuxml.xmlmap.core.XmlObject` subclasses representing a
85+
can define new :class:`~neuxml.xmlmap.XmlObject` subclasses representing a
8686
type of XML node with predictable structure. Members of these classes can be
8787
regular methods and values like in regular Python classes, but they can also be
8888
special :ref:`field <xmlmap-field>` objects that associate XPath expressions
@@ -128,7 +128,7 @@ whole collection of them.
128128
Field objects are typically created as part of an :class:`XmlObject`
129129
definition and accessed with standard Python object attribute syntax. If a
130130
:class:`Foo` class defines a :attr:`bar` attribute as an
131-
:mod:`~neuxml.xmlmap.fields` field object, then an object will reference it simply
131+
:mod:`~neuxml.xmlmap` field object, then an object will reference it simply
132132
as ``foo.bar``.
133133

134134
.. automodule:: neuxml.xmlmap.fields
@@ -138,12 +138,12 @@ as ``foo.bar``.
138138
Other facilities
139139
----------------
140140

141-
.. autofunction:: neuxml.xmlmap.core.load_xmlobject_from_string
141+
.. autofunction:: neuxml.xmlmap.load_xmlobject_from_string
142142

143-
.. autofunction:: neuxml.xmlmap.core.load_xmlobject_from_file
143+
.. autofunction:: neuxml.xmlmap.load_xmlobject_from_file
144144

145-
.. autofunction:: neuxml.xmlmap.core.parseString
145+
.. autofunction:: neuxml.xmlmap.parseString
146146

147-
.. autofunction:: neuxml.xmlmap.core.parseUri
147+
.. autofunction:: neuxml.xmlmap.parseUri
148148

149-
.. autofunction:: neuxml.xmlmap.core.loadSchema(uri, base_uri=None)
149+
.. autofunction:: neuxml.xmlmap.loadSchema(uri, base_uri=None)

neuxml/catalog.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import sys
3636

3737
import neuxml
38-
from neuxml.xmlmap import core, fields
38+
from neuxml import xmlmap
3939

4040
# requests is an optional dependency, handle gracefully if not present
4141
try:
@@ -74,25 +74,25 @@
7474
# 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd',
7575

7676

77-
class Uri(core.XmlObject):
78-
""":class:`core.XmlObject` class for Catalog URIs"""
77+
class Uri(xmlmap.XmlObject):
78+
""":class:`xmlmap.XmlObject` class for Catalog URIs"""
7979

8080
ROOT_NAME = "uri"
8181
ROOT_NS = "urn:oasis:names:tc:entity:xmlns:xml:catalog"
8282
#: name, i.e. schema URI
83-
name = fields.StringField("@name")
83+
name = xmlmap.StringField("@name")
8484
#: uri, i.e. path to load the schema locally
85-
uri = fields.StringField("@uri")
85+
uri = xmlmap.StringField("@uri")
8686

8787

88-
class Catalog(core.XmlObject):
89-
""":class:`core.XmlObject` class to for generating XML Catalogs"""
88+
class Catalog(xmlmap.XmlObject):
89+
""":class:`xmlmap.XmlObject` class to for generating XML Catalogs"""
9090

9191
ROOT_NAME = "catalog"
9292
ROOT_NS = "urn:oasis:names:tc:entity:xmlns:xml:catalog"
9393
ROOT_NAMESPACES = {"c": ROOT_NS}
9494
#: list of uris, as instance of :class:`Uri`
95-
uri_list = fields.NodeListField("c:uri", Uri)
95+
uri_list = xmlmap.NodeListField("c:uri", Uri)
9696

9797

9898
def download_schema(uri, path, comment=None):

neuxml/utils/migrate_eulxml.py

Lines changed: 0 additions & 114 deletions
This file was deleted.

neuxml/xmlmap/__init__.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,70 @@
2020
nodes map to Python attributes using XPath expressions.
2121
2222
For developer convenience this package is divided into submodules. Users
23-
should import the names from submodules. This package exports
23+
should import the names directly from neuxml.xmlmap. This package exports
2424
the following names:
25-
* core.XmlObject -- a base class for XML-Python mapping objects
26-
* core.parseUri and core.parseString -- parse a URI or string into an xml node with
25+
* XmlObject -- a base class for XML-Python mapping objects
26+
* parseUri and parseString -- parse a URI or string into an xml node with
2727
XPath methods that xmlmap depends on
28-
* core.load_xmlobject_from_string and core.load_xmlobject_from_file -- parse a string
28+
* load_xmlobject_from_string and load_xmlobject_from_file -- parse a string
2929
or file directly into an XmlObject
30-
* fields.NodeField and fields.NodeListField -- field classes for mapping relative
30+
* NodeField and NodeListField -- field classes for mapping relative
3131
xml nodes to other XmlObjects
32-
* fields.StringField and fields.StringListField -- field classes for mapping xml
32+
* StringField and StringListField -- field classes for mapping xml
3333
nodes to Python strings
34-
* fields.IntegerField and fields.IntegerListField -- field classes for mapping xml
34+
* IntegerField and IntegerListField -- field classes for mapping xml
3535
nodes to Python integers
3636
3737
"""
38+
39+
from neuxml.xmlmap.core import (
40+
XmlObject,
41+
parseUri,
42+
parseString,
43+
loadSchema,
44+
load_xmlobject_from_string,
45+
load_xmlobject_from_file,
46+
load_xslt,
47+
)
48+
from neuxml.xmlmap.fields import (
49+
StringField,
50+
StringListField,
51+
IntegerField,
52+
IntegerListField,
53+
NodeField,
54+
NodeListField,
55+
ItemField,
56+
SimpleBooleanField,
57+
DateTimeField,
58+
DateTimeListField,
59+
DateField,
60+
DateListField,
61+
SchemaField,
62+
FloatField,
63+
FloatListField,
64+
)
65+
66+
__all__ = [
67+
"XmlObject",
68+
"parseUri",
69+
"parseString",
70+
"loadSchema",
71+
"load_xmlobject_from_string",
72+
"load_xmlobject_from_file",
73+
"load_xslt",
74+
"StringField",
75+
"StringListField",
76+
"IntegerField",
77+
"IntegerListField",
78+
"NodeField",
79+
"NodeListField",
80+
"ItemField",
81+
"SimpleBooleanField",
82+
"DateTimeField",
83+
"DateTimeListField",
84+
"DateField",
85+
"DateListField",
86+
"SchemaField",
87+
"FloatField",
88+
"FloatListField",
89+
]

0 commit comments

Comments
 (0)