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

Add Python Script task #7242

Merged
merged 24 commits into from
May 18, 2018
Merged

Add Python Script task #7242

merged 24 commits into from
May 18, 2018

Conversation

brcrista
Copy link
Contributor

image

image

Testing

  • Manually in designer and YAML

@@ -0,0 +1,71 @@
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unused

"label": "Arguments",
"required": false,
"defaultValue": "",
"helpMarkDown": "Arguments passed to the script execution, available through `sys.argv`."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Bash task only lets you pass arguments when you're running a script from a file. I don't see any reason for that restriction (in Python at least), so this task lets you pass arguments to inline scripts as well.

} else { // Run inline script
// Print one-line scripts
const script = parameters.script!; // Required if `targetType` is 'script'
if (!(script.includes('\n') || script.toLowerCase().includes('##vso['))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I carried over the one-line restriction from the Bash task, but I don't see any reason for it -- the length of the script is set in the task.json anyway. So I'm just going to log the whole inline script.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, the script gets logged when you run with system.debug, so I think I'll just remove this.

{
"name": "filePath",
"type": "filePath",
"label": "Script Path",
Copy link
Contributor

Choose a reason for hiding this comment

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

Sentence-cased as "Script path"

],
"inputs": [
{
"name": "targetType",
Copy link
Contributor

Choose a reason for hiding this comment

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

In YAML, targetType might be more intuitive if named scriptSource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but this is consistent with the other script tasks.

"label": "Python interpreter",
"defaultValue": "",
"required": false,
"helpMarkDown": "Absolute path to the Python interpreter to use. If not specified, the task will use the interpreter in PATH.",
Copy link
Contributor

Choose a reason for hiding this comment

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

You could append:
"The Use Python Version task can be used to set the version of Python in PATH."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about I add this as a "tip" in the docs page? That will keep the help text here brief.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like David's suggestion. Many users don't look at docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Contributor Author

@brcrista brcrista May 18, 2018

Choose a reason for hiding this comment

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

image

"label": "Fail on standard error",
"defaultValue": "false",
"required": false,
"helpMarkDown": "If this is true, this task will fail if any text are written to the stderr stream.",
Copy link
Contributor

Choose a reason for hiding this comment

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

is written to...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"any texts are written to"

}
},
{
"name": "filePath",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rename this input from "filePath" to "scriptPath" so that the designer and YAML views match?

{
"name": "targetType",
"type": "radio",
"label": "Type",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make this label "Type" match the "name" field?

"label": "Script",
"visibleRule": "targetType = inline",
"required": true,
"defaultValue": "",
Copy link
Contributor

Choose a reason for hiding this comment

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

You could set the default inline script to the following so that it succeeds faster without modification:

# Write your Python script here.\n\n# Add variables marked secret on the Variables tab to pass secret variables to this script.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Synced offline, won't fix for now. We'll hold off on doing secret variables for this task.

"visibleRule": "targetType = inline",
"required": true,
"defaultValue": "",
"properties": {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't suppose that by some miracle there might be a 'show whitespace' property on this, is there? (probably not...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not that I know of ...

const scriptPath = await (async () => {
if (parameters.targetType.toLowerCase() === 'filepath') { // Run script file
// Required if `targetType` is 'filepath':
const filePath = parameters.filePath!;
Copy link
Contributor

Choose a reason for hiding this comment

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

As I understand it, the trailing bang doesn't actually perform a null check. I think it would be an improvement to have an error message that states 'filePath is required'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right -- it's just a compile-time assertion. I can change it to a runtime check.

return filePath;
} else { // Run inline script
// Required if `targetType` is 'script':
const script = parameters.script!;
Copy link
Contributor

Choose a reason for hiding this comment

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

parameters.script! => Same as above.

@lkillgore
Copy link
Contributor

It's looking pretty good. Any tests?

@brcrista
Copy link
Contributor Author

brcrista commented May 17, 2018

None of the other script-runner tasks have tests -- which admittedly is a bad reason not to add tests here. From manual testing I'm pretty confident with it. Since it's the end of sprint, I'd like to go ahead with this commit and add the tests in a separate change.

@brcrista brcrista merged commit 938e2a1 into master May 18, 2018
brcrista added a commit that referenced this pull request May 18, 2018
@brcrista brcrista deleted the users/brcrista/python-script branch May 29, 2018 18:49
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.

4 participants