How would someone put multiline "script" in switch? #138
-
Right now, I have this nasty expression: control.expr = """
pathlib.Path(".venv/bin/npm").is_file() and set(
pathlib.Path("node-requirements.txt").read_text().split("\\n")[0:-1]).intersection(set(
re.findall(r"[a-z-]+@(?:[0-9]+\\.?)+", subprocess.run(["npm", "ls", "-g"], capture_output = True) \
.stdout.decode("utf-8")
))
)
"""
control.imports = ["re", "subprocess", "pathlib"] Is it possible to write multi statement "script" (something using variables, exception handling, etc)? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The point of the expr task is to streamline the use-case where you want to evaluate a single python expression. For the most powerful option would be to use a script task to call a python function defined somewhere in your project (I usually put stuff in src/tasks.py, which doesn't have to be included in the build). In general you can define a shell with |
Beta Was this translation helpful? Give feedback.
Accessing arguments as python variables only works for
script
orexpr
tasks, but shell tasks using python as an interpreter aren't as clever because they work by passing a whole script to the python interpreter, rather than composing one dynamically from the given components.For shell tasks you can access the arg value as an environment variable like so:
Notice I avoided calling the variable
path
…