| 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 | import glob |
|---|
| 37 | import os |
|---|
| 38 | import sys |
|---|
| 39 | import string |
|---|
| 40 | |
|---|
| 41 | from distutils.core import Command |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | import ez_setup |
|---|
| 45 | ez_setup.use_setuptools() |
|---|
| 46 | |
|---|
| 47 | from setuptools import setup, find_packages |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | from setuptools.command.test import test as _test |
|---|
| 52 | |
|---|
| 53 | def _TestClass(base): |
|---|
| 54 | class _test(base): |
|---|
| 55 | description = base.description + ", for FiPy and its examples" |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | user_options = base.user_options + [ |
|---|
| 60 | ('inline', None, "run FiPy with inline compilation enabled"), |
|---|
| 61 | ('pythoncompiled=', None, "directory in which to put weave's work product"), |
|---|
| 62 | ('Trilinos', None, "run FiPy using Trilinos solvers"), |
|---|
| 63 | ('Pysparse', None, "run FiPy using Pysparse solvers (default)"), |
|---|
| 64 | ('all', None, "run all non-interactive FiPy tests (default)"), |
|---|
| 65 | ('really-all', None, "run *all* FiPy tests (including those requiring user input)"), |
|---|
| 66 | ('examples', None, "test FiPy examples"), |
|---|
| 67 | ('modules', None, "test FiPy code modules"), |
|---|
| 68 | ('viewers', None, "test FiPy viewer modules (requires user input)"), |
|---|
| 69 | ('cache', None, "run FiPy with Variable caching"), |
|---|
| 70 | ('no-cache', None, "run FiPy without Variable caching"), |
|---|
| 71 | ] |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | def initialize_options(self): |
|---|
| 75 | base.initialize_options(self) |
|---|
| 76 | |
|---|
| 77 | self.all = False |
|---|
| 78 | self.really_all = False |
|---|
| 79 | self.examples = False |
|---|
| 80 | self.modules = False |
|---|
| 81 | self.viewers = False |
|---|
| 82 | |
|---|
| 83 | self.inline = False |
|---|
| 84 | self.pythoncompiled = None |
|---|
| 85 | self.cache = False |
|---|
| 86 | self.no_cache = True |
|---|
| 87 | self.Trilinos = False |
|---|
| 88 | self.Pysparse = False |
|---|
| 89 | |
|---|
| 90 | def finalize_options(self): |
|---|
| 91 | noSuiteOrModule = (self.test_suite is None |
|---|
| 92 | and self.test_module is None) |
|---|
| 93 | |
|---|
| 94 | base.finalize_options(self) |
|---|
| 95 | |
|---|
| 96 | if noSuiteOrModule: |
|---|
| 97 | self.test_args.remove(self.distribution.test_suite) |
|---|
| 98 | |
|---|
| 99 | if not (self.examples or self.modules or self.viewers): |
|---|
| 100 | self.all = True |
|---|
| 101 | if self.all or self.really_all: |
|---|
| 102 | self.examples = True |
|---|
| 103 | self.modules = True |
|---|
| 104 | if self.really_all: |
|---|
| 105 | self.viewers = True |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | if self.viewers: |
|---|
| 109 | print "*" * 60 |
|---|
| 110 | print "*" + "".center(58) + "*" |
|---|
| 111 | print "*" + "ATTENTION".center(58) + "*" |
|---|
| 112 | print "*" + "".center(58) + "*" |
|---|
| 113 | print "*" + "Some of the following tests require user interaction".center(58) + "*" |
|---|
| 114 | print "*" + "".center(58) + "*" |
|---|
| 115 | print "*" * 60 |
|---|
| 116 | |
|---|
| 117 | self.test_args.append("fipy.viewers.testinteractive._suite") |
|---|
| 118 | |
|---|
| 119 | if self.modules: |
|---|
| 120 | self.test_args.append("fipy.test._suite") |
|---|
| 121 | |
|---|
| 122 | if self.examples: |
|---|
| 123 | self.test_args.append("examples.test._suite") |
|---|
| 124 | |
|---|
| 125 | if self.test_args and noSuiteOrModule: |
|---|
| 126 | self.test_suite = "dummy" |
|---|
| 127 | |
|---|
| 128 | def run_tests(self): |
|---|
| 129 | import sys |
|---|
| 130 | if self.Trilinos: |
|---|
| 131 | try: |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | try: |
|---|
| 138 | import scipy |
|---|
| 139 | except: |
|---|
| 140 | pass |
|---|
| 141 | import PyTrilinos |
|---|
| 142 | except ImportError, a: |
|---|
| 143 | print >>sys.stderr, "!!! Trilinos library is not installed" |
|---|
| 144 | return |
|---|
| 145 | |
|---|
| 146 | if self.inline: |
|---|
| 147 | try: |
|---|
| 148 | from scipy import weave |
|---|
| 149 | except ImportError, a: |
|---|
| 150 | print >>sys.stderr, "!!! weave library is not installed" |
|---|
| 151 | return |
|---|
| 152 | |
|---|
| 153 | if self.pythoncompiled is not None: |
|---|
| 154 | import os |
|---|
| 155 | os.environ['PYTHONCOMPILED'] = self.pythoncompiled |
|---|
| 156 | |
|---|
| 157 | base.run_tests(self) |
|---|
| 158 | |
|---|
| 159 | return _test |
|---|
| 160 | |
|---|
| 161 | test = _TestClass(_test) |
|---|
| 162 | |
|---|
| 163 | try: |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | from bitten.util.testrunner import unittest as _unittest |
|---|
| 167 | unittest = _TestClass(_unittest) |
|---|
| 168 | except ImportError, e: |
|---|
| 169 | unittest = test |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | class build_docs (Command): |
|---|
| 174 | |
|---|
| 175 | description = "build the FiPy api documentation" |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | user_options = [('latex', None, "compile the LaTeX variant of the apis"), |
|---|
| 180 | ('html', None, "compile the HTML variant of the apis"), |
|---|
| 181 | ('guide', None, "compile the user guide"), |
|---|
| 182 | ('apis', None, "compile the programmer's reference"), |
|---|
| 183 | ('manual', None, "compile the manual"), |
|---|
| 184 | ('all', None, "compile both the LaTeX and HTML variants of the apis"), |
|---|
| 185 | ('webpage', None, "compile the html for the web page"), |
|---|
| 186 | ('upload', None, "upload webpages, documentation, and distributions to CTCMS website"), |
|---|
| 187 | ('uploadwww', None, "upload webpages to CTCMS website"), |
|---|
| 188 | ] |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | def initialize_options (self): |
|---|
| 192 | self.latex = 0 |
|---|
| 193 | self.html = 0 |
|---|
| 194 | self.guide = 0 |
|---|
| 195 | self.apis = 0 |
|---|
| 196 | self.manual = 0 |
|---|
| 197 | self.all = 0 |
|---|
| 198 | self.webpage = 0 |
|---|
| 199 | self.upload = 0 |
|---|
| 200 | self.uploadwww = 0 |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | def finalize_options (self): |
|---|
| 205 | if self.all: |
|---|
| 206 | self.latex = 1 |
|---|
| 207 | self.manual = 1 |
|---|
| 208 | self.webpage = 1 |
|---|
| 209 | |
|---|
| 210 | if self.manual: |
|---|
| 211 | self.guide = 1 |
|---|
| 212 | self.apis = 1 |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | def _initializeDirectory(self, dir, type = 'latex'): |
|---|
| 217 | dir = os.path.join(dir, type) |
|---|
| 218 | |
|---|
| 219 | try: |
|---|
| 220 | for root, dirs, files in os.walk(dir, topdown=False): |
|---|
| 221 | for name in files: |
|---|
| 222 | os.remove(os.path.join(root, name)) |
|---|
| 223 | for name in dirs: |
|---|
| 224 | os.rmdir(os.path.join(root, name)) |
|---|
| 225 | os.rmdir(dir) |
|---|
| 226 | except: |
|---|
| 227 | pass |
|---|
| 228 | |
|---|
| 229 | os.makedirs(dir) |
|---|
| 230 | |
|---|
| 231 | def _epydocFiles(self, module, dir = None, type = 'pdflatex'): |
|---|
| 232 | dir = os.path.join(dir, type) |
|---|
| 233 | |
|---|
| 234 | import epydoc.cli |
|---|
| 235 | epydoc.cli.cli(["--%s" % type, "--output", dir, |
|---|
| 236 | "--no-private", "--show-imports", |
|---|
| 237 | "--name", "FiPy", |
|---|
| 238 | module]) |
|---|
| 239 | |
|---|
| 240 | def _buildTeXAPIs(self): |
|---|
| 241 | dir = os.path.join('documentation', 'manual', 'api') |
|---|
| 242 | self._initializeDirectory(dir = dir, type = 'latex') |
|---|
| 243 | dir = os.path.join(dir, 'latex') |
|---|
| 244 | |
|---|
| 245 | import epydoc.cli |
|---|
| 246 | epydoc.cli.cli(["--latex", "--output", dir, |
|---|
| 247 | "--graph=classtree", "--inheritance=listed", |
|---|
| 248 | "--no-private", "--show-imports", |
|---|
| 249 | "fipy/"]) |
|---|
| 250 | |
|---|
| 251 | savedir = os.getcwd() |
|---|
| 252 | try: |
|---|
| 253 | |
|---|
| 254 | os.chdir(os.path.join('documentation','manual')) |
|---|
| 255 | |
|---|
| 256 | f = open(os.path.join('api','latex', 'api-rev.tex'), 'w') |
|---|
| 257 | f.write("% This file is created automatically by:\n") |
|---|
| 258 | f.write("% python setup.py build_docs --latex\n\n") |
|---|
| 259 | for root, dirs, files in os.walk(os.path.join('api','latex'), topdown=True): |
|---|
| 260 | |
|---|
| 261 | if 'api.tex' in files: |
|---|
| 262 | files.remove('api.tex') |
|---|
| 263 | |
|---|
| 264 | if 'api-rev.tex' in files: |
|---|
| 265 | files.remove('api-rev.tex') |
|---|
| 266 | |
|---|
| 267 | if 'fipy-module.tex' in files: |
|---|
| 268 | files.remove('fipy-module.tex') |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | files.sort() |
|---|
| 273 | |
|---|
| 274 | import re |
|---|
| 275 | mainModule = re.compile(r"(fipy\.[^.-]*)-module\.tex") |
|---|
| 276 | subModule = re.compile(r"(fipy(\.[^.-]*)+)-module\.tex") |
|---|
| 277 | for name in files: |
|---|
| 278 | mainMatch = mainModule.match(name) |
|---|
| 279 | subMatch = subModule.match(name) |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | def stringInModule(s): |
|---|
| 283 | module = open(os.path.join(root, name)) |
|---|
| 284 | functionLine = re.compile(s) |
|---|
| 285 | flag = False |
|---|
| 286 | for line in module: |
|---|
| 287 | if functionLine.search(line): |
|---|
| 288 | flag = True |
|---|
| 289 | break |
|---|
| 290 | |
|---|
| 291 | module.close() |
|---|
| 292 | |
|---|
| 293 | return flag |
|---|
| 294 | |
|---|
| 295 | if mainMatch and stringInModule(r"\\section{Package") \ |
|---|
| 296 | and not stringInModule(r"no chapter heading"): |
|---|
| 297 | module = open(os.path.join(root, name), 'r') |
|---|
| 298 | lines = [] |
|---|
| 299 | |
|---|
| 300 | for line in module: |
|---|
| 301 | |
|---|
| 302 | line = re.sub(r'\\section', r'\\chapter', line) |
|---|
| 303 | line = re.sub(r'\\subsection', r'\\section', line) |
|---|
| 304 | line = re.sub(r'\\subsubsection', r'\\subsection', line) |
|---|
| 305 | lines.append(line) |
|---|
| 306 | |
|---|
| 307 | module.close() |
|---|
| 308 | module = open(os.path.join(root, name), 'w') |
|---|
| 309 | module.writelines(lines) |
|---|
| 310 | module.close() |
|---|
| 311 | |
|---|
| 312 | if not stringInModule(r"\\section{(Functions|Variables|Class)"): |
|---|
| 313 | f.write("\\chapter{Package \\EpydocDottedName{" + subMatch.group(1) + "}}\n") |
|---|
| 314 | |
|---|
| 315 | if subMatch: |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | if not stringInModule(r"\\(sub)?section{(Functions|Variables|Class)"): |
|---|
| 319 | continue |
|---|
| 320 | |
|---|
| 321 | split = os.path.splitext(name) |
|---|
| 322 | if split[1] == ".tex": |
|---|
| 323 | f.write("\\input{" + os.path.splitext(name)[0] + "}\n\\newpage\n") |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | f.close() |
|---|
| 327 | except: |
|---|
| 328 | pass |
|---|
| 329 | |
|---|
| 330 | os.chdir(savedir) |
|---|
| 331 | |
|---|
| 332 | def _translateTextFiles(self, source_dir = '.', destination_dir = '.', files = [], writer = None, settings = {}, ext = '.tex'): |
|---|
| 333 | from docutils import core |
|---|
| 334 | |
|---|
| 335 | for file in files: |
|---|
| 336 | |
|---|
| 337 | destination_path = os.path.join(destination_dir, string.lower(file) + ext) |
|---|
| 338 | try: |
|---|
| 339 | os.makedirs(os.path.dirname(destination_path)) |
|---|
| 340 | except: |
|---|
| 341 | pass |
|---|
| 342 | source_path = os.path.join(source_dir, file + '.txt') |
|---|
| 343 | |
|---|
| 344 | core.publish_file(source_path= source_path, |
|---|
| 345 | destination_path = destination_path, |
|---|
| 346 | reader_name = 'standalone', |
|---|
| 347 | parser_name = 'restructuredtext', |
|---|
| 348 | writer = writer, |
|---|
| 349 | settings_overrides = settings) |
|---|
| 350 | |
|---|
| 351 | translated = open(destination_path, 'r') |
|---|
| 352 | lines = [] |
|---|
| 353 | |
|---|
| 354 | for line in translated: |
|---|
| 355 | import re |
|---|
| 356 | line = re.sub(r'\\tableofcontents', r'% this automatically generated line conflicts with minitoc\r% \\tableofcontents', line) |
|---|
| 357 | lines.append(line) |
|---|
| 358 | |
|---|
| 359 | translated.close() |
|---|
| 360 | translated = open(destination_path, 'w') |
|---|
| 361 | translated.writelines(lines) |
|---|
| 362 | translated.close() |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | os.utime(destination_path, (os.path.getatime(source_path), os.path.getmtime(source_path))) |
|---|
| 366 | |
|---|
| 367 | def run (self): |
|---|
| 368 | f = open(os.path.join('documentation','VERSION.txt'), 'w') |
|---|
| 369 | f.write('.. |VERSION| replace:: ' + self.distribution.metadata.get_version()) |
|---|
| 370 | f.close() |
|---|
| 371 | |
|---|
| 372 | mainRestructuredTextFiles = {'article': |
|---|
| 373 | ['INSTALLATION', |
|---|
| 374 | 'README', |
|---|
| 375 | 'LICENSE', |
|---|
| 376 | 'DISCLAIMER', |
|---|
| 377 | 'examples/README'], |
|---|
| 378 | 'startlower': |
|---|
| 379 | ['WINDOWS-INSTALLATION', |
|---|
| 380 | 'MACOSX-INSTALLATION', |
|---|
| 381 | 'examples/levelSet/electroChem/README']} |
|---|
| 382 | |
|---|
| 383 | |
|---|
| 384 | secondaryRestructuredTextFiles = {'article': |
|---|
| 385 | ['CREDITS', |
|---|
| 386 | 'TALKS', |
|---|
| 387 | 'TODOLIST', |
|---|
| 388 | 'SVN', |
|---|
| 389 | 'EFFICIENCY', |
|---|
| 390 | 'VKML'], |
|---|
| 391 | 'startlower': |
|---|
| 392 | ['MAIL']} |
|---|
| 393 | |
|---|
| 394 | if self.latex: |
|---|
| 395 | if self.apis: |
|---|
| 396 | self._buildTeXAPIs() |
|---|
| 397 | |
|---|
| 398 | if self.guide: |
|---|
| 399 | dir = os.path.join('documentation', 'manual', 'examples') |
|---|
| 400 | self._initializeDirectory(dir = dir, type = 'latex') |
|---|
| 401 | dir = os.path.join(dir, 'latex') |
|---|
| 402 | |
|---|
| 403 | import epydoc.cli |
|---|
| 404 | epydoc.cli.cli(["--latex", "--output", dir, |
|---|
| 405 | "--no-private", "--show-imports", |
|---|
| 406 | "examples/"]) |
|---|
| 407 | |
|---|
| 408 | if self.html: |
|---|
| 409 | dir = os.path.join('documentation', 'manual', 'api') |
|---|
| 410 | self._initializeDirectory(dir = dir, type = 'html') |
|---|
| 411 | self._epydocFiles(module = 'fipy/', dir = dir, type = 'html') |
|---|
| 412 | |
|---|
| 413 | if self.apis: |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | dir = os.path.join('documentation', 'manual', 'tutorial') |
|---|
| 417 | self._initializeDirectory(dir = dir, type = 'latex') |
|---|
| 418 | dir = os.path.join(dir, 'latex') |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | exec(""" |
|---|
| 428 | import sys |
|---|
| 429 | if sys.modules.has_key('fipy'): |
|---|
| 430 | del sys.modules['fipy'] |
|---|
| 431 | |
|---|
| 432 | if sys.modules.has_key('epydoc.uid'): |
|---|
| 433 | sys.modules['epydoc.uid']._object_uids = {} |
|---|
| 434 | sys.modules['epydoc.uid']._variable_uids = {} |
|---|
| 435 | sys.modules['epydoc.uid']._name_to_uid = {} |
|---|
| 436 | |
|---|
| 437 | import epydoc.cli |
|---|
| 438 | epydoc.cli.cli(["--latex", "--output", dir, |
|---|
| 439 | "--graph=classtree", |
|---|
| 440 | "--no-private", "--show-imports", |
|---|
| 441 | "documentation/manual/tutorial/fipy/"]) |
|---|
| 442 | """) |
|---|
| 443 | |
|---|
| 444 | if self.guide or self.apis: |
|---|
| 445 | savedir = os.getcwd() |
|---|
| 446 | |
|---|
| 447 | os.chdir(os.path.join('documentation','manual')) |
|---|
| 448 | |
|---|
| 449 | f = open('version.tex', 'w') |
|---|
| 450 | f.write("% This file is created automatically by:\n") |
|---|
| 451 | f.write("% python setup.py build_docs --manual\n\n") |
|---|
| 452 | f.write("\\newcommand{\\Version}{" + self.distribution.metadata.get_version() + "}\n") |
|---|
| 453 | f.close() |
|---|
| 454 | |
|---|
| 455 | from utils.includedLaTeXWriter import IncludedLaTeXWriter |
|---|
| 456 | |
|---|
| 457 | for key in mainRestructuredTextFiles.keys(): |
|---|
| 458 | self._translateTextFiles(files = mainRestructuredTextFiles[key], |
|---|
| 459 | source_dir = '../..', |
|---|
| 460 | writer = IncludedLaTeXWriter(), |
|---|
| 461 | settings ={'use_latex_toc': True, |
|---|
| 462 | 'footnote_references': 'superscript', |
|---|
| 463 | 'table_style': 'nolines', |
|---|
| 464 | 'documentclass': key}) |
|---|
| 465 | |
|---|
| 466 | for key in mainRestructuredTextFiles.keys(): |
|---|
| 467 | self._translateTextFiles(files = secondaryRestructuredTextFiles[key], |
|---|
| 468 | source_dir = '..', |
|---|
| 469 | writer = IncludedLaTeXWriter(), |
|---|
| 470 | settings ={'use_latex_toc': True, |
|---|
| 471 | 'footnote_references': 'superscript', |
|---|
| 472 | 'table_style': 'booktabs', |
|---|
| 473 | 'documentclass': key}) |
|---|
| 474 | |
|---|
| 475 | if self.guide: |
|---|
| 476 | os.system("pdflatex fipy") |
|---|
| 477 | os.system("bibtex fipy") |
|---|
| 478 | os.system("makeindex fipy") |
|---|
| 479 | os.system("pdflatex fipy") |
|---|
| 480 | os.system("pdflatex fipy") |
|---|
| 481 | |
|---|
| 482 | if self.apis: |
|---|
| 483 | os.system("pdflatex reference") |
|---|
| 484 | os.system("bibtex reference") |
|---|
| 485 | os.system("makeindex reference") |
|---|
| 486 | os.system("pdflatex reference") |
|---|
| 487 | os.system("pdflatex reference") |
|---|
| 488 | |
|---|
| 489 | os.chdir(savedir) |
|---|
| 490 | |
|---|
| 491 | if self.webpage: |
|---|
| 492 | import tempfile |
|---|
| 493 | tmp = tempfile.mkdtemp() |
|---|
| 494 | dir = os.path.join('documentation', 'www') |
|---|
| 495 | |
|---|
| 496 | from utils.includedHTMLWriter import IncludedHTMLWriter |
|---|
| 497 | |
|---|
| 498 | print "main files" |
|---|
| 499 | for key in mainRestructuredTextFiles.keys(): |
|---|
| 500 | self._translateTextFiles(files = mainRestructuredTextFiles[key], |
|---|
| 501 | destination_dir = tmp, |
|---|
| 502 | writer = IncludedHTMLWriter(), |
|---|
| 503 | settings = {'initial_header_level' : 3, |
|---|
| 504 | 'xml_declaration' : 0}, |
|---|
| 505 | ext = '.html') |
|---|
| 506 | |
|---|
| 507 | print "secondary files" |
|---|
| 508 | for key in secondaryRestructuredTextFiles.keys(): |
|---|
| 509 | self._translateTextFiles(files = secondaryRestructuredTextFiles[key], |
|---|
| 510 | source_dir = "documentation", |
|---|
| 511 | destination_dir = tmp, |
|---|
| 512 | writer = IncludedHTMLWriter(), |
|---|
| 513 | settings = {'initial_header_level' : 3, |
|---|
| 514 | 'xml_declaration' : 0}, |
|---|
| 515 | ext = '.html') |
|---|
| 516 | |
|---|
| 517 | import shutil |
|---|
| 518 | for f in ['menu.html', 'meta.html', 'logo.html', 'extra.html']: |
|---|
| 519 | shutil.copyfile(os.path.join(dir, f), os.path.join(tmp, f)) |
|---|
| 520 | shutil.move(os.path.join(tmp, 'readme.html'), os.path.join(tmp, 'index.html')) |
|---|
| 521 | shutil.move(os.path.join(tmp, 'examples', 'levelSet', 'electroChem', 'readme.html'), os.path.join(tmp, 'electrochem.html')) |
|---|
| 522 | |
|---|
| 523 | print "merging files" |
|---|
| 524 | os.system("/Library/WebServer/Documents/CSS/ctcmsWeb.py %s %s" % (tmp, dir)) |
|---|
| 525 | |
|---|
| 526 | print "removing directories" |
|---|
| 527 | for root, dirs, files in os.walk(tmp, topdown=False): |
|---|
| 528 | for name in files: |
|---|
| 529 | os.remove(os.path.join(root, name)) |
|---|
| 530 | for name in dirs: |
|---|
| 531 | os.rmdir(os.path.join(root, name)) |
|---|
| 532 | |
|---|
| 533 | if self.upload: |
|---|
| 534 | |
|---|
| 535 | print "setting group and ownership of manuals..." |
|---|
| 536 | os.system('chgrp -R pfm documentation/manual/fipy.pdf') |
|---|
| 537 | os.system('chmod -R g+w documentation/manual/reference.pdf') |
|---|
| 538 | os.system('chmod -R g+w documentation/manual/reference.pdf') |
|---|
| 539 | os.system('chgrp -R pfm documentation/manual/fipy.pdf') |
|---|
| 540 | |
|---|
| 541 | print "linking manuals to website..." |
|---|
| 542 | os.system('mkdir documentation/www/download/') |
|---|
| 543 | os.system('ln -sf ../../manual/fipy.pdf documentation/www/download/fipy-%s.pdf'%self.distribution.metadata.get_version()) |
|---|
| 544 | os.system('ln -sf ../../manual/reference.pdf documentation/www/download/reference-%s.pdf'%self.distribution.metadata.get_version()) |
|---|
| 545 | |
|---|
| 546 | for name in ('.tar.gz', '.win32.zip'): |
|---|
| 547 | file = 'dist/FiPy-%s%s'%(self.distribution.metadata.get_version(), name) |
|---|
| 548 | print "setting group and ownership for %s ..."%file |
|---|
| 549 | os.system('chmod -R g+w %s'%file) |
|---|
| 550 | os.system('chgrp -R pfm %s'%file) |
|---|
| 551 | |
|---|
| 552 | print "linking %s to website ..."%file |
|---|
| 553 | os.system('ln -sf ../../../%s documentation/www/download/'%file) |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | if self.upload or self.uploadwww: |
|---|
| 557 | |
|---|
| 558 | print "setting group and ownership of web pages..." |
|---|
| 559 | os.system('chgrp -R pfm documentation/www/') |
|---|
| 560 | os.system('chmod -R g+w documentation/www/') |
|---|
| 561 | |
|---|
| 562 | print "uploading web pages..." |
|---|
| 563 | |
|---|
| 564 | |
|---|
| 565 | os.system('rsync -rlpgoDLC -e ssh %s %s'%('documentation/www/', os.environ['FIPY_WWWHOST'])) |
|---|
| 566 | |
|---|
| 567 | print "activating web pages..." |
|---|
| 568 | os.system(os.environ['FIPY_WWWACTIVATE']) |
|---|
| 569 | |
|---|
| 570 | |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | class copy_script(Command): |
|---|
| 574 | description = "copy an example script into a new editable file" |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | |
|---|
| 578 | user_options = [ |
|---|
| 579 | |
|---|
| 580 | ('From=', None, |
|---|
| 581 | "path and file name containing script to copy"), |
|---|
| 582 | ('To=', None, |
|---|
| 583 | "path and file name to save script to") |
|---|
| 584 | ] |
|---|
| 585 | |
|---|
| 586 | def initialize_options(self): |
|---|
| 587 | self.From = None |
|---|
| 588 | self.To = None |
|---|
| 589 | |
|---|
| 590 | def finalize_options(self): |
|---|
| 591 | if self.From == None: |
|---|
| 592 | raise "Please specify a '--From' input script file" |
|---|
| 593 | |
|---|
| 594 | if self.To == None: |
|---|
| 595 | raise "Please specify a '--To' output script file" |
|---|
| 596 | |
|---|
| 597 | if os.path.exists(os.path.expanduser(self.To)): |
|---|
| 598 | ans = "junk" |
|---|
| 599 | |
|---|
| 600 | while (len(ans) > 0) and ("yes".find(ans.lower()) is not 0) and ("no".find(ans.lower()) is not 0): |
|---|
| 601 | ans = raw_input("The file '%s' already exists. Overwrite? [n] "%self.To) |
|---|
| 602 | |
|---|
| 603 | if ans is '': |
|---|
| 604 | ans = 'no' |
|---|
| 605 | |
|---|
| 606 | if ("no".find(ans.lower()) is 0): |
|---|
| 607 | self.To = raw_input("Please give a name for the ouput file: ") |
|---|
| 608 | self.finalize_options() |
|---|
| 609 | |
|---|
| 610 | def run(self): |
|---|
| 611 | import imp |
|---|
| 612 | import fipy.tests.doctestPlus |
|---|
| 613 | |
|---|
| 614 | mod = imp.load_source("copy_script_module", self.From) |
|---|
| 615 | script = fipy.tests.doctestPlus._getScript(name = "copy_script_module") |
|---|
| 616 | |
|---|
| 617 | script = "#!/usr/bin/env python\n\n## This script was derived from\n## '%s'\n\n%s"%(self.From, script) |
|---|
| 618 | |
|---|
| 619 | f = file(self.To, "w") |
|---|
| 620 | f.write(script) |
|---|
| 621 | f.close |
|---|
| 622 | |
|---|
| 623 | print "Script code exported from '%s' to '%s'"%(self.From, self.To) |
|---|
| 624 | |
|---|
| 625 | class efficiency_test(Command): |
|---|
| 626 | description = "run FiPy efficiency tests" |
|---|
| 627 | |
|---|
| 628 | user_options = [ ('minimumelements=', None, 'minimum number of elements'), |
|---|
| 629 | ('factor=', None, 'factor by which the number of elements is increased'), |
|---|
| 630 | ('inline', None, 'turn on inlining for the efficiency tests'), |
|---|
| 631 | ('cache', None, 'turn on variable caching'), |
|---|
| 632 | ('maximumelements=', None, 'maximum number of elements'), |
|---|
| 633 | ('sampleTime=', None, 'sampling interval for memory high-water'), |
|---|
| 634 | ('path=', None, 'directory to place output results in')] |
|---|
| 635 | |
|---|
| 636 | def initialize_options(self): |
|---|
| 637 | self.factor = 10 |
|---|
| 638 | self.inline = 0 |
|---|
| 639 | self.cache = 0 |
|---|
| 640 | self.maximumelements = 10000 |
|---|
| 641 | self.minimumelements = 100 |
|---|
| 642 | self.sampleTime = 1 |
|---|
| 643 | self.path = None |
|---|
| 644 | self.cases = ['examples/benchmarking/cahnHilliard.py', 'examples/benchmarking/superfill.py', 'examples/benchmarking/phaseImpingement.py', 'examples/benchmarking/mesh.py'] |
|---|
| 645 | |
|---|
| 646 | def finalize_options(self): |
|---|
| 647 | self.factor = int(self.factor) |
|---|
| 648 | self.maximumelements = int(self.maximumelements) |
|---|
| 649 | self.minimumelements = int(self.minimumelements) |
|---|
| 650 | self.sampleTime = float(self.sampleTime) |
|---|
| 651 | |
|---|
| 652 | def run(self): |
|---|
| 653 | |
|---|
| 654 | import time |
|---|
| 655 | import os |
|---|
| 656 | |
|---|
| 657 | for case in self.cases: |
|---|
| 658 | print "case: %s" % case |
|---|
| 659 | |
|---|
| 660 | if self.path is None: |
|---|
| 661 | testPath = os.path.split(case)[0] |
|---|
| 662 | else: |
|---|
| 663 | testPath = self.path |
|---|
| 664 | |
|---|
| 665 | if not os.access(testPath, os.F_OK): |
|---|
| 666 | os.makedirs(testPath) |
|---|
| 667 | |
|---|
| 668 | testPath = os.path.join(testPath, '%s.dat' % os.path.split(case)[1]) |
|---|
| 669 | |
|---|
| 670 | if not os.path.isfile(testPath): |
|---|
| 671 | f = open(testPath, 'w') |
|---|
| 672 | |
|---|
| 673 | f.write("\t".join(["--inline", "--cache", "Date", "Elements", \ |
|---|
| 674 | "mesh (s)", "variables (s)", "terms (s)", \ |
|---|
| 675 | "solver (s)", "BCs (s)", "solve (s)", \ |
|---|
| 676 | "total (s)", "per step (s)", \ |
|---|
| 677 | \ |
|---|
| 678 | "mesh (KiB)", "variables (KiB)", \ |
|---|
| 679 | "terms (KiB)", "solver (KiB)", "BCs (KiB)", \ |
|---|
| 680 | "solve (KiB)", "max (KiB)", \ |
|---|
| 681 | "per element (KiB)"])) |
|---|
| 682 | f.write("\n") |
|---|
| 683 | f.flush() |
|---|
| 684 | else: |
|---|
| 685 | f = open(testPath, 'a') |
|---|
| 686 | |
|---|
| 687 | numberOfElements = self.minimumelements |
|---|
| 688 | |
|---|
| 689 | while numberOfElements <= self.maximumelements: |
|---|
| 690 | print "\tnumberOfElements: %i" % numberOfElements |
|---|
| 691 | |
|---|
| 692 | cmd = [case, '--numberOfElements=%i' % numberOfElements] |
|---|
| 693 | |
|---|
| 694 | if self.inline: |
|---|
| 695 | cmd += ['--inline'] |
|---|
| 696 | |
|---|
| 697 | if self.cache: |
|---|
| 698 | cmd += ['--cache'] |
|---|
| 699 | else: |
|---|
| 700 | cmd += ['--no-cache'] |
|---|
| 701 | |
|---|
| 702 | output = "\t".join([str(self.inline), str(self.cache), time.ctime(), str(numberOfElements)]) |
|---|
| 703 | |
|---|
| 704 | timeCmd = cmd + ['--measureTime'] |
|---|
| 705 | w, r = os.popen4(' '.join(timeCmd)) |
|---|
| 706 | output += '\t' + ''.join(r.readlines()).strip() |
|---|
| 707 | r.close() |
|---|
| 708 | w.close() |
|---|
| 709 | |
|---|
| 710 | memCmd = cmd + ['--measureMemory', '--sampleTime=%f' % self.sampleTime] |
|---|
| 711 | w, r = os.popen4(' '.join(memCmd)) |
|---|
| 712 | output += '\t' + ''.join(r.readlines()).strip() |
|---|
| 713 | r.close() |
|---|
| 714 | w.close() |
|---|
| 715 | |
|---|
| 716 | f.write(output + '\n') |
|---|
| 717 | f.flush() |
|---|
| 718 | |
|---|
| 719 | numberOfElements *= self.factor |
|---|
| 720 | |
|---|
| 721 | f.close() |
|---|
| 722 | |
|---|
| 723 | try: |
|---|
| 724 | f = open('README.txt', 'r') |
|---|
| 725 | long_description = '\n' + f.read() + '\n' |
|---|
| 726 | f.close() |
|---|
| 727 | except IOError, e: |
|---|
| 728 | long_description = '' |
|---|
| 729 | |
|---|
| 730 | try: |
|---|
| 731 | f = open('LICENSE.txt', 'r') |
|---|
| 732 | license = '\n' + f.read() + '\n' |
|---|
| 733 | f.close() |
|---|
| 734 | except IOError, e: |
|---|
| 735 | license = '' |
|---|
| 736 | |
|---|
| 737 | |
|---|
| 738 | |
|---|
| 739 | |
|---|
| 740 | |
|---|
| 741 | |
|---|
| 742 | |
|---|
| 743 | |
|---|
| 744 | |
|---|
| 745 | |
|---|
| 746 | |
|---|
| 747 | |
|---|
| 748 | dist = setup( name = "FiPy", |
|---|
| 749 | version = "2.0a1", |
|---|
| 750 | author = "Jonathan Guyer, Daniel Wheeler, & Jim Warren", |
|---|
| 751 | author_email = "fipy@nist.gov", |
|---|
| 752 | url = "http://www.ctcms.nist.gov/fipy/", |
|---|
| 753 | license = license, |
|---|
| 754 | description = "A finite volume PDE solver in Python", |
|---|
| 755 | long_description = long_description, |
|---|
| 756 | cmdclass = { |
|---|
| 757 | 'build_docs':build_docs, |
|---|
| 758 | 'test':test, |
|---|
| 759 | 'unittest':unittest, |
|---|
| 760 | 'copy_script': copy_script, |
|---|
| 761 | 'efficiency_test': efficiency_test |
|---|
| 762 | }, |
|---|
| 763 | test_suite="fipy.test._suite", |
|---|
| 764 | packages = find_packages(exclude=["examples", "examples.*", "utils", "utils.*"]), |
|---|
| 765 | entry_points=""" |
|---|
| 766 | [fipy.viewers] |
|---|
| 767 | gist = fipy.viewers.gistViewer:GistViewer |
|---|
| 768 | gnuplot = fipy.viewers.gnuplotViewer:GnuplotViewer |
|---|
| 769 | matplotlib = fipy.viewers.matplotlibViewer:MatplotlibViewer |
|---|
| 770 | mayavi = fipy.viewers.mayaviViewer:MayaviViewer |
|---|
| 771 | """, |
|---|
| 772 | classifiers = [ |
|---|
| 773 | 'Development Status :: 5 - Production/Stable', |
|---|
| 774 | 'Environment :: Console', |
|---|
| 775 | 'Environment :: X11 Applications', |
|---|
| 776 | 'Intended Audience :: Science/Research', |
|---|
| 777 | 'License :: Public Domain', |
|---|
| 778 | 'Natural Language :: English', |
|---|
| 779 | 'Operating System :: OS Independent', |
|---|
| 780 | 'Programming Language :: Python', |
|---|
| 781 | 'Topic :: Scientific/Engineering :: Mathematics', |
|---|
| 782 | 'Topic :: Scientific/Engineering :: Physics', |
|---|
| 783 | 'Topic :: Scientific/Engineering :: Visualization', |
|---|
| 784 | 'Topic :: Software Development :: Libraries :: Python Modules' |
|---|
| 785 | ], |
|---|
| 786 | ) |
|---|
| 787 | |
|---|
| 788 | if 'install' in dist.commands: |
|---|
| 789 | req = [] |
|---|
| 790 | |
|---|
| 791 | for pkg in ['numpy', 'pysparse']: |
|---|
| 792 | try: |
|---|
| 793 | __import__(pkg) |
|---|
| 794 | except ImportError, exc: |
|---|
| 795 | req.append(pkg) |
|---|
| 796 | |
|---|
| 797 | if len(req) > 0: |
|---|
| 798 | print "!!!!!!" |
|---|
| 799 | print "The required module(s) " + str(req) + " cannot be loaded." |
|---|
| 800 | print "FiPy will not work properly until these modules are installed." |
|---|
| 801 | |
|---|
| 802 | opt = [] |
|---|
| 803 | |
|---|
| 804 | for pkg in ['scipy', 'matplotlib', 'gist', 'mayavi']: |
|---|
| 805 | try: |
|---|
| 806 | __import__(pkg) |
|---|
| 807 | except ImportError, exc: |
|---|
| 808 | opt.append(pkg) |
|---|
| 809 | |
|---|
| 810 | if len(opt) > 0: |
|---|
| 811 | print "------" |
|---|
| 812 | print "The optional module(s) " + str(opt) + " cannot be loaded." |
|---|
| 813 | print "FiPy will have improved capabilities if these modules are installed." |
|---|