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

Create default execution behavior for indexer and replay while debugging #709

Open
machawk1 opened this issue Jul 24, 2020 · 3 comments
Open

Comments

@machawk1
Copy link
Member

When developing ipwb, I have been using a cycle of pip installing the source then testing. This gets tedious, repetitive, and incurs additional iterative temporal cost. It would be useful to be able to run the replay system, for example, using the Python script directly without installing it.

At one point, the replay and indexer scripts handled this via:

if __name__ == "__main__":
  do_something()

This is executed, for example, when running python -m ipwb.replay sample.cdxj. Currently, because all functionality is enclosed within functions (as appropriate), the previous command immediately exits. This would be different if the default execution (e.g., do_something() snippet) were added.

It would be worthwhile to identify how this is implemented in other projects that act as system "binaries" executed directly from the command-line.

@ibnesayeed
Copy link
Member

I think we should be able to use ipwb/__main__.py in place of ipwb from the project root after some changes in how relative imports work and making the script executable (by adding the shebang line and changing permissions). I made it work in AccessLog Parser.

@machawk1
Copy link
Member Author

@ibnesayeed Can you provide more information on what changes you anticipate for "how relative imports work"? I do not want to change too much with the logic of the code, but would like to execute the current state of the code using the python command, as I would run a conventional script.

@ibnesayeed
Copy link
Member

I am a little busy, so I cannot elaborate much on this for the next few weeks, but if you want to investigate it now, I would suggest you start a fresh Python Docker container, clone the repo there (or mount from outside) so that dependencies do not leak in or out. One problem that I faced when I was working on accesslog-parser has to do with how relative imports work (or rather not work) when running modules as scripts. For that, I have added these two lines and then I was able to execute the __main__.py script directly, using the folder, or using it as a zip file, while also being able to install via pip and use it as system-wide executable configured via setup-py.

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

2 participants