Skip to content

Conversation

@stewartboogert
Copy link
Contributor

Need an easy way to determine what clhep, root and geant4 are installed

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new Versions class to the Run.py module that detects and retrieves version information for ROOT, Geant4, and CLHEP by executing their respective config commands.

Key Changes:

  • Introduced Versions class with methods to query version information from external tools (ROOT, Geant4, CLHEP)
  • Added error handling for CLHEP version detection when the executable is not available
Comments suppressed due to low confidence (1)

src/pybdsim/Run.py:568

  • Except block directly handles BaseException.
        except :

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 561 to 575
result = _subprocess.run(["root-config","--version"], capture_output=True, text=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"

def _find_geant4_version(self) :
try :
result = _subprocess.run(["geant4-config","--version"], capture_output=True, text=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"

def _find_clhep_version(self) :
try :
result = _subprocess.run(["clhep-config","--version"], capture_output=True, text=True)
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception handling catches CalledProcessError but doesn't check the return code before accessing stdout. If the command fails (non-zero exit code), stdout may still contain data but the exception will be caught. Add check=True parameter to subprocess.run() to properly raise CalledProcessError on non-zero exit codes.

Suggested change
result = _subprocess.run(["root-config","--version"], capture_output=True, text=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"
def _find_geant4_version(self) :
try :
result = _subprocess.run(["geant4-config","--version"], capture_output=True, text=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"
def _find_clhep_version(self) :
try :
result = _subprocess.run(["clhep-config","--version"], capture_output=True, text=True)
result = _subprocess.run(["root-config","--version"], capture_output=True, text=True, check=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"
def _find_geant4_version(self) :
try :
result = _subprocess.run(["geant4-config","--version"], capture_output=True, text=True, check=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"
def _find_clhep_version(self) :
try :
result = _subprocess.run(["clhep-config","--version"], capture_output=True, text=True, check=True)

Copilot uses AI. Check for mistakes.
Comment on lines 561 to 575
result = _subprocess.run(["root-config","--version"], capture_output=True, text=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"

def _find_geant4_version(self) :
try :
result = _subprocess.run(["geant4-config","--version"], capture_output=True, text=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"

def _find_clhep_version(self) :
try :
result = _subprocess.run(["clhep-config","--version"], capture_output=True, text=True)
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception handling catches CalledProcessError but doesn't check the return code before accessing stdout. If the command fails (non-zero exit code), stdout may still contain data but the exception will be caught. Add check=True parameter to subprocess.run() to properly raise CalledProcessError on non-zero exit codes.

Suggested change
result = _subprocess.run(["root-config","--version"], capture_output=True, text=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"
def _find_geant4_version(self) :
try :
result = _subprocess.run(["geant4-config","--version"], capture_output=True, text=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"
def _find_clhep_version(self) :
try :
result = _subprocess.run(["clhep-config","--version"], capture_output=True, text=True)
result = _subprocess.run(["root-config","--version"], capture_output=True, text=True, check=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"
def _find_geant4_version(self) :
try :
result = _subprocess.run(["geant4-config","--version"], capture_output=True, text=True, check=True)
return result.stdout.strip()
except (FileNotFoundError, _subprocess.CalledProcessError):
return "Not found"
def _find_clhep_version(self) :
try :
result = _subprocess.run(["clhep-config","--version"], capture_output=True, text=True, check=True)

Copilot uses AI. Check for mistakes.
Comment on lines 575 to 581
result = _subprocess.run(["clhep-config","--version"], capture_output=True, text=True)
parts = result.stdout.split()
if len(parts) == 2 :
return parts[1].strip()
else :
return "Not found"
except (FileNotFoundError, _subprocess.CalledProcessError):
Copy link

Copilot AI Nov 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception handling catches CalledProcessError but doesn't check the return code before accessing stdout. If the command fails (non-zero exit code), the code will attempt to parse stdout before the exception is caught. Add check=True parameter to subprocess.run() to properly raise CalledProcessError on non-zero exit codes.

Copilot uses AI. Check for mistakes.
@lnevay
Copy link
Contributor

lnevay commented Nov 11, 2025

Looks good. Only thing is that technically, your environment can be different from what BDSIM was compiled w.r.t. The other solution would be to add the functionality to BDSIM to report back what it was compiled with. If this technicality is ok for you then fine.

@stewartboogert
Copy link
Contributor Author

Looks good. Only thing is that technically, your environment can be different from what BDSIM was compiled w.r.t. The other solution would be to add the functionality to BDSIM to report back what it was compiled with. If this technicality is ok for you then fine.

I think here creating a bdsim-config script or executable (very similar to geant4-config, clhep-config and root-config) would make a lot of sense in this case. Not a lot of work, but not worth it right now I feel.

@stewartboogert stewartboogert merged commit 0210063 into bdsim-collaboration:develop Nov 28, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants