Skip to content

read the bat file to set up the process environment #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 12 additions & 19 deletions OMPython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,25 +933,18 @@ def _run_cmd(self, cmd: list, verbose: bool = True):

if platform.system() == "Windows":
omhome = os.path.join(os.environ.get("OPENMODELICAHOME"))
dllPath = (os.path.join(omhome, "bin")
+ os.pathsep + os.path.join(omhome, "lib/omc")
+ os.pathsep + os.path.join(omhome, "lib/omc/cpp")
+ os.pathsep + os.path.join(omhome, "lib/omc/omsicpp"))

# include path to resources of defined external libraries
for element in self.lmodel:
if element is not None:
if isinstance(element, str):
if element.endswith("package.mo"):
pkgpath = element[:-10] + '/Resources/Library/'
for wver in ['win32', 'win64']:
pkgpath_wver = pkgpath + '/' + wver
if os.path.exists(pkgpath_wver):
dllPath = pkgpath_wver + os.pathsep + dllPath

# fix backslash in path definitions
dllPath = dllPath.replace("\\", "/")

dllPath = ""

## set the process environment from the generated .bat file in windows which should have all the dependencies
batFilePath = os.path.join(self.tempdir, '{}.{}'.format(self.modelName, "bat")).replace("\\", "/")
if (not os.path.exists(batFilePath)):
print("Error: bat does not exist " + batFilePath)
Copy link
Member

Choose a reason for hiding this comment

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

You can change this to logging once PR #228 is merged.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@adeas31 sure

Copy link
Contributor

@syntron syntron Nov 11, 2024

Choose a reason for hiding this comment

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

Shouldn't this be an IOError? - if the *.bat file does not exists there is something wrong ...


with open(batFilePath, 'r') as file:
for line in file:
match = re.match(r"^SET PATH=([^%]*)", line, re.IGNORECASE)
if match:
dllPath = match.group(1).strip(';') # Remove any trailing semicolons
my_env = os.environ.copy()
my_env["PATH"] = dllPath + os.pathsep + my_env["PATH"]
else:
Expand Down