Skip to content

Commit

Permalink
Fix broken part initialization as a result of changes the config file…
Browse files Browse the repository at this point in the history
… path initialiation
  • Loading branch information
openvmp committed Jan 3, 2024
1 parent 78abad6 commit 552c78d
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/partcad/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def __init__(self, config_path="."):
spinner=spinner,
)
if not spinner is None:
spinner.finish()
logging.info("PartCAD: Finished loading dependencies.")

atexit.register(Context._finalize_real, self)
Expand Down
13 changes: 8 additions & 5 deletions src/partcad/part_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ def __init__(self, ctx, project, part_config, extension=""):
self.path = self.name + extension
if "path" in part_config:
self.path = part_config["path"]
if not os.path.isdir(project.path):
raise Exception("ERROR: The project path must be a directory")
self.path = os.path.join(project.path, self.path)
if not os.path.exists(self.path):
raise Exception("ERROR: The part path must exist")
if not os.path.isdir(project.config_dir):
raise Exception(
"ERROR: The project config directory must be a directory, found: '%s'"
% project.config_dir
)
self.path = os.path.join(project.config_dir, self.path)
if not os.path.isfile(self.path):
raise Exception("ERROR: The part path (%s) must be a file" % self.path)

# Pass the autodetected path to the 'Part' class
part_config["path"] = self.path
Expand Down
2 changes: 1 addition & 1 deletion src/partcad/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, ctx, path):
# 'self.path' has to be set to the directory name.
dir_name = path
if not os.path.isdir(dir_name):
dir_name = os.path.dirname(dir_name)
dir_name = os.path.dirname(os.path.abspath(dir_name))
self.path = dir_name

# self.part_configs contains the configs of all the parts in this project
Expand Down
26 changes: 14 additions & 12 deletions src/partcad/project_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@
class Configuration:
def __init__(self, config_path=DEFAULT_CONFIG_FILENAME):
self.config_obj = {}
self.config_dir = ""
self.config_path = ""
self.config_dir = config_path
self.config_path = config_path

if os.path.isdir(config_path):
config_path += "/" + DEFAULT_CONFIG_FILENAME
if not os.path.isfile(config_path):
logging.error("PartCAD configuration file is not found: %s" % config_path)
return
self.config_path = config_path
self.config_path = os.path.join(config_path, DEFAULT_CONFIG_FILENAME)
else:
self.config_dir = os.path.dirname(os.path.abspath(config_path))

self.config_dir = os.path.dirname(config_path)
if not os.path.isfile(self.config_path):
logging.error(
"PartCAD configuration file is not found: '%s'" % self.config_path
)
return

if config_path.endswith(".yaml"):
self.config_obj = yaml.safe_load(open(config_path, "r"))
if config_path.endswith(".json"):
self.config_obj = json.load(open(config_path, "r"))
if self.config_path.endswith(".yaml"):
self.config_obj = yaml.safe_load(open(self.config_path, "r"))
if self.config_path.endswith(".json"):
self.config_obj = json.load(open(self.config_path, "r"))

# option: "partcad"
# description: the version of PartCAD required to handle this package
Expand Down
10 changes: 4 additions & 6 deletions src/partcad/project_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# Licensed under Apache License, Version 2.0.
#

import os

from . import project as p


Expand All @@ -27,16 +29,12 @@ def __init__(self, ctx, parent, import_config_obj, name):
self.import_config_name = name

if parent is None:
self.config_path = ctx.config_path
self.config_dir = ctx.config_dir
else:
self.config_path = parent.config_path
self.config_dir = parent.config_dir

# TODO(clairbee): Make project cache path a function of the project
# config not just its name
self.cache_path = (
self.config_dir + "/.partcad/projects/" + self.import_config_name
)

# TODO(clairbee): Initialize the config object if necessary

def _create(self, config):
Expand Down
3 changes: 1 addition & 2 deletions src/partcad/project_factory_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ def __init__(self, ctx, parent, config, name=None):
pf.ProjectFactory.__init__(self, ctx, parent, config, name)
GitImportConfiguration.__init__(self)

self.cache_path = self._clone_or_update_repo(self.import_config_url)
self.path = self._clone_or_update_repo(self.import_config_url)

# Complement the config object here if necessary
self.path = self.cache_path
self._create(config)

# TODO(clairbee): actually fill in the self.project object here
Expand Down
5 changes: 2 additions & 3 deletions src/partcad/project_factory_tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ def __init__(self, ctx, parent, config, name=None):
pf.ProjectFactory.__init__(self, ctx, parent, config, name)
TarImportConfiguration.__init__(self)

# TODO(clairbee): Clone self.import_config_url to self.cache_path
self.cache_path = self._extract(self.import_config_url)
# TODO(clairbee): Clone self.import_config_url to self.path
self.path = self._extract(self.import_config_url)

# Complement the config object here if necessary
self.path = self.cache_path
self._create(config)

# TODO(clairbee): actually fill in the self.project object here
Expand Down

0 comments on commit 552c78d

Please sign in to comment.