AnswerDotAI / AnswerDotAI/nbdev

Commands in the `release` module always return exit code 0, even if they fail

Open
#1,358 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Jupyter Notebook
Stars
5.3k
Forks
513
Avg merge
2d 30m
Merged PRs (30d)
8

Description

Hi,
When executing commands such as `nbdev_pypi` from a shell (which get routed to `nbdev.release:release_pypi`), the commands always return exit code 0 regardless of the errors happening inside the command.

I ran into this issue while using `nbdev_pypi` inside my CI/CD. If I forget to bump the version, for example, the `twine upload` command will fail with a "409 Conflict" error, but the `nbdev_pypi` command still returns error code 0 (success).
This is problematic, because there is no way to catch this error and do something useful (like fail the CI/CD build).

The code for `release_pypi` uses os.system calls like:
```python
system(f'twine upload --repository {repository} {_dir}/dist/*')
```
https://github.com/fastai/nbdev/blob/4af4d479c78880f4a18af4254b119f8af8b3a8a4/nbdev/release.py#L307-L313C68

As far as I can see, the call to `os.system()` returns the exit code as a 0/1 but does not throw an exception.

I'm happy to contribute a pull request to fix this, but would like some guidance on what is the right way to go about it.
Options I see:
1. Change code to use subprocess instead of os.system()
2. Keep using os.system, but instead of calling it directly - add a wrapping function like execute_throw_on_error() which will check the response code and throw exception if it's not 0.
3. Somehow handle it in a more generic way in the the call_parse decorator (but what do we do if there are multiple calls to os.system and we want to fail if either fails?)

Thanks!

Julian.

Contributor guide

Open the contributing guide

Research direction

Start in nbdev/release.py around release_pypi and its os.system call for `twine upload`. Inspect the other release commands for the same exit-status handling, then reproduce a failed upload such as the reported 409 Conflict. Done means a failing command propagates a nonzero exit code so CI/CD can detect the failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ci-cd, release
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.