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

sedsed as a Python module #9

Closed
aureliojargas opened this issue Apr 23, 2014 · 4 comments
Closed

sedsed as a Python module #9

aureliojargas opened this issue Apr 23, 2014 · 4 comments
Milestone

Comments

@aureliojargas
Copy link
Owner

aureliojargas commented Apr 23, 2014

Besides being run from the command line, sedsed should also be importable as a Python module.

This will enable unit tests on classes/methods and the emulator could be used inside Python programs.

@jayvdb
Copy link

jayvdb commented May 14, 2019

I believe this has been done, and released on PyPI as 1.1dev0

It would be good to have a final 1.1 release, with tests included in the sdist. I was trying to build a rpm of it at https://build.opensuse.org/package/show/home:jayvdb:py-new/python-sedsed

@aureliojargas
Copy link
Owner Author

aureliojargas commented May 15, 2019

Hi @jayvdb, unfortunately, this work is still pending.

Currently sedsed works only from the command line. If you try to import it, an error is shown since it will try to execute and parse something:

>>> import sedsed
ERROR: there's no SED script to parse! (try --help)

And the worst is that a sys.exit() is triggered, aborting the interactive prompt (or caller script).

@aureliojargas
Copy link
Owner Author

@jayvdb You're right about a new version release, I'll try to get it done, #23 was opened for that. Thanks for the feedback!

aureliojargas added a commit that referenced this issue Jun 21, 2019
Before:
    >>> import sedsed
    ERROR: there's no SED script to parse! (try --help)
    # interactive prompt aborted (sys.exit())

Now:
    >>> import sedsed
    >>>

This is only a first step. The code is still not very friendly
to be used as a module.
@aureliojargas
Copy link
Owner Author

Done

aureliojargas added a commit that referenced this issue Nov 17, 2019
Previously the call to parse() was at top level, so it would be
executed when doing `import sedsed`.

Now importing sedsed works as expected: nothing gets automatically
executed. Calling code now can call `parse()` whenever needed.
@aureliojargas aureliojargas added this to the v2.0 milestone Nov 19, 2019
aureliojargas added a commit that referenced this issue Nov 22, 2019
Previous to this change, some code was being executed bare in the global
scope, unprotected by the `if __name__ == "__main__"` clause.

In this "light" refactor I tried to keep the same logic, but isolating
code into functions that set the usual global variables (they are still
there, getting rid of them is a task for the future).

All the global variables are now defined at the top, then come all the
functions, then come the `if main` clause, where the command line
parsing and sed script validation now occurs.

The new functions:

- parse_command_line()
- set_debug_commands()
- set_colors()

Now the code is more friendly to be used as a Python module, and all of
this was a necessary step to have (in following commits) an entrypoint
and create the pypi package.
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