Opened 8 years ago

Closed 8 years ago

#627 closed defect (fixed)

Git commit hash not found on linux

Reported by: lewis Owned by:
Priority: minor Milestone: SasView 4.0.0
Component: SasView Keywords:
Cc: Work Package: SasView Bug Fixing

Description

Running SasView on linux gives the error:

WARNING:root:Error while determining build number
  Command '['git', 'rev-parse', 'HEAD']' returned non-zero exit status 1

Then when SasView opens, clicking Help→About shows "Build: GIT_COMMIT" instead of the actual commit hash.

I believe this is because on linux, commands executed via subprocess.check_output() aren't ran from the cwd.

Adding something like:

command = 'git rev-parse HEAD'
if sys.platform.count('linux') > 0:
    command = 'cd ' + os.getcwd() + '; ' + command
git_revision = subprocess.check_output(command,
                stderr=FNULL,
                shell=True)

to sasview/__init__.py seems to do the job, but seems a bit hacky?

Change History (10)

comment:1 Changed 8 years ago by butler

The git hash is made to ensure that the commit hash for the build being distributed gets placed in the correct variable but should not prevent from running on a system without git. For Linux of course one is building in place I suspect? or is it from the ubuntu egg?

Either way — the point is that the first error is now generated on windows machines as well even when running the windows distributable built on DMSC machines. However it is mostly invisible as it only shows up in the log file (not even in the console). The About box has the last hash put there which is the one put there when built on DMSC machines and so correct.

HOWEVER — loading SasView now seems really slow compared to what it used to be. Suspect these are related?

comment:2 Changed 8 years ago by lewis

I was building in place (running "python run.py" from the sasview repo)

SasView still runs fine, the error message just appears in the terminal

comment:3 Changed 8 years ago by wojciech

The problem also appears on osx and when running from run.py the side effect is that it doesn't log to sasview.log.

The potential fix to the problem may involve pass in expect statement of sasview/init.py instead of:
import logging
import sys
logging.warning("Error while determining build number\n %s" % sys.exc_value)

comment:4 Changed 8 years ago by ajj

  • Resolution set to fixed
  • Status changed from new to closed

Problem was that the call to subprocess was incorrectly assembled.

Fixed in a3f1c11

comment:5 Changed 8 years ago by krzywon

  • Resolution fixed deleted
  • Status changed from closed to reopened

Windows is now throwing this error:

WARNING:root:Error while determining build number
  Using command:
 ['git describe --tags'] 
 Output:

comment:6 Changed 8 years ago by krzywon

Changing line 8 of sasview.init fixes the issue on Windows. Subprocess wants each argument as a separate list item. Could someone check this on linux?

git_revision = subprocess.check_output(['git', 'describe', '--tags'],

comment:7 Changed 8 years ago by ajj

That will now break on linux and mac - on those platforms putting the arguments as a list made it fail.

comment:8 Changed 8 years ago by ajj

In commit 654e8e0 line 8 now reads:

git_revision = subprocess.check_output(['git describe', '--tags'],

which works on mac and linux AFAICS. Will close ticket once confirmed that this works on windows.

(Has a single line of code ever been so commented on? )

comment:9 Changed 8 years ago by krzywon

That didn't work so I changed it to be platform dependent. Confirm on Linux and Mac, please.

if platform.system() == "Windows":
    args = ['git', 'describe', '--tags']
else:
    args = ['git describe --tags']
git_revision = subprocess.check_output(args,


comment:10 Changed 8 years ago by ajj

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed by jkrzywon as above.

For future reference: https://docs.python.org/2/library/subprocess.html#popen-constructor contains at least the statement that how the arguments to subprocess are marshalled and executed depends on the OS. Next time I'll RTFM properly.

Note: See TracTickets for help on using tickets.