From 01d41e6011e3f5281380230cb7bdbe17bab2c88e Mon Sep 17 00:00:00 2001 From: Walter Scheper Date: Wed, 7 Jun 2017 15:52:56 -0400 Subject: [PATCH] Support for loading POM files without a maven client Adds the classmethods Pom.fromstring and Pom.parse. These are modeled on the lxml.etree functions of the same name. If a MavenClient is passed in, then the resulting Pom object will attempt to dynamically load data from external POM files available via the client. Sem-Ver: feature Fixes: #4 --- README.md | 10 ++ README.rst | 1 - pymaven/pom.py | 335 +++++++++++++++++++++++++++++----------------- pymaven/utils.py | 17 +++ setup.cfg | 2 +- tests/test_pom.py | 13 +- 6 files changed, 245 insertions(+), 133 deletions(-) create mode 100644 README.md delete mode 100644 README.rst diff --git a/README.md b/README.md new file mode 100644 index 0000000..d5ba5e9 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Pymaven + +## Overview + +Pymaven is a Python library for interfacing with the maven build system. There +are two major interfaces: + +- pymaven.client provides a basic maven repository client +- pymaven.pom provides a Pom object that can provide progromatic access to + a maven pom file diff --git a/README.rst b/README.rst deleted file mode 100644 index 10427ea..0000000 --- a/README.rst +++ /dev/null @@ -1 +0,0 @@ -Python library for interfacing with maven diff --git a/pymaven/pom.py b/pymaven/pom.py index ee81da5..a3708a8 100644 --- a/pymaven/pom.py +++ b/pymaven/pom.py @@ -24,15 +24,29 @@ from .artifact import Artifact from .utils import memoize +from .utils import parse_source from .versioning import VersionRange +EMPTY_POM = """\ + + + 4.0.0 + {0.group_id} + {0.artifact_id} + {0.version} + +""" +POM_NAMESPACE = "http://maven.apache.org/POM/4.0.0" +POM = "{%s}" % (POM_NAMESPACE,) +POM_NAMESPACE_LEN = len(POM) POM_PARSER = etree.XMLParser( recover=True, remove_comments=True, remove_pis=True, ) PROPERTY_RE = re.compile(r'\$\{(.*?)\}') -STRIP_NAMESPACE_RE = re.compile(r"") +STRIP_NAMESPACE_RE = re.compile(POM) log = logging.getLogger(__name__) @@ -43,17 +57,12 @@ class Pom(Artifact): RANGE_CHARS = ('[', '(', ']', ')') - __slots__ = ("_client", "_parent", "_dep_mgmt", "_dependencies", - "_properties", "_xml") + __slots__ = ("_client", "_parent", "_dep_mgmt", "_dependencies", "_pom_data", "_properties") - def __init__(self, coordinate, client): - super(Pom, self).__init__(coordinate) - with client.get_artifact(self.coordinate).contents as fh: - xml = fh.read() - self._xml = etree.fromstring( - STRIP_NAMESPACE_RE.sub('', xml[xml.find('