Skip to content

Commit

Permalink
Merge pull request #1124 from notdian/file_not_found_error
Browse files Browse the repository at this point in the history
remove incorrect os.chdir, handle relative extends/includes
  • Loading branch information
p12tic authored Jan 30, 2025
2 parents 51d180d + e03d675 commit d1ba2f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions newsfragments/1125.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix handling of relative includes and extends
12 changes: 8 additions & 4 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -1925,9 +1925,6 @@ def _parse_compose_file(self):
dotenv_path = os.path.realpath(args.env_file)
dotenv_dict.update(dotenv_to_dict(dotenv_path))

# TODO: remove next line
os.chdir(dirname)

os.environ.update({
key: value for key, value in dotenv_dict.items() if key.startswith("PODMAN_")
})
Expand Down Expand Up @@ -1969,11 +1966,18 @@ def _parse_compose_file(self):
content = normalize(content)
# log(filename, json.dumps(content, indent = 2))
content = rec_subs(content, self.environ)
if isinstance(services := content.get('services'), dict):
for service in services.values():
if 'extends' in service and (service_file := service['extends'].get('file')):
service['extends']['file'] = os.path.join(
os.path.dirname(filename), service_file
)

rec_merge(compose, content)
# If `include` is used, append included files to files
include = compose.get("include")
if include:
files.extend(include)
files.extend([os.path.join(os.path.dirname(filename), i) for i in include])
# As compose obj is updated and tested with every loop, not deleting `include`
# from it, results in it being tested again and again, original values for
# `include` be appended to `files`, and, included files be processed for ever.
Expand Down

0 comments on commit d1ba2f4

Please sign in to comment.