Skip to content

Commit

Permalink
Resolve exported packages' imports
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed May 6, 2022
1 parent 6299719 commit c419351
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
17 changes: 10 additions & 7 deletions rflx/model/model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from collections import defaultdict
from pathlib import Path
from typing import Dict, List, Sequence, Union
from typing import Dict, Sequence

from rflx import const
from rflx.common import Base, indent, verbose_repr
from rflx.common import Base, verbose_repr
from rflx.error import RecordFluxError, Severity, Subsystem
from rflx.identifier import ID
from rflx.model.package import Package
Expand Down Expand Up @@ -46,11 +45,15 @@ def create_specifications(self) -> Dict[ID, str]:
pkgs: Dict[ID, Package] = {}
for ty in self.__types:
if not type_.is_builtin_type(ty.name) and not type_.is_internal_type(ty.name):
pkg = ty.package
pkgs.setdefault(pkg, Package(pkg)).types.append(ty)
pkg_name: ID = ty.package
pkg: Package = pkgs.setdefault(pkg_name, Package(pkg_name))
for dep in ty.dependencies:
if dep.package != pkg_name:
pkg.imports.append(dep.package)
pkg.types.append(ty)
for sess in self.__sessions:
pkg = sess.package
pkgs.setdefault(pkg, Package(pkg)).sessions.append(sess)
pkg_name = sess.package
pkgs.setdefault(pkg_name, Package(pkg_name)).sessions.append(sess)
return {id: str(pkg) for id, pkg in pkgs.items()}

def write_specification_files(self, output_dir: Path) -> None:
Expand Down
8 changes: 2 additions & 6 deletions rflx/model/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,5 @@ def sessions_str(self) -> str:
return textwrap.indent(raw, " " * 3)

def __str__(self) -> str:
return "\n\n".join(
filter(
None,
[self.imports_str, self.begin_str, self.types_str, self.sessions_str, self.end_str],
)
)
pieces = [self.imports_str, self.begin_str, self.types_str, self.sessions_str, self.end_str]
return "\n\n".join(filter(None, pieces))
2 changes: 1 addition & 1 deletion tests/unit/model/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,5 @@ def test_write_specification_file_multiple_packages(tmp_path: Path) -> None:
type U is mod 65536;
end P;"""
end Q;"""
)

0 comments on commit c419351

Please sign in to comment.