Skip to content

Commit

Permalink
Merge pull request #97 from inab/76-wfexs-backend-init-issues
Browse files Browse the repository at this point in the history
76 wfexs backend init issues
  • Loading branch information
jmfernandez committed Jun 4, 2024
2 parents 2427712 + dca9ea5 commit 3340a88
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
4 changes: 2 additions & 2 deletions tests/pushers/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_cache_push(tmpdir) -> "None": # type: ignore[no-untyped-def]
# First, instantiate WfExS backend
temppath = tmpdir.mkdir("TEMP")

bootstrap_ok, test_local_config = WfExSBackend.bootstrap(
bootstrap_ok, test_local_config, config_directory = WfExSBackend.bootstrap(
local_config_ro={
"cacheDir": "CACHE",
"workDir": "WORKDIRS",
Expand All @@ -129,7 +129,7 @@ def test_cache_push(tmpdir) -> "None": # type: ignore[no-untyped-def]
)
wfexs = WfExSBackend(
local_config=test_local_config,
config_directory=tmpdir.strpath,
config_directory=config_directory,
)

# Second, instantiate the cache plugin
Expand Down
17 changes: 10 additions & 7 deletions wfexs_backend/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ def main() -> None:
)

if args.cacheDir:
local_config["cache-directory"] = args.cacheDir
local_config["cacheDir"] = args.cacheDir

# In any case, assuring the cache directory does exist
cacheDir = local_config.get("cacheDir")
Expand All @@ -1273,11 +1273,12 @@ def main() -> None:

# A filename is needed later, in order to initialize installation keys
if not localConfigFilename:
localConfigFilename = defaultLocalConfigFilename

# Hints for the the default path for the Crypt4GH keys
config_directory = os.path.dirname(localConfigFilename)
config_relname = os.path.basename(localConfigFilename)
config_directory = None
config_relname = os.path.basename(defaultLocalConfigFilename)
else:
# Hints for the the default path for the Crypt4GH keys
config_directory = os.path.dirname(localConfigFilename)
config_relname = os.path.basename(localConfigFilename)

# Initialize (and create config file)
if command in (
Expand All @@ -1290,9 +1291,11 @@ def main() -> None:
WfExS_Commands.Import,
WfExS_Commands.Execute,
):
updated_config, local_config = WfExSBackend.bootstrap(
updated_config, local_config, config_directory = WfExSBackend.bootstrap(
local_config, config_directory, key_prefix=config_relname
)
# This is needed because config directory could have been empty
localConfigFilename = os.path.join(config_directory, config_relname)

# Last, should config be saved back?
if updated_config or not os.path.exists(localConfigFilename):
Expand Down
33 changes: 27 additions & 6 deletions wfexs_backend/wfexs_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def bootstrap(
local_config_ro: "WfExSConfigBlock",
config_directory: "Optional[AnyPath]" = None,
key_prefix: "Optional[str]" = None,
) -> "Tuple[bool, WfExSConfigBlock]":
) -> "Tuple[bool, WfExSConfigBlock, AnyPath]":
"""
:param local_config: Relevant local configuration, like the cache directory.
:param config_directory: The filename to be used to resolve relative paths
Expand All @@ -292,11 +292,20 @@ def bootstrap(

updated = False

valErrors = config_validate(local_config_ro, cls.CONFIG_SCHEMA)
if len(valErrors) > 0:
logging.error(
f"ERROR on incoming local configuration block for bootstrap: {valErrors}"
)
sys.exit(1)

local_config = cast("WritableWfExSConfigBlock", copy.deepcopy(local_config_ro))

# Getting the config directory
if config_directory is None:
config_directory = cast("AbsPath", os.getcwd())
config_directory = cast(
"AbsPath", tempfile.mkdtemp(prefix="WfExS", suffix="config")
)
if not os.path.isabs(config_directory):
config_directory = cast("AbsPath", os.path.abspath(config_directory))

Expand Down Expand Up @@ -395,7 +404,16 @@ def bootstrap(
"Python interpreter does not support scrypt, so encoded crypt4gh keys with that algorithm cannot be used"
)

return updated, local_config
# Validate, again, as it changed
if updated:
valErrors = config_validate(local_config, cls.CONFIG_SCHEMA)
if len(valErrors) > 0:
logging.error(
f"ERROR in bootstrapped updated local configuration block: {valErrors}"
)
sys.exit(1)

return updated, local_config, config_directory

@classmethod
def FromDescription(
Expand Down Expand Up @@ -425,7 +443,7 @@ def FromDescription(
stacklevel=2,
)

_, updated_local_config = cls.bootstrap(
_, updated_local_config, config_directory = cls.bootstrap(
local_config, config_directory=config_directory
)

Expand Down Expand Up @@ -464,7 +482,8 @@ def __init__(
)

if not isinstance(local_config, dict):
local_config = {}
# Minimal bootstrapping for embedded cases
_, local_config, config_directory = self.bootstrap({}, config_directory)

# validate the local configuration object
valErrors = config_validate(local_config, self.CONFIG_SCHEMA)
Expand Down Expand Up @@ -1654,7 +1673,9 @@ def listStagedWorkflows(
creation,
orcids, # TODO: give some use to this
instanceRawWorkdir,
) = self.parseOrCreateRawWorkDir(entry.path, create_ok=False)
) = self.parseOrCreateRawWorkDir(
cast("AbsPath", entry.path), create_ok=False
)
except:
self.logger.warning(f"Skipped {entry.name} on listing")
continue
Expand Down

0 comments on commit 3340a88

Please sign in to comment.