Skip to content

Commit

Permalink
Merge #232
Browse files Browse the repository at this point in the history
232: run: Deal with lists being put in the configuration file r=duckinator a=nbraud

I just noticed that Bork will accept lists, in command definitions, and pass them to `subprocess.run`, which seems to silently discard all but the first element.

It seemed sensible to interpret it instead as a list of commands to execute sequentially; doing it in parallel could be cute, but also rather silly  >_>'

If this seems like a bad idea, please make sure that lists are rejected instead.
The current situation is just very confusing.  :3

Co-authored-by: nicoo <nicoo@mur.at>
  • Loading branch information
bors[bot] and nbraud authored Dec 28, 2020
2 parents 7acc362 + 6d1f786 commit d44f46c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ if you put this in pyproject.toml:
```toml
[tool.bork.aliases]
# Runs *only* pylint. (Not the actual tests.)
lint = "pytest -k 'pylint' --pylint --verbose"
lint = [
# Runs *only* pylint. (Not the actual tests.)
"pytest -k 'pylint' --pylint --verbose",
# Typecheck the project
"mypy .",
]
# Runs tests and pylint.
test = "pytest --pylint --verbose"
test-only = "pytest --verbose"
Expand Down
15 changes: 12 additions & 3 deletions bork/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,23 @@ def run(alias):
pyproject = toml.load('pyproject.toml')

try:
command = pyproject['tool']['bork']['aliases'][alias]
commands = pyproject['tool']['bork']['aliases'][alias]
except KeyError as error:
raise RuntimeError("No such alias: '{}'".format(alias)) from error

logger().info("Running '%s'", command)
logger().info("Running '%s'", commands)

if isinstance(commands, str):
commands = [commands]
elif isinstance(commands, list):
pass
else:
raise TypeError(f"commands must be str or list, was {type(commands)}")

try:
subprocess.run(command, check=True, shell=True)
for command in commands:
print(command)
subprocess.run(command, check=True, shell=True)

except subprocess.CalledProcessError as error:
if error.returncode < 0:
Expand Down

0 comments on commit d44f46c

Please sign in to comment.