|
4 | 4 | __date__ = "$July 30, 2015 20:20:18 EDT$" |
5 | 5 |
|
6 | 6 | from glob import glob |
| 7 | +import os |
| 8 | +import shutil |
| 9 | +import sys |
| 10 | + |
7 | 11 | from setuptools import setup, find_packages |
8 | 12 |
|
9 | 13 | import versioneer |
10 | 14 |
|
11 | 15 |
|
| 16 | +build_requires = [] |
| 17 | +install_requires = [] |
| 18 | +tests_require = ["nose"] |
| 19 | +sphinx_build_pdf = False |
| 20 | +if len(sys.argv) == 1: |
| 21 | + pass |
| 22 | +elif sys.argv[1] == "build_sphinx": |
| 23 | + import sphinx.apidoc |
| 24 | + |
| 25 | + sphinx.apidoc.main([ |
| 26 | + sphinx.apidoc.__file__, |
| 27 | + "-f", "-T", "-e", "-M", |
| 28 | + "-o", "docs", |
| 29 | + ".", "setup.py", "tests", "versioneer.py" |
| 30 | + ]) |
| 31 | + |
| 32 | + build_prefix_arg_index = None |
| 33 | + for each_build_arg in ["-b", "--builder"]: |
| 34 | + try: |
| 35 | + build_arg_index = sys.argv.index(each_build_arg) |
| 36 | + except ValueError: |
| 37 | + continue |
| 38 | + |
| 39 | + if sys.argv[build_arg_index + 1] == "pdf": |
| 40 | + sphinx_build_pdf = True |
| 41 | + sys.argv[build_arg_index + 1] = "latex" |
| 42 | +elif sys.argv[1] == "clean": |
| 43 | + saved_rst_files = ["docs/index.rst", "docs/readme.rst", "docs/todo.rst"] |
| 44 | + |
| 45 | + tmp_rst_files = glob("docs/*.rst") |
| 46 | + |
| 47 | + print("removing 'docs/*.rst'") |
| 48 | + for each_saved_rst_file in saved_rst_files: |
| 49 | + print("skipping '" + each_saved_rst_file + "'") |
| 50 | + tmp_rst_files.remove(each_saved_rst_file) |
| 51 | + |
| 52 | + for each_tmp_rst_file in tmp_rst_files: |
| 53 | + os.remove(each_tmp_rst_file) |
| 54 | + |
| 55 | + if os.path.exists("build/sphinx/doctrees"): |
| 56 | + print("removing 'build/sphinx/doctrees'") |
| 57 | + shutil.rmtree("build/sphinx/doctrees") |
| 58 | + else: |
| 59 | + print("'build/sphinx/doctrees' does not exist -- can't clean it") |
| 60 | + |
| 61 | + if os.path.exists(".eggs"): |
| 62 | + print("removing '.eggs'") |
| 63 | + shutil.rmtree(".eggs") |
| 64 | + else: |
| 65 | + print("'.eggs' does not exist -- can't clean it") |
| 66 | + |
| 67 | + if (len(sys.argv) > 2) and (sys.argv[2] in ["-a", "--all"]): |
| 68 | + if os.path.exists("build/sphinx"): |
| 69 | + print("removing 'build/sphinx'") |
| 70 | + shutil.rmtree("build/sphinx") |
| 71 | + else: |
| 72 | + print("'build/sphinx' does not exist -- can't clean it") |
| 73 | +elif sys.argv[1] == "develop": |
| 74 | + if (len(sys.argv) > 2) and (sys.argv[2] in ["-u", "--uninstall"]): |
| 75 | + if os.path.exists("mouse_recorder.egg-info"): |
| 76 | + print("removing 'mouse_recorder.egg-info'") |
| 77 | + shutil.rmtree("mouse_recorder.egg-info") |
| 78 | + else: |
| 79 | + print("'mouse_recorder.egg-info' does not exist -- can't clean it") |
| 80 | + |
12 | 81 | setup( |
13 | 82 | name="mouse_recorder", |
14 | 83 | version=versioneer.get_version(), |
|
26 | 95 | test_suite="nose.collector", |
27 | 96 | zip_safe=True |
28 | 97 | ) |
| 98 | + |
| 99 | +if sphinx_build_pdf: |
| 100 | + make_cmd = os.environ.get("MAKE", "make") |
| 101 | + cwd = os.getcwd() |
| 102 | + os.chdir("build/sphinx/latex") |
| 103 | + os.execlpe(make_cmd, "all", os.environ) |
| 104 | + os.chdir(cwd) |
0 commit comments