Skip to content

Commit

Permalink
Fixed recursive operations (#178)
Browse files Browse the repository at this point in the history
* Fixed recursive operations

* Attempting to fix ubuntu tests and mating
  • Loading branch information
openvmp authored Aug 20, 2024
1 parent 25378c9 commit 31d024d
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 45 deletions.
140 changes: 104 additions & 36 deletions partcad-cli/src/partcad_cli/cli_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,21 @@ def cli_list_sketches(args, ctx):

output = "PartCAD sketches:\n"
for project_name in ctx.projects:
if not args.recursive and args.package != project_name:
continue

if (
hasattr(args, "package")
and not args.package is None
and args.package != project_name
args.recursive
and hasattr(args, "package")
and args.package is not None
and not project_name.startswith(args.package)
):
continue

if project_name != ctx.get_current_project_path() and (
not args.recursive
and hasattr(args, "package")
and args.package is None
if (
args.recursive
and (not hasattr(args, "package") or args.package is None)
and not project_name.startswith(ctx.get_current_project_path())
):
continue

Expand Down Expand Up @@ -268,17 +272,21 @@ def cli_list_interfaces(args, ctx):

output = "PartCAD interfaces:\n"
for project_name in ctx.projects:
if not args.recursive and args.package != project_name:
continue

if (
hasattr(args, "package")
and not args.package is None
and args.package != project_name
args.recursive
and hasattr(args, "package")
and args.package is not None
and not project_name.startswith(args.package)
):
continue

if project_name != ctx.get_current_project_path() and (
not args.recursive
and hasattr(args, "package")
and args.package is None
if (
args.recursive
and (not hasattr(args, "package") or args.package is None)
and not project_name.startswith(ctx.get_current_project_path())
):
continue

Expand Down Expand Up @@ -333,6 +341,37 @@ def cli_list_mates(args, ctx):
# with corresponding logging calls
time.sleep(2)

# Instantiate all interfaces in the relevant packages to get the mating data
# finalized
for package_name in ctx.projects:
if not args.recursive:
if (
hasattr(args, "package")
and args.package is not None
and package_name != args.package
):
continue
if (
not hasattr(args, "package") or args.package is None
) and package_name != ctx.get_current_project_path():
continue

if args.recursive:
if (
hasattr(args, "package")
and args.package is not None
and not package_name.startswith(args.package)
):
continue
if (
not hasattr(args, "package") or args.package is None
) and not package_name.startswith(ctx.get_current_project_path()):
continue

package = ctx.projects[package_name]
for interface_name in package.interfaces:
package.get_interface(interface_name)

output = "PartCAD mating interfaces:\n"
for source_interface_name in ctx.mates:
source_package_name = source_interface_name.split(":")[0]
Expand All @@ -345,19 +384,40 @@ def cli_list_mates(args, ctx):
mating = ctx.mates[source_interface_name][target_interface_name]

if (
hasattr(args, "package")
and not args.package is None
and args.package != source_package_name
and args.package != target_package_name
args.recursive
and hasattr(args, "package")
and args.package is not None
and not source_package_name.startswith(args.package)
and not target_package_name.startswith(args.package)
):
continue

if (
source_package_name != ctx.get_current_project_path()
and target_package_name != ctx.get_current_project_path()
and not args.recursive
args.recursive
and (not hasattr(args, "package") or args.package is None)
and not source_package_name.startswith(
ctx.get_current_project_path()
)
and not target_package_name.startswith(
ctx.get_current_project_path()
)
):
continue

if (
not args.recursive
and hasattr(args, "package")
and args.package is None
and args.package is not None
and source_package_name != args.package
and target_package_name != args.package
):
continue

if (
not args.recursive
and (not hasattr(args, "package") or args.package is None)
and source_package_name != ctx.get_current_project_path()
and target_package_name != ctx.get_current_project_path()
):
continue

Expand Down Expand Up @@ -409,17 +469,21 @@ def cli_list_parts(args, ctx):

output = "PartCAD parts:\n"
for project_name in ctx.projects:
if not args.recursive and args.package != project_name:
continue

if (
hasattr(args, "package")
and not args.package is None
and args.package != project_name
args.recursive
and hasattr(args, "package")
and args.package is not None
and not project_name.startswith(args.package)
):
continue

if project_name != ctx.get_current_project_path() and (
not args.recursive
and hasattr(args, "package")
and args.package is None
if (
args.recursive
and (not hasattr(args, "package") or args.package is None)
and not project_name.startswith(ctx.get_current_project_path())
):
continue

Expand Down Expand Up @@ -475,17 +539,21 @@ def cli_list_assemblies(args, ctx):

output = "PartCAD assemblies:\n"
for project_name in ctx.projects:
if not args.recursive and args.package != project_name:
continue

if (
hasattr(args, "package")
and not args.package is None
and args.package != project_name
args.recursive
and hasattr(args, "package")
and args.package is not None
and not project_name.startswith(args.package)
):
continue

if project_name != ctx.get_current_project_path() and (
not args.recursive
and hasattr(args, "package")
and args.package is None
if (
args.recursive
and (not hasattr(args, "package") or args.package is None)
and not project_name.startswith(ctx.get_current_project_path())
):
continue

Expand Down
23 changes: 15 additions & 8 deletions partcad/src/partcad/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def __init__(self, root_path=None, search_root=True):
"type": "local",
"path": self.config_path,
"maybeEmpty": True,
"isRoot": True,
},
)

Expand Down Expand Up @@ -315,13 +316,15 @@ def _get_project_recursive(self, project, import_list: list[str]):
and not project.config_obj["import"] is None
):
imports = project.config_obj["import"]
if project.name != self.name:
filtered = filter(
lambda x: "onlyInRoot" not in imports[x]
or not imports[x]["onlyInRoot"],
imports,
)
imports = list(filtered)
# TODO(clairbee): revisit if this code path is needed when the
# user explicitly asked for a particular package
# if not project.config_obj.get("isRoot", False):
# filtered = filter(
# lambda x: "onlyInRoot" not in imports[x]
# or not imports[x]["onlyInRoot"],
# imports,
# )
# imports = list(filtered)
for prj_name in imports:
pc_logging.debug(
"Checking the import: %s vs %s..."
Expand Down Expand Up @@ -397,7 +400,7 @@ async def _import_all_recursive(self, project):
and not project.config_obj["import"] is None
):
imports = project.config_obj["import"]
if project.name != self.name:
if not project.config_obj.get("isRoot", False):
filtered = filter(
lambda x: "onlyInRoot" not in imports[x]
or not imports[x]["onlyInRoot"],
Expand All @@ -414,6 +417,10 @@ async def _import_all_recursive(self, project):
next_project_path = get_child_project_path(
project.name, prj_name
)
if next_project_path == self.name:
# Avoid circular imports of the root package
# TODO(clairbee): fix circular imports in general
continue
pc_logging.debug("Importing: %s..." % next_project_path)

if "name" in prj_conf:
Expand Down
2 changes: 1 addition & 1 deletion partcad/src/partcad/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def get_child_project_names(self):
and not self.config_obj["import"] is None
):
imports = self.config_obj["import"]
if self.path != self.ctx.root_path:
if not self.config_obj.get("isRoot", False):
filtered = filter(
lambda x: "onlyInRoot" not in imports[x]
or not imports[x]["onlyInRoot"],
Expand Down
2 changes: 2 additions & 0 deletions partcad/src/partcad/project_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, config_obj={}):
else:
raise ValueError("Import configuration type is not set")
self.import_config_type = config_obj.get("type")
self.import_config_is_root = config_obj.get("isRoot", False)
self.include_paths = self.config_obj.get("includePaths", [])


Expand All @@ -50,6 +51,7 @@ def _create(self, config):
)
# Make the project config inherit some properties of the import config
self.project.config_obj["type"] = self.import_config_type
self.project.config_obj["isRoot"] = self.import_config_is_root

def _save(self):
self.ctx.projects[self.name] = self.project

0 comments on commit 31d024d

Please sign in to comment.