[CalendarServer-changes] [14591] twext/trunk/setup.py
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 13 15:31:51 PDT 2015
Revision: 14591
http://trac.calendarserver.org//changeset/14591
Author: sagen at apple.com
Date: 2015-03-13 15:31:51 -0700 (Fri, 13 Mar 2015)
Log Message:
-----------
update setup.py with pep440 version
Modified Paths:
--------------
twext/trunk/setup.py
Modified: twext/trunk/setup.py
===================================================================
--- twext/trunk/setup.py 2015-03-13 20:45:32 UTC (rev 14590)
+++ twext/trunk/setup.py 2015-03-13 22:31:51 UTC (rev 14591)
@@ -18,28 +18,33 @@
from __future__ import print_function
+import os
from os.path import dirname, abspath, join as joinpath
-from setuptools import setup, find_packages as setuptools_find_packages
-import errno
-import os
import subprocess
import sys
+import errno
+from setuptools import setup, find_packages as setuptools_find_packages
+from xml.etree import ElementTree
+base_version = "0.1"
+
#
# Utilities
#
-
def find_packages():
modules = [
"twisted.plugins",
]
- for pkg in filter(
- lambda p: os.path.isdir(p) and os.path.isfile(os.path.join(p, "__init__.py")),
- os.listdir(".")
- ):
+ def is_package(path):
+ return (
+ os.path.isdir(path) and
+ os.path.isfile(os.path.join(path, "__init__.py"))
+ )
+
+ for pkg in filter(is_package, os.listdir(".")):
modules.extend([pkg, ] + [
"{}.{}".format(pkg, subpkg)
for subpkg in setuptools_find_packages(pkg)
@@ -47,70 +52,157 @@
return modules
-
-def version():
+def svn_info(wc_path):
"""
- Compute the version number.
+ Look up info on a Subversion working copy.
"""
+ try:
+ info_xml = subprocess.check_output(
+ ["svn", "info", "--xml", wc_path],
+ stderr=subprocess.STDOUT,
+ )
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ return None
+ raise
+ except subprocess.CalledProcessError:
+ return None
- base_version = "0.1"
+ info = ElementTree.fromstring(info_xml)
+ assert info.tag == "info"
- branches = tuple(
- branch.format(
- project="twext",
- version=base_version,
- )
- for branch in (
- "tags/release/{project}-{version}",
- "branches/release/{project}-{version}-dev",
- "trunk",
- )
+ entry = info.find("entry")
+ url = entry.find("url")
+ root = entry.find("repository").find("root")
+ if url.text.startswith(root.text):
+ location = url.text[len(root.text):].strip("/")
+ else:
+ location = url.text.strip("/")
+ project, branch = location.split("/")
+
+ return dict(
+ root=root.text,
+ project=project, branch=branch,
+ revision=info.find("entry").attrib["revision"],
)
- source_root = dirname(abspath(__file__))
- for branch in branches:
- cmd = ["svnversion", "-n", source_root, branch]
+def svn_status(wc_path):
+ """
+ Look up status on a Subversion working copy.
+ Complies with PEP 440: https://www.python.org/dev/peps/pep-0440/
- try:
- svn_revision = subprocess.check_output(cmd)
+ Examples:
+ C{6.0} (release tag)
+ C{6.1.b2.dev14564} (release branch)
+ C{7.0.b1.dev14564} (trunk)
+ C{6.0.a1.dev14441+branches.pg8000} (other branch)
+ """
+ try:
+ status_xml = subprocess.check_output(
+ ["svn", "status", "--xml", wc_path]
+ )
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ return
+ raise
+ except subprocess.CalledProcessError:
+ return
- except OSError as e:
- if e.errno == errno.ENOENT:
- full_version = base_version + "-unknown"
- break
- raise
+ status = ElementTree.fromstring(status_xml)
+ assert status.tag == "status"
- if "S" in svn_revision:
- continue
+ target = status.find("target")
- full_version = base_version
+ for entry in target.findall("entry"):
+ entry_status = entry.find("wc-status")
+ if entry_status is not None:
+ item = entry_status.attrib["item"]
+ if item == "unversioned":
+ continue
+ path = entry.attrib["path"]
+ if wc_path != ".":
+ path = path.lstrip(wc_path)
+ yield dict(path=path)
- if branch == "trunk":
- full_version += "b.trunk"
- elif branch.endswith("-dev"):
- full_version += "c.dev"
- if svn_revision in ("exported", "Unversioned directory"):
- full_version += "-unknown"
- else:
- full_version += "-r{revision}".format(revision=svn_revision)
+def version():
+ """
+ Compute the version number.
+ """
+ source_root = dirname(abspath(__file__))
+ info = svn_info(source_root)
+ print(info)
+
+ if info is None:
+ # We don't have Subversion info...
+ return "{}.a1+unknown".format(base_version)
+
+ assert info["project"] == project_name, (
+ "Subversion project {!r} != {!r}"
+ .format(info["project"], project_name)
+ )
+
+ status = svn_status(source_root)
+
+ for entry in status:
+ # We have modifications.
+ modified = "+modified"
break
else:
- full_version = base_version
- full_version += "a.unknown"
- full_version += "-r{revision}".format(revision=svn_revision)
+ modified = ""
- return full_version
+ if info["branch"].startswith("tags/release/"):
+ project_version = info["branch"].lstrip("tags/release/")
+ project, version = project_version.split("-")
+ assert project == project_name, (
+ "Tagged project {!r} != {!r}".format(project, project_name)
+ )
+ assert version == base_version, (
+ "Tagged version {!r} != {!r}".format(version, base_version)
+ )
+ # This is a correctly tagged release of this project.
+ return "{}{}".format(base_version, modified)
+ if info["branch"].startswith("branches/release/"):
+ project_version = info["branch"].lstrip("branches/release/")
+ project, version, dev = project_version.split("-")
+ assert project == project_name, (
+ "Branched project {!r} != {!r}".format(project, project_name)
+ )
+ assert version == base_version, (
+ "Branched version {!r} != {!r}".format(version, base_version)
+ )
+ assert dev == "dev", (
+ "Branch name doesn't end in -dev: {!r}".format(info["branch"])
+ )
+ # This is a release branch of this project.
+ # Designate this as beta2, dev version based on svn revision.
+ return "{}.b2.dev{}{}".format(base_version, info["revision"], modified)
+ if info["branch"].startswith("trunk"):
+ # This is trunk.
+ # Designate this as beta1, dev version based on svn revision.
+ return "{}.b1.dev{}{}".format(base_version, info["revision"], modified)
+
+ # This is some unknown branch or tag...
+ return "{}.a1.dev{}+{}{}".format(
+ base_version,
+ info["revision"],
+ info["branch"].replace("/", "."),
+ modified.replace("+", "."),
+ )
+
+
+
+
#
# Options
#
-name = "twextpy"
+project_name = "twextpy"
description = "Extensions to Twisted"
@@ -207,7 +299,7 @@
version_file.close()
setup(
- name=name,
+ name=project_name,
version=version_string,
description=description,
long_description=long_description,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150313/4044bc0f/attachment-0001.html>
More information about the calendarserver-changes
mailing list