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

Corrected project to conform to PEP8 style. Passed pep8, py27, cover … #15

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ nosetests.xml
coverage.xml
*,cover
.hypothesis/
.testrepository/
cover/

# Translations
*.mo
Expand Down Expand Up @@ -87,3 +89,6 @@ ENV/

# Rope project settings
.ropeproject

#vim swap files
.swp
49 changes: 44 additions & 5 deletions pybluedot/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
"""
cli.py constructs a cli interface of commands, options, and subcommands in argparse, given data structures from commands.py
"""
import argparse
import json
from pybluedot.commands import cmd, subcmd
from pybluedot.commands import cmd_arg
from pybluedot.commands import sub_cmd

# Licensed under the Apache License, Version 2.0 (the "License");
Copy link
Contributor

Choose a reason for hiding this comment

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

For all files, could you move this licensing statement above the imports? Should be the first thing at the top so you don't have to jump over this to see your imports.

# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


def cmd_to_args(cmd_arg):
"""creates argparse arguments from commands.cmd dict.
return argparse object.
"""
all_args = argparse.ArgumentParser()
for arg in cmd_arg:
for i in sorted(arg.keys()):
# TODO(gamefiend)
pass
return all_args


def cmd_to_subs(sub_cmd):
"""creates subcommand arguments from commands.subcmd dict.
returns argparse object.
"""
all_subs = argparse.ArgumentParser()
for sub in sub_cmd:
for i in sorted(sub):
# TODO(gamefiend)
pass
return all_subs


if __name__ == "__main__":
Copy link
Contributor

Choose a reason for hiding this comment

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

See https://github.com/commitmas/pybluedot/blob/master/setup.cfg#L24 and study up on the setuptools configuration. In short, none of the Python files we develop will be called directly - that role will be fulfilled by a console script ("binary") generated by setuptools. What you should do is create a "main()" function here so that the current setuptools configuration knows what to grab.

Then, running this is simple:

sudo python setup.py install
bdot patents

bdot_args = cmd_to_args(cmd_arg)
bdot_subcmds = cmd_to_subs(sub_cmd)
bdot_args.parse()
bdot_subcmds.parse()
74 changes: 36 additions & 38 deletions pybluedot/commands.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
""" commands.py contains the data structures that cli.py uses to construct the arguments/subcommand structure.
"""
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# global arguments and flags to the command, like '--verbose' or '--debug'
cmd_arg = [
{
name: "verbose",
action: "store_const"
},
{
name: "debug",
action: "store_const"
}
]

# subcommands used by the program, like 'bdot init' or 'bdot search'.
# Subcommands are tied to functions, so you must specify a function to use with each subcommand.
sub_cmd = [
{
name: "init",
help: "create a pybluedot configuration file",
options: [
{
name: "--force",
action: "store_const"
},
{
name: "--display",
action: "store_const"
}
],
function: "init"
},
{
name: "sounds",
help: "just useless boilerplate atm!",
options: [],
function: "sounds"
}
]
cmd_arg = [{
Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly, this approach of having args in a list like this may be more trouble than it's worth. Just a gut feeling - you may consider seeing what @jeorryb did here: #13 on args, and try to gel this approach with that one. It's possible do to it, but you would have to use the same options for each arg, which you may not want.

'name': 'verbose',
'action': 'store_const'
}, {
'name': 'debug',
'action': 'store_const'
}]

# subcommands used by the program, like 'bdot init'
sub_cmd = [{
Copy link
Contributor

Choose a reason for hiding this comment

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

I consider this format less readable than the previous way you had written this. I know it probably seems overly verbose, but at a glance, I could easily see what was a dict, what was a list, etc. Now, I can't.

'name': 'init',
'help': 'create a pybluedot configuration file',
'options': [{
'name': '--force',
'action': 'store_const'
}, {
'name': '--display',
'action': 'store_const'
}],
'function': 'init'
}, {
'name': 'sounds',
'help': 'just useless boilerplate atm!',
'options': [],
'function': 'sounds'
}]
12 changes: 12 additions & 0 deletions pybluedot/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import unittest

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


class DietTestCase(unittest.TestCase):
"""Same great taste, less filling.
Expand Down
12 changes: 12 additions & 0 deletions pybluedot/tests/unit/test_sample.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
from pybluedot.tests import base
Copy link
Contributor

Choose a reason for hiding this comment

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

No unit tests for the functions you've created? 😄


# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


class SampleTestSuite(base.DietTestCase):
"""This test suite provides some common things relevant to the
Expand Down