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

Modules installer #174

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

alexsiri7
Copy link
Contributor

This is a simple modules installer (can't handle multiple files, or requirements yet)

It connects to http://jaspermoduleshub.herokuapp.com/

I added a walk_packages on brain.py so that modules can be installed in subfolders.

@Holzhaus
Copy link
Member

I didn't have the time to take a closer look yet, but I already have to nag (silly me 😜 ):

Please do not use the minus sign (-) in a module name (which will make it very hard to import). According to PEP 8 there may be an underscore (_), but IMHO we should try to avoid that, too.

I'd suggest...uhmmm..... modinstaller.py (?)

@alexsiri7
Copy link
Contributor Author

Ok, I changed the name to the module.

@alexsiri7
Copy link
Contributor Author

@Holzhaus @crm416 @shbhrsaha were you able to take a look at this? What do you think?

@alexsiri7
Copy link
Contributor Author

attention

@Holzhaus
Copy link
Member

IMHO we can add sth like this to Jasper, but we can also wait for v2. Depending in what @crm416 and @shbhrsaha say, we can either start testing for v1 or we change the code to play nice with v2's Plugin system and postpone merging.

@@ -43,10 +43,10 @@ def get_modules(cls):
"""

module_locations = [jasperpath.PLUGIN_PATH]
module_names = [name for loader, name, ispkg in pkgutil.iter_modules(module_locations)]
module_names = [name for loader, name, ispkg in pkgutil.walk_packages(module_locations, prefix='modules.')]
Copy link
Member

Choose a reason for hiding this comment

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

This should be part of a separate PR and can be merged regardless of the plugin installer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it could. But it was necessary for this one.

Copy link
Member

Choose a reason for hiding this comment

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

Just make a new PR containing just the changes to brain.py and I'll merge it today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@alexsiri7
Copy link
Contributor Author

I think when v2 comes out, with it's plugin system, the module site will still be pretty much the same (downloading the code from a location, and setting it up in a directory). So the plugin installing would remain the same, the only change would be the code inside of those plugins

@Holzhaus
Copy link
Member

Yes, but the site would contain a lot of v2 incompatible plugins.

print "Installed module: %s" % self.module

def create_module_folder(self):
self.module_path = os.path.abspath('modules/'+self.module)
Copy link
Member

Choose a reason for hiding this comment

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

You should use jasperpath.PLUGIN_PATH. This won't work it's executed from outside the client folder, e.g:

cd /
/home/pi/jasper/client/modinstaller.py --install foo

In this case, it will try to create /modules/foo (in the root fs).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

os.makedirs(self.module_path)
open(os.path.join(self.module_path, '__init__.py'), 'a').close()

def get_module_metadata(self):
Copy link
Member

Choose a reason for hiding this comment

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

This method name is very misleading. It does not return metadata but checks if a plugin of this name existis in the remote repository. Therefore it should be renamed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I made then two methods, one to get the metadata and another to check if the metadata exists.

@alexsiri7 alexsiri7 force-pushed the installer branch 3 times, most recently from 60cfedf to 9d43499 Compare September 25, 2014 05:57
@charliermarsh
Copy link

Will do my best to read through this today... Sorry for the delay.

@charliermarsh
Copy link

Don't have a ton of comments on the actual code, but I'd be fine with merging this in the near future. Seems reasonably useful. However, it's going to need some documentation. For example, it wasn't clear to me that you have to the Git route if your module has dependencies (i.e., because you need to include a folder with a requirements.txt... right?).

Additionally, why do you need to give the site full access to your GitHub "personal user data"?


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Jasper modules installer')
parser.add_argument('--install', nargs=1,

Choose a reason for hiding this comment

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

Why is nargs=1 if we give the Modules to install description? Shouldn't it be nargs='+'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@alexsiri7
Copy link
Contributor Author

I took some ideas from the code you wrote, and examples for the comments you added to the PR.

self.module = module

def __str__(self):
return self.message + ": " + self.module
Copy link
Member

Choose a reason for hiding this comment

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

Please use one of these syntaxes:

"%s: %s" % (self.message, self.module)
# or
"{message}: {module}".format(message=self.message, module=self.module)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@Holzhaus
Copy link
Member

Holzhaus commented Oct 2, 2014

Nice.

PS: I hope I didn't appear rough or something, but in case, I just wanted to say: Sorry, I didn't mean it. Text-only communication can be a bit ambiguous sometimes.

@alexsiri7
Copy link
Contributor Author

@Holzhaus No worries. I know it's hard to communicate things using text-only, and I suppose the same counts for me (so, sorry if I offended/annoyed you in any way). Anyways, thanks for that message.

@alexsiri7
Copy link
Contributor Author

@Holzhaus do you think this is ready to be merged?

finally:
shutil.rmtree(temp_path)
else:
raise ModuleInstallationError("Module not found", module)
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather do something like:

raise ModuleInstallationError("Module '%s' not found" % module)

and then replace the custom ModuleInstallationError with this:

class ModuleInstallationError(Exception):
    pass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But this way, you'll have to interpolate the name of the module everywhere, and there is no requirement of a module name when instantiating the class. Wouldn't you think that, as the Error pertains a module, that the module is part of the parameters of the object being instantiated?

Copy link
Member

Choose a reason for hiding this comment

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

Well, You know the module name anyway, because you call the install() function with this argument. And IMHO, the module name should be part of it's message.
Also, the current implementation overrides the __init__() method, but does not call the superclass' __init__(), which should not happen.

@Holzhaus
Copy link
Member

Holzhaus commented Oct 6, 2014

Sorry, some more comments, but hopefully can merge soon.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling da72882 on alexsiri7:installer into * on jasperproject:master*.

@korniza
Copy link

korniza commented Jan 16, 2016

I get the following error if I use AT&T STT. I have already copied the APP_KEY, Secret_key from site (Basic free access).

INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.att.com
DEBUG:requests.packages.urllib3.connectionpool:"POST /oauth/v4/token HTTP/1.1" 400 None
ERROR:jasper.mic:Transcription failed!
Traceback (most recent call last):
File "/root/jasper/jasper/mic.py", line 117, in check_for_keyword
transcribed = self.passive_stt_engine.transcribe(f)
File "/root/jasper/plugins/stt/att-stt/att.py", line 57, in transcribe
r = self._get_response(data)
File "/root/jasper/plugins/stt/att-stt/att.py", line 97, in _get_response
headers = {'Authorization': 'Bearer %s' % self.token,
File "/root/jasper/plugins/stt/att-stt/att.py", line 52, in token
self._token = r.json()['access_token']
KeyError: 'access_token'

Do I need to upgrade to premium account so to get STT access or there is something wrong with code/keys?

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

Successfully merging this pull request may close these issues.

5 participants