Skip to content
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

Merged
merged 3 commits into from May 1, 2018
Merged

Replace sys.exit calls with exceptions #318

merged 3 commits into from May 1, 2018

Conversation

andresdelfino
Copy link
Contributor

Pass exceptions to the main module instead of sys.exiting.

@coveralls
Copy link

coveralls commented Apr 30, 2018

Coverage Status

Coverage increased (+0.03%) to 75.0% when pulling c2223d1 on andresdelfino:sysexit-fixes into 6552e04 on PyAr:master.

Copy link
Member

@facundobatista facundobatista left a 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!

class FadesError(Exception):
"""Provides a Fades exception."""

def __init__(self, reason):
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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:
Copy link
Member

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.")
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use FadesError

Copy link
Member

@facundobatista facundobatista left a 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
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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)

@facundobatista
Copy link
Member

Awesome! Thank you very much!

@facundobatista facundobatista merged commit dd2d033 into PyAr:master May 1, 2018
@andresdelfino andresdelfino deleted the sysexit-fixes branch May 1, 2018 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants