Merge lp:~manishsinha/microfiber/fix-hardcoded-sphinx-build-in-usrbin into lp:microfiber

Status: Merged
Merged at revision: 78
Proposed branch: lp:~manishsinha/microfiber/fix-hardcoded-sphinx-build-in-usrbin
Merge into: lp:microfiber
Diff against target: 24 lines (+10/-2)
1 file modified
setup.py (+10/-2)
To merge this branch: bzr merge lp:~manishsinha/microfiber/fix-hardcoded-sphinx-build-in-usrbin
Reviewer Review Type Date Requested Status
Jason Gerard DeRose Approve
Review via email: mp+74918@code.launchpad.net

Commit message

Fixed bugs #847044 where sphinx-build was hardcoded at /usr/bin/sphinx-build

Read the $PATH environment variable. Split it by : character. For every entry append
'sphinx-build' and check whether the file exists. If the file exists, check if it
is executable. If yes, then return the path. If none is found then return None.
The method calling this search method has to handle None return by showing a WARNING

Description of the change

Fixed bugs #847044 where sphinx-build was hardcoded at /usr/bin/sphinx-build

Read the $PATH environment variable. Split it by : character. For every entry append
'sphinx-build' and check whether the file exists. If the file exists, check if it
is executable. If yes, then return the path. If none is found then return None.
The method calling this search method has to handle None return by showing a WARNING

To post a comment you must log in.
Revision history for this message
Jason Gerard DeRose (jderose) wrote :

After thinking on this a bit, I feel something like this is a better solution:

class build_with_docs(build):

    def run(self):
        build.run(self)
        try:
            sphinx = subprocess.check_output(['/bin/which', 'sphinx-build'])
        except subprocess.CalledProcessError:
            print("WARNING: Documentation not generated. python-sphinx missing")
            return
        tree = path.dirname(path.abspath(__file__))
        src = path.join(tree, 'doc')
        dst = path.join(tree, 'doc', '_build', 'html')
        cmd = [
            sphinx,
            '-b', 'html',
            src,
            dst
        ]
        subprocess.check_call(cmd)

What do you think?

review: Needs Fixing
Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

In this case you are again hardcoding the path to be /bin or something. The actual path has to be taken from PATH environment variable

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

My mistake. I mistook it. Now there are two ways
* Open subprocesses
* check the path now.

Your call now

79. By Manish Sinha (मनीष सिन्हा)

Changed manual filename creation with os.path.join

80. By Manish Sinha (मनीष सिन्हा)

Change os.path.isfile to path.isfile

81. By Manish Sinha (मनीष सिन्हा)

Removed the name clash with 'path'. Renamed path to file_path

Revision history for this message
Jason Gerard DeRose (jderose) wrote :

That's the ticket. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'setup.py'
2--- setup.py 2011-09-11 17:41:32 +0000
3+++ setup.py 2011-09-11 20:10:24 +0000
4@@ -102,10 +102,18 @@
5
6 class build_with_docs(build):
7
8+ def find_sphinx_path(self):
9+ for prefix in os.environ['PATH'].split(':'):
10+ file_path = os.path.join(prefix, 'sphinx-build')
11+ if path.isfile(file_path) and os.access(file_path, os.X_OK):
12+ return file_path
13+
14+ return None
15+
16 def run(self):
17 build.run(self)
18- sphinx = '/usr/bin/sphinx-build'
19- if not path.isfile(sphinx):
20+ sphinx = self.find_sphinx_path()
21+ if sphinx is None:
22 print("WARNING: Documentation not generated. python-sphinx missing")
23 return
24 tree = path.dirname(path.abspath(__file__))

Subscribers

People subscribed via source and target branches