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

Make the pip() function more usable #54

Closed
dloscutoff opened this issue Mar 19, 2022 · 1 comment
Closed

Make the pip() function more usable #54

dloscutoff opened this issue Mar 19, 2022 · 1 comment
Milestone

Comments

@dloscutoff
Copy link
Owner

In theory, running pip("code", ["arglist"]) from within Python code should work nicely; and indeed, it does work nicely from within IDLE. But in any other context (Python's built-in REPL, other Python code), the fact that the function calls sys.exit(1) when it runs into a fatal error is unexpected and a bit tricky to deal with. A better approach would be to raise a normal exception (maybe FatalError) and let the caller handle it. When running pip.py as the main program, one approach might be to catch the error in the if __name__ == "__main__" section and do sys.exit(1) there.

In a similar vein, sys.exit(0) could instead be return, which would play a lot nicer with anyone trying to call pip() from their own code.

Finally, there are some parts of the current pip() function that ought to be refactored and called something else. The argparse code could probably go in its own function, for starters; and any code that assumes we're coming from a command-line invocation probably belongs outside of pip(), which might be called from some other context.

@dloscutoff dloscutoff added this to the v1.1 milestone Mar 19, 2022
@dloscutoff dloscutoff modified the milestones: v1.1, v1.2 Jun 25, 2022
dloscutoff added a commit that referenced this issue Mar 15, 2024
- pip() now raises FatalError instead of using sys.exit(1), making it play much nicer with third-party code that calls it
- Moved main-program code into main() function
- Added run() function for running specific code
@dloscutoff
Copy link
Owner Author

Fixed the sys.exit parts. The refactoring isn't as important, so it has been moved to its own issue (#69).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant