Skip to content

Commit

Permalink
fix: don't resolve filename in compilation unit provider
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Oct 30, 2023
1 parent f0bd453 commit 7c32194
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion mecha/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def __post_init__(
self.steps.append(self.optimize)
self.steps.append(self.check)

self.database.directory = self.directory

if self.perf_report is None and self.output_perf:
self.perf_report = []

Expand All @@ -238,7 +240,7 @@ def __post_init__(
parsers=get_parsers(version),
)

self.providers = [FileTypeCompilationUnitProvider([Function], self.directory)]
self.providers = [FileTypeCompilationUnitProvider([Function])]

self.serialize = Serializer(
spec=self.spec,
Expand Down
17 changes: 10 additions & 7 deletions mecha/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class CompilationDatabase(Container[TextFileBase[Any], CompilationUnit]):
current: TextFileBase[Any]
count: int

generate: Optional[Generator] = None
generate: Optional[Generator]
directory: Optional[FileSystemPath]

def __init__(self):
super().__init__()
Expand All @@ -88,6 +89,7 @@ def __init__(self):
self.count = 0

self.generate = None
self.directory = None

@property
def index(self) -> Dict[str, TextFileBase[Any]]:
Expand All @@ -102,7 +104,14 @@ def process(
for index in [value.filename, value.resource_location]:
if index:
pack_index[index] = key

value.diagnostics.file = key

if not value.filename and key.source_path and self.directory:
value.filename = os.path.relpath(key.source_path, self.directory)
if not value.diagnostics.filename and value.filename:
value.diagnostics.filename = value.filename

return value

def __delitem__(self, key: TextFileBase[Any]):
Expand Down Expand Up @@ -171,7 +180,6 @@ class FileTypeCompilationUnitProvider:
"""Provide source files based on their type."""

file_types: List[Type[NamespaceFile]]
directory: FileSystemPath

def __call__(
self,
Expand All @@ -192,10 +200,5 @@ def __call__(

yield file_instance, CompilationUnit(
resource_location=resource_location,
filename=(
os.path.relpath(file_instance.source_path, self.directory)
if file_instance.source_path
else None
),
pack=pack,
)
2 changes: 1 addition & 1 deletion tests/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class DummySourceFile(TextFile):
@pytest.fixture
def dummy_source_file_provider(mc: Mecha):
previous_providers = mc.providers
mc.providers = [FileTypeCompilationUnitProvider([DummySourceFile], mc.directory)]
mc.providers = [FileTypeCompilationUnitProvider([DummySourceFile])]
yield
mc.providers = previous_providers

Expand Down

0 comments on commit 7c32194

Please sign in to comment.