1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
#! /usr/bin/python
# -*- coding: utf-8 -*-
# setup.py
# Part of Gracie, an OpenID provider.
#
# Copyright © 2007–2010 Ben Finney <ben+python@benfinney.id.au>
# This is free software; you may copy, modify and/or distribute this work
# under the terms of the GNU General Public License, version 2 or later.
# No warranty expressed or implied. See the file ‘LICENSE.GPL-2’ for details.
""" Python distutils setup for ‘gracie’ distribution.
"""
import distutils.cmd
import distutils.command.build
import distutils.command.install
import distutils.command.clean
import distutils.log
import distutils.util
import os
import os.path
import glob
import errno
import subprocess
import re
import textwrap
from setuptools import setup, find_packages
import docutils.core
distribution_name = "gracie"
main_module_name = 'gracie'
main_module = __import__(main_module_name, fromlist=['version'])
version = main_module.version
main_module_doc = main_module.__doc__.decode('utf-8')
short_description, long_description = (
textwrap.dedent(desc).strip()
for desc in main_module_doc.split('\n\n', 1)
)
def is_source_file_newer(source_path, destination_path, force=False):
""" Return True if destination is older than source or does not exist. """
if force:
result = True
else:
source_stat = os.stat(source_path)
source_ctime = source_stat.st_ctime
try:
destination_stat = os.stat(destination_path)
except OSError, exc:
if exc.errno == errno.ENOENT:
destination_ctime = None
else:
raise
else:
destination_ctime = destination_stat.st_ctime
result = (source_ctime > destination_ctime)
return result
class BuildDocumentationCommand(distutils.cmd.Command):
""" Build documentation for this distribution. """
user_options = [
("force", 'f',
"Forcibly build everything (ignore file timestamps)."),
("html-src-files=", None,
"Source files to build to HTML documents."),
("manpage-8-src-files=", None,
"Source files to build to Unix manpages for section 8."),
("logo-src-file=", None,
"Source SVG document for project logo."),
]
boolean_options = ['force']
def initialize_options(self):
""" Initialise command options to defaults. """
self.document_transforms = {
'html': {
'func': render_rst_document,
'source_name_option': 'html_src_files',
'writer_name': 'html',
'source_suffix_regex': re.compile("\.txt$"),
'dest_suffix': ".html",
},
'manpage.8': {
'func': render_rst_document,
'source_name_option': 'manpage_8_src_files',
'writer_name': 'manpage',
'source_suffix_regex': re.compile("\.8\.txt$"),
'dest_suffix': ".8",
},
'logo': {
'func': render_svg_document,
'source_name_option': 'logo_src_file',
'size': 80,
'format': 'PNG',
'source_suffix_regex': re.compile("\.svg$"),
'dest_suffix': ".png",
},
}
self.force = None
for transform in self.document_transforms.values():
option_name = transform['source_name_option']
setattr(self, option_name, None)
def finalize_options(self):
""" Finalise command options before execution. """
self.set_undefined_options(
'build',
('force', 'force'))
for (transform_name, transform) in self.document_transforms.items():
source_paths = []
option_name = transform['source_name_option']
source_files_option_value = getattr(self, option_name, None)
if source_files_option_value is not None:
source_paths = source_files_option_value.split()
transform['source_paths'] = source_paths
def _render_documents(self, transform):
""" Render documents that are not up-to-date. """
for in_file_path in transform['source_paths']:
out_file_base = re.sub(
transform['source_suffix_regex'], "",
in_file_path)
out_file_path = out_file_base + transform['dest_suffix']
render_document_func = transform['func']
if is_source_file_newer(in_file_path, out_file_path, self.force):
out_file_dir = os.path.dirname(out_file_path)
if not os.path.isdir(out_file_dir):
self.mkpath(out_file_dir)
render_document_func(in_file_path, out_file_path, transform)
def run(self):
""" Execute this command. """
for transform in self.document_transforms.values():
self._render_documents(transform)
class BuildCommand(distutils.command.build.build):
""" Custom ‘build’ command for this distribution. """
sub_commands = (
[('build_doc', lambda self: True)]
+ distutils.command.build.build.sub_commands)
class InstallCommand(distutils.command.install.install):
""" Custom ‘install’ command for this distribution. """
sub_commands = (
[('build_doc', lambda self: True)]
+ distutils.command.install.install.sub_commands)
def render_rst_document(in_file_path, out_file_path, transform):
""" Render a document from source to dest using specified writer. """
in_file_path = distutils.util.convert_path(in_file_path)
out_file_path = distutils.util.convert_path(out_file_path)
writer = transform['writer_name']
distutils.log.info(
"using writer %(writer)r to render document"
" %(in_file_path)r -> %(out_file_path)r"
% vars())
docutils.core.publish_file(
source_path=in_file_path,
destination_path=out_file_path,
writer_name=transform['writer_name'])
def render_svg_document(in_file_path, out_file_path, transform):
""" Render SVG document to destination logo file. """
in_file_path = distutils.util.convert_path(in_file_path)
out_file_path = distutils.util.convert_path(out_file_path)
geometry = "%(size)dx%(size)d" % transform
render_process_args = [
"gm", "convert",
"-format", "SVG", in_file_path,
"-geometry", geometry,
"-format", transform['format'], out_file_path,
]
distutils.log.info(
"rendering logo %(in_file_path)r -> %(out_file_path)r"
% vars())
subprocess.call(render_process_args)
class CleanDocumentationCommand(distutils.cmd.Command):
""" Clean files generated for this distribution's documentation. """
user_options = [
("all", 'a',
"Remove all build output, not just temporary by-products."),
("generated-files=", None,
"File globs of generated documentation files."),
]
boolean_options = ['all']
def initialize_options(self):
""" Initialise command options to defaults. """
self.all = None
self.generated_files = None
def finalize_options(self):
""" Finalise command options before execution. """
self.set_undefined_options(
'clean',
('all', 'all'))
if self.generated_files:
self.generated_file_globs = self.generated_files.split()
else:
self.generated_file_globs = []
def run(self):
""" Execute this command. """
generated_file_paths = set()
for file_glob in self.generated_file_globs:
generated_file_paths.update(set(
glob.glob(file_glob)))
for file_path in generated_file_paths:
os.remove(file_path)
class CleanCommand(distutils.command.clean.clean, object):
""" Custom ‘clean’ command for this distribution. """
sub_commands = (
[('clean_doc', lambda self: True)]
+ distutils.command.clean.clean.sub_commands)
def run(self):
for cmd_name in self.get_sub_commands():
self.run_command(cmd_name)
super(CleanCommand, self).run()
setup(
name=distribution_name,
version=version.version,
packages=find_packages(
exclude=['test'],
),
scripts=[
"bin/gracied",
],
cmdclass={
"build": BuildCommand,
"build_doc": BuildDocumentationCommand,
"install": InstallCommand,
"clean": CleanCommand,
"clean_doc": CleanDocumentationCommand,
},
# Setuptools metadata.
zip_safe=False,
install_requires=[
"setuptools",
"docutils >=0.6",
"python-daemon >=1.4.5",
"python-openid >=1.2",
"Routes >=1.6.3",
],
tests_require=[
"MiniMock >= 1.2.2",
],
test_suite="test.suite",
# PyPI metadata.
author=version.author_name,
author_email=version.author_email,
description=short_description,
keywords=[
"gracie", "openid", "identity", "authentication", "provider",
],
url=main_module._url,
long_description=long_description,
license=version.license,
classifiers=[
# Reference: http://pypi.python.org/pypi?%3Aaction=list_classifiers
"Development Status :: 3 - Alpha",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Programming Language :: Python",
"Topic :: Internet",
"Topic :: System",
"Operating System :: POSIX",
"Intended Audience :: System Administrators",
],
)
# Local variables:
# coding: utf-8
# mode: python
# End:
# vim: fileencoding=utf-8 filetype=python :
|