Repository: codespell-project/codespell

Issue:
Exit status is always 0 when started as a Python module
When started as `python -m codespell_lib` codespell always exits with 0.

Is it intentional?



Discussion:
I install it in my user's home `pip install --user` and don't want to `"$(python -m site --user-base)/bin/codespell"`
Indeed:
```
$ codespell -I non_existent_file
ERROR: cannot find ignore-words file: non_existent_file
[...]
$ echo $?
0
$ 
$ python -m codespell_lib -I non_existent_file
ERROR: cannot find ignore-words file: non_existent_file
[...]
$ echo $?
64
$ 
```
But the way, isn't `$(python -m site --user-base)/bin` in the `PATH` by default on most Linux distributions?
> But the way, isn't `$(python -m site --user-base)/bin` in the `PATH` by default on most Linux distributions?

Could be ...
But I like my computer to be extra simple.

The codespell executable `$(python -m site --user-base)/bin/codespell` looks like this:
```python
from codespell_lib import _script_main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(_script_main())
```
File `codespell_lib/__main__.py` looks like this:
```python
from ._codespell import _script_main

if __name__ == "__main__":
    _script_main()
```
Does changing the last line help?
```python
if __name__ == "__main__":
    sys.exit(_script_main())
```

Yes.
Also, do you know if that's right thing to do? I cannot find definitive information in the relevant documentation, although some examples do call `sys.exit()`:
* https://docs.python.org/3/library/__main__.html#main-py-in-python-packages
🤔 
The only thing I can think of is: when codespell is used as a library it should not exit (terminate)
My wrong, it **is** (partially at least) documented:
> `main` functions are often used to create command-line tools by specifying them as entry points for console scripts. When this is done, [pip](https://pip.pypa.io/) inserts the function call into a template script, where the return value of `main` is passed into [`sys.exit()`](https://docs.python.org/3/library/sys.html#sys.exit). For example:
> ```python
>  sys.exit(main())
> ```
> Since the call to `main` is wrapped in [`sys.exit()`](https://docs.python.org/3/library/sys.html#sys.exit), the expectation is that your function will return some value acceptable as an input to [`sys.exit()`](https://docs.python.org/3/library/sys.html#sys.exit); typically, an integer or `None` (which is implicitly returned if your function does not have a return statement).

It's just that the above refers to the template script `$(python -m site --user-base)/bin/codespell` as far as I can tell, not to `python -m`. Also, I would have expected different wording such as "you MUST".

Can you please create a pull request that adds `sys.exit()`? I should be able to merge it rapidly - unlike my own pull requests.

Resolving patch:
diff --git a/codespell_lib/__main__.py b/codespell_lib/__main__.py
--- a/codespell_lib/__main__.py
+++ b/codespell_lib/__main__.py
@@ -1,4 +1,6 @@
+import sys
+
 from ._codespell import _script_main
 
 if __name__ == "__main__":
-    _script_main()
+    sys.exit(_script_main())


Test patch: