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

#237 WIP: Add -m argument to execute pythons module #371

Closed
wants to merge 1 commit into from

Conversation

jcarizza
Copy link
Contributor

The idea behind this PR is to use the parameter -m and --module to run modules as script. For example:

echo '{"foo": "bar"}' | fades -m json.tool
{
    "foo": "bar"
}

# or

fades -m http.server                      
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

# or passing parameters

fades -m "http.server -b 127.0.0.1 9000"
Serving HTTP on 127.0.0.1 port 9000 (http://0.0.0.0:9000/) 

There is a work around as @gilgamezh said:

fades -x python -m http.server

So far, the work around has worked for me..but maybe is time to formalize it?

How this shoud be tested?

@jcarizza jcarizza requested a review from facundobatista May 27, 2019 19:12
@facundobatista
Copy link
Member

Hola Juan!

Some installed python modules/scripts can be executed "as a module", so you may do python -m foobar.

In "fades world" that would be translated to fades -d foobar -x python -m foobar (in English: create a virtualenv with foobar dependency, and inside there execute python passing "-m foobar" parameters).

We want a shortcut for that, so you may do fades -d foobar -m foobar or fades -d foobar --module foobar.

Yes, it looks a little repetitive, but the dependency should always be explicit.

At code level, I guess you could translate internally "-m foobar" to "-x python -m foobar", and that should be enough. Regarding testing this, don't know how much can be done now. We REALLY need #345 to be done.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 81.188% when pulling fcdd4be on jcarizza:master into 5e5002b on PyAr:master.

module_option = ["-m"] + args.module.split()
cmd = [python_exe] + python_options + module_option
p = subprocess.Popen(cmd)
elif child_program is None:
Copy link
Member

Choose a reason for hiding this comment

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

I think this is the wrong place to insert this new behaviour.

There's a big if down there, first part is running interactive Python shell (with interactive=True), the second is running a child program somehow. This new --module behaviour belongs to the else part of this if.

IIUC, it would have a args.executable, but you should double check it.

Thanks!

@gilgamezh
Copy link
Contributor

please rebase after we merge #387

@gilgamezh
Copy link
Contributor

@jcarizza cierro el PR por ahora. si retomas el laburo lo volvés a abrir. gracias!

@gilgamezh gilgamezh closed this May 5, 2020
@facundobatista
Copy link
Member

I'll use part of this for a future branch.

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.

4 participants