Skip to content

Generate nameroot and nameext from basename - #420

Merged
tetron merged 7 commits into
common-workflow-language:masterfrom
undu:basename-fields
Jun 12, 2017
Merged

tetron merged 7 commits into
common-workflow-language:masterfrom
undu:basename-fields

Conversation

@undu

@undu undu commented Jun 9, 2017

Copy link
Copy Markdown
Contributor

Here's the cleaner PR to fix #268
Obsoletes #338

kapilkd13 and others added 3 commits June 9, 2017 18:34
Additionally only generate it for Files, not Directories
(following specification). And also generate nameext.
@cwl-bot

cwl-bot commented Jun 9, 2017

Copy link
Copy Markdown

Can one of the admins verify this patch?

@undu

undu commented Jun 10, 2017 •

Copy link
Copy Markdown
Contributor Author

I'm unsure on what the behaviour should be when only nameroot or nameext is missing, not both.

Should it generate the value from basename disregarding the other one; should it try to play nice with the existing value of the other one; should it overwite the existing value because the algorithm knows what's the 'correct' value for both fields?

@undu

undu commented Jun 10, 2017

Copy link
Copy Markdown
Contributor Author

For clarification, right now the code (over)writes both from the calculated values to ensure that there are no inconsistencies between both.

@tetron

tetron commented Jun 12, 2017

Copy link
Copy Markdown
Member

@undu yes, that's correct, the nameroot and nameext fields are supposed to be generated from basename, no the other way.

Comment thread cwltool/pathmapper.py Outdated
d["basename"] = os.path.basename(urllib.request.url2pathname(path))

if d["class"] == "File":
if "nameroot" or "nameext" not in d:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace this with the line from draft2tool.py:

f["nameroot"], f["nameext"] = os.path.splitext(f["basename"])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know there was a function that did it out of the box, it's changed now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove the conditional. As mentioned earlier we can set nameroot and nameext unconditionally.

FYI that construction doesn't do what you want:

if "x" or "y" in "abc":
  print "yes"

This will always print "yes" because the expression is actually bool("x") or bool("y" in "abc") and non-empty strings are True.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip, I removed the condition.

Comment thread tests/test_examples.py Outdated
"basename": "bar.cwl",
"nameroot": "bar",
"class": "File",
"nameext": "cwl",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the spec:

The basename root such that nameroot + nameext == basename, and nameext is empty or begins with a period and contains at most one period. For the purposess of path splitting leading periods on the basename are ignored; a basename of .cshrc will have a nameroot of .cshrc.

So nameext in this example should be .cwl

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the tests have been changed to conform to os.path.splitext.

Comment thread cwltool/pathmapper.py Outdated
d["basename"] = os.path.basename(urllib.request.url2pathname(path))

if d["class"] == "File":
if "nameroot" or "nameext" not in d:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove the conditional. As mentioned earlier we can set nameroot and nameext unconditionally.

FYI that construction doesn't do what you want:

if "x" or "y" in "abc":
  print "yes"

This will always print "yes" because the expression is actually bool("x") or bool("y" in "abc") and non-empty strings are True.

@tetron

tetron commented Jun 12, 2017

Copy link
Copy Markdown
Member

Jenkins, test this please

@tetron
tetron merged commit a4793fe into common-workflow-language:master Jun 12, 2017
@undu
undu deleted the basename-fields branch June 12, 2017 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nameroot field is not generated for File in input

4 participants