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
Replace sys.exit calls with exceptions #318
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!!! Thank you!!! I added some comments and requests, thanks!
fades/envbuilder.py
Outdated
class FadesError(Exception): | ||
"""Provides a Fades exception.""" | ||
|
||
def __init__(self, reason): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not really needed, as Exceptions already receive and store a message
, so just define FadesError, with the docstring, and that's all.
That said, it's better to define this exception in a more general place... put it in fades/__init__.py
and import it from there...
fades/helpers.py
Outdated
@@ -135,7 +135,7 @@ def _get_interpreter_info(interpreter=None): | |||
requested_interpreter_info = logged_exec(args) | |||
except Exception as error: | |||
logger.error("Error getting requested interpreter version: %s", error) | |||
sys.exit(1) | |||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use FadesError, as above (it's a good idea!!!)
fades/helpers.py
Outdated
@@ -250,7 +250,7 @@ def check_pypi_exists(dependencies): | |||
exists = _pypi_head_package(dependency) | |||
except Exception as error: | |||
logger.error("Error checking %s in PyPI: %r", dependency, error) | |||
sys.exit(1) | |||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use FadesError...
fades/main.py
Outdated
@@ -166,7 +166,7 @@ def go(): | |||
getattr(sys, 'base_prefix', None)): | |||
logger.error( | |||
"fades is running from inside a virtualenv (%r), which is not supported", sys.prefix) | |||
sys.exit(-1) | |||
raise Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use FadesError, as above
fades/main.py
Outdated
except Exception: | ||
rc = 1 | ||
logger.debug("CLEAN_UNUSED_VENVS must be an integer.") | ||
except Exception.ValueError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is invalid, just use ValueError
fades/main.py
Outdated
rc = 1 | ||
logger.debug("CLEAN_UNUSED_VENVS must be an integer.") | ||
except Exception.ValueError: | ||
logger.debug("clean_unused_venvs must be an integer.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log in ERROR here, not DEBUG
fades/main.py
Outdated
@@ -262,7 +260,7 @@ def go(): | |||
"You can use '--no-precheck-availability' to avoid it.") | |||
if not helpers.check_pypi_exists(indicated_deps): | |||
logger.error("An indicated dependency doesn't exists. Exiting") | |||
sys.exit(1) | |||
raise Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use FadesError
fades/main.py
Outdated
@@ -304,7 +302,7 @@ def go(): | |||
p = subprocess.Popen(cmd + args.child_options) | |||
except FileNotFoundError: | |||
logger.error("Command not found: %s", args.child_program) | |||
sys.exit(1) | |||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use FadesError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of more issues...
fades/main.py
Outdated
rc = 1 | ||
logger.debug("CLEAN_UNUSED_VENVS must be an integer.") | ||
except ValueError: | ||
logger.error("clean_unused_venvs must be an integer.") | ||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise FadesError
fades/main.py
Outdated
finally: | ||
sys.exit(rc) | ||
|
||
usage_manager.clean_unused_venvs(max_days_to_keep) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this operation, fades must quit (this was handled in the finally
you removed)
testdev.bat
Outdated
@@ -0,0 +1,11 @@ | |||
@echo off | |||
|
|||
rem Copyright 2014-2016 Facundo Batista, Nicolás Demarchi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2018 is enough here (this file is new)
Awesome! Thank you very much! |
Pass exceptions to the main module instead of sys.exiting.