Skip to content

Commit b8344f0

Browse files
committed
Merge pull request #26 from jakirkham/setup_improv
Improves on `setup.py`
2 parents 5d581fa + b4357e7 commit b8344f0

File tree

4 files changed

+165
-3
lines changed

4 files changed

+165
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*.py[cod]
66
*.egg-info
77

8+
# Build products
9+
build/
10+
dist/
11+
812
# Test coverage files
913
.coverage
1014

README.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,47 @@ Test the program using the following command:
3737

3838
python setup.py tests
3939

40+
Documentation
41+
=============
42+
43+
Documentation can be built from source on any platform easily. Just run the
44+
following command.
45+
46+
::
47+
48+
python setup.py build_sphinx
49+
50+
This will generate HTML documentation, which can be open using this file
51+
``build/sphinx/html/index.html`` in the current directory.
52+
53+
For more build options, simply run the following command.
54+
55+
::
56+
57+
python setup.py build_sphinx --help
58+
59+
Other build targets can be specified using the ``-b`` or ``--builder`` option.
60+
Beyond the standard options that Sphinx provides, we add the `pdf` option.
61+
62+
Cleaning
63+
========
64+
65+
To clean up the directory after building, one can use the ``clean`` option.
66+
This will eliminate all intermediates build products. The syntax is shown
67+
below.
68+
69+
::
70+
71+
python setup.py clean
72+
73+
If this is not sufficient, and one wishes to eliminate the final products this
74+
can be done with the flag ``-a`` or ``--all``. This adjustment to the syntax is
75+
shown below.
76+
77+
::
78+
79+
python setup.py clean --all
80+
4081
Usage
4182
=====
4283

mouse/__init__.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,30 @@
7878
Documentation
7979
===============================================================================
8080
81-
Documentation can be built from source on any platform easily. To do this enter
82-
the ``docs/`` directory. A number of different formats can be used. However,
83-
the design target is HTML. To build the HTML docs, enter the following command.
81+
Documentation can be built from source on any platform easily. Just run the
82+
following command.
83+
84+
.. code-block:: sh
85+
86+
python setup.py build_sphinx
87+
88+
This will generate HTML documentation, which can be open using this file
89+
``build/sphinx/html/index.html`` in the current directory.
90+
91+
For more build options, simply run the following command.
92+
93+
.. code-block:: sh
94+
95+
python setup.py build_sphinx --help
96+
97+
Other build targets can be specified using the ``-b`` or ``--builder`` option.
98+
Beyond the standard options that Sphinx provides, we add the `pdf` option.
99+
100+
Alternatively, if one does not wish to use ``setup.py``, one can use a Makefile
101+
or ``make.bat`` on Windows in the ``docs/`` directory to generate
102+
documentation. To do this enter the ``docs/`` directory. A number of different
103+
formats can be used. However, the design target is HTML. To build the HTML
104+
docs, enter the following command.
84105
85106
.. code-block:: sh
86107
@@ -101,6 +122,26 @@
101122
102123
make clean
103124
125+
===============================================================================
126+
Cleaning
127+
===============================================================================
128+
129+
To clean up all build products, one can use the ``clean`` option. This will
130+
eliminate all intermediates used to build. This has been amended to include
131+
picking up documentation build intermediates. The syntax is shown below.
132+
133+
.. code-block:: sh
134+
135+
python setup.py clean
136+
137+
If this is not sufficient, and one wishes to eliminate the final products, as
138+
well. This can be done with the flag ``-a`` or ``--all``. This adjustment to
139+
the syntax is shown below.
140+
141+
.. code-block:: sh
142+
143+
python setup.py clean --all
144+
104145
===============================================================================
105146
Usage
106147
===============================================================================

setup.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,80 @@
44
__date__ = "$July 30, 2015 20:20:18 EDT$"
55

66
from glob import glob
7+
import os
8+
import shutil
9+
import sys
10+
711
from setuptools import setup, find_packages
812

913
import versioneer
1014

1115

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+
1281
setup(
1382
name="mouse_recorder",
1483
version=versioneer.get_version(),
@@ -26,3 +95,10 @@
2695
test_suite="nose.collector",
2796
zip_safe=True
2897
)
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

Comments
 (0)