Skip to content
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

base_parser: support relative path include files #399

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Javagedes
Copy link
Contributor

@Javagedes Javagedes commented Aug 28, 2023

This commit adds support for including multiple relative paths from the same directory by storing a stack of all included files that have not finished being parsed, and the number of lines that still need to be parsed in each file.

Previously, only includes of nested relative paths were supported as the currently parsed file was not reverted to the previous file when the parsing of an included file was completed. This led to further includes needing the be relative to the latest included file.

closes #394

@Javagedes Javagedes requested a review from spbrogan August 28, 2023 18:41
@Javagedes Javagedes added this to the v0.17.1 milestone Aug 28, 2023
@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (cadd3f2) 81.19% compared to head (d15392b) 81.30%.
Report is 1 commits behind head on master.

Files Patch % Lines
edk2toollib/uefi/edk2/parsers/base_parser.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #399      +/-   ##
==========================================
+ Coverage   81.19%   81.30%   +0.11%     
==========================================
  Files          57       57              
  Lines        7358     7383      +25     
==========================================
+ Hits         5974     6003      +29     
+ Misses       1384     1380       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Javagedes Javagedes modified the milestones: v0.18.1, 0.18.3 Oct 2, 2023
@Javagedes Javagedes modified the milestones: 0.19.1, 0.19.2, 0.19.3, 0.19.4 Oct 23, 2023
@Javagedes Javagedes modified the milestones: 0.19.4, 0.19.5 Nov 1, 2023
@Javagedes Javagedes modified the milestones: 0.19.5, 0.19.6, v0.19.7 Nov 20, 2023
@Javagedes Javagedes modified the milestones: 0.19.7, 0.19.8 Dec 4, 2023
@Javagedes Javagedes requested a review from makubacki December 8, 2023 19:39
This commit adds support for including multiple relative paths from
the same directory by storing a stack of all included files that have
not finished being parsed, and the number of lines that still need to
be parsed in each file.

Previously, only includes of nested relative paths were supported as
the currently parsed file was not reverted to the previous file when the
parsing of an included file was completed. This led to further includes
needing the be relative to the latest included file.
@Javagedes Javagedes modified the milestones: 0.19.8, v0.19.9 Dec 13, 2023
@Javagedes Javagedes modified the milestones: v0.19.9, v0.19.10 Jan 11, 2024
@Javagedes Javagedes added this to the v0.20.2 milestone Feb 2, 2024
@Javagedes Javagedes modified the milestones: v0.20.2, v0.20.3, v0.20.4 Feb 9, 2024
@@ -42,6 +42,8 @@ def __init__(self, log="BaseParser"):
self.PPs = []
self._Edk2PathUtil = None
self.TargetFilePath = None # the abs path of the target file
self.FilePathStack = [] # a stack containing a list of size 2: [filepath, line_count]
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT:

Since you're likely dealing with a large set of data, the following solution probably doesn't make a lot of sense performance wise but if you wanted to improve readability of the code you could do something like a namedtuple.

However the object instantiation might be too much for a large dataset

from collections import namedtuple

# Define the namedtuple type
FilePathRecord = namedtuple('FilePathRecord', ['filepath', 'line_count'])

self.FilePathStack = []  # a stack containing FilePathRecord instances

self.FilePathStack.append(FilePathRecord('my_file_path', 100))

self.FilePathStack[0].file_path

return False
line_count = self.FilePathStack[-1][1]
if line_count - 1 > 0:
self.FilePathStack[-1][1] -= 1
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT:

        updated_line_count = self.FilePathStack[-1][1] - 1
        if updated_line_count > 0:
            self.FilePathStack[-1][1] -= updated_line_count

@@ -92,10 +92,10 @@ def __ParseLine(self, Line, file_name=None, lineno=None):
if sp is None:
raise FileNotFoundError(include_file)
self.Logger.debug("Opening Include File %s" % sp)
self._PushTargetFile(sp)
lf = open(sp, "r")
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: I know you didn't write this but if we switch to with we can drop lf.close()

@Javagedes Javagedes modified the milestones: v0.21.4, v0.21.6 Apr 15, 2024
@Javagedes Javagedes modified the milestones: v0.21.6, v0.21.7, v0.21.8 Jun 5, 2024
@Javagedes Javagedes modified the milestones: v0.21.8, v0.21.9 Jun 24, 2024
@Javagedes Javagedes modified the milestones: v0.21.9, v0.21.10, v0.21.11 Jul 31, 2024
@Javagedes Javagedes modified the milestones: v0.21.11, v0.21.12, v0.21.13 Oct 1, 2024
@Javagedes Javagedes modified the milestones: v0.22.0, v0.22.1, v0.22.2, v0.22.3 Oct 14, 2024
@Javagedes Javagedes modified the milestones: v0.22.3, v0.22.4 Nov 22, 2024
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.

[Bug]: base_parser.TargetFilePath not reverted when exiting an !include parse
2 participants