Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix parsing FROM: /filepath #2017

Merged
merged 2 commits into from
Nov 9, 2023
Merged

🐛 Fix parsing FROM: /filepath #2017

merged 2 commits into from
Nov 9, 2023

Conversation

shnizzedy
Copy link
Member

Fixes

Fixes FileNotFoundError: [Errno 2] No such file or directory: '/code/CPAC/resources/configs/pipeline_config_/configs/pipeline_config_cpac_1.8.5_fromPhoebeNoDeriviativesNative.yml.yml' by @Shinwon Park

Technical details

Consolidates

C-PAC/CPAC/utils/utils.py

Lines 1518 to 1542 in ecfc583

def load_preconfig(pipeline_label):
import os
import pkg_resources as p
if pipeline_label not in ALL_PIPELINE_CONFIGS:
raise BadParameter(
"The pre-configured pipeline name '{0}' you provided is not one "
"of the available pipelines.\n\nAvailable pipelines:\n"
"{1}\n".format(pipeline_label, str(AVAILABLE_PIPELINE_CONFIGS)),
param='preconfig')
pipeline_file = \
p.resource_filename(
"CPAC",
os.path.join(
"resources",
"configs",
"pipeline_config_{0}.yml".format(pipeline_label)
)
)
print(f"Loading the '{pipeline_label}' pre-configured pipeline.",
file=sys.stderr)
return pipeline_file
and
def preconfig_yaml(preconfig_name='default', load=False):
"""Get the path to a preconfigured pipeline's YAML file
Parameters
----------
preconfig_name : str
load : boolean
return dict if True, str if False
Returns
-------
str or dict
path to YAML file or dict loaded from YAML
"""
if load:
with open(preconfig_yaml(preconfig_name), 'r', encoding='utf-8') as _f:
return yaml.safe_load(_f)
return p.resource_filename("CPAC", os.path.join(
"resources", "configs", f"pipeline_config_{preconfig_name}.yml"))
into
def preconfig_yaml(preconfig_name='default', load=False):
"""Get the path to a preconfigured pipeline's YAML file.
Raises BadParameter if an invalid preconfig name is given.
Parameters
----------
preconfig_name : str
load : boolean
return dict if True, str if False
Returns
-------
str or dict
path to YAML file or dict loaded from YAML
"""
from CPAC.pipeline import ALL_PIPELINE_CONFIGS, AVAILABLE_PIPELINE_CONFIGS
if preconfig_name not in ALL_PIPELINE_CONFIGS:
raise BadParameter(
"The pre-configured pipeline name '{0}' you provided is not one "
"of the available pipelines.\n\nAvailable pipelines:\n"
f"{1}\n".format(preconfig_name, str(AVAILABLE_PIPELINE_CONFIGS)),
param='preconfig')
if load:
with open(preconfig_yaml(preconfig_name), 'r', encoding='utf-8') as _f:
return yaml.safe_load(_f)
return p.resource_filename("CPAC", os.path.join(
"resources", "configs", f"pipeline_config_{preconfig_name}.yml"))
so preconfiguration loading is handled consistently everywhere and updates the relevant function calls.

Tests

# A loaded YAML file to test https://tinyurl.com/cmicnlslack420349
SLACK_420349 = {
"filepath": yaml.dump({
"FROM": str(_TEST_CONFIGS_PATH / "neurostars_23786.yml"),
"pipeline_setup": {"pipeline_name": "slack_420349_filepath"}}),
"preconfig": yaml.dump({"FROM": "preproc",
"pipeline_setup": {"pipeline_name": "slack_420349_preconfig"}})}

>>> from CPAC.utils.tests.configs import SLACK_420349
# test "FROM: /path/to/file"
>>> slack_420349_filepath = Configuration(
... yaml.safe_load(SLACK_420349['filepath']))
>>> slack_420349_filepath['pipeline_setup', 'pipeline_name']
'slack_420349_filepath'
# test "FROM: preconfig"
>>> slack_420349_preconfig = Configuration(
... yaml.safe_load(SLACK_420349['preconfig']))
>>> slack_420349_preconfig['pipeline_setup', 'pipeline_name']
'slack_420349_preconfig'

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I updated the changelog.
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@shnizzedy
Copy link
Member Author

The ACCESS deployments are "failure"s because I rejected them ― these changes shouldn't affect anything that those would cover

@sgiavasis sgiavasis merged commit 4b35e6c into develop Nov 9, 2023
65 of 67 checks passed
@shnizzedy shnizzedy deleted the fix/FROM_filepath branch November 9, 2023 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants