Compare commits

..

14 Commits

Author SHA1 Message Date
skullY 1a723e488f New release: 0.0.26 → 0.0.27 2020-01-26 11:40:14 -08:00
skullY bf502d26fa sync milc with qmk_firmware 2020-01-26 11:40:00 -08:00
skullY ebea7f7ea0 New release: 0.0.25 → 0.0.26 2019-11-28 08:42:55 -08:00
skullY 49b288786a Add support for hidden subcommands 2019-11-28 08:42:49 -08:00
skullY e75b4d4ed1 New release: 0.0.24 → 0.0.25 2019-11-18 22:33:19 -08:00
skullY 7f56cfd781 Add flake8 to requirements 2019-11-18 22:33:14 -08:00
skullY b04bf7a4da New release: 0.0.23 → 0.0.24 2019-11-15 23:25:13 -08:00
skullY fb260f29e1 Fix commands with no arguments 2019-11-15 23:15:07 -08:00
skullY e8e98ca15a New release: 0.0.22 → 0.0.23 2019-11-15 22:21:33 -08:00
skullY 4d1302696e Make folding arguments into config operate more correctly. 2019-11-15 22:21:26 -08:00
skullY 4d78df2cbc New release: 0.0.21 → 0.0.22 2019-11-12 16:54:28 -08:00
skullY 4a45081412 filter None from config files 2019-11-12 16:53:32 -08:00
skullY 9cab9ea610 New release: 0.0.20 → 0.0.21 2019-11-11 13:04:13 -08:00
skullY 177fa55bce fix pytest in qmkfm/base_container 2019-11-11 13:03:39 -08:00
5 changed files with 50 additions and 27 deletions
+41 -23
View File
@@ -178,8 +178,9 @@ class ConfigurationSection(Configuration):
def __getitem__(self, key):
"""Returns a config value, pulling from the `user` section as a fallback.
This is called when the attribute is accessed either via the get method or through [ ] index.
"""
if key in self._config:
if key in self._config and self._config.get(key) is not None:
return self._config[key]
elif key in self.parent.user:
@@ -187,6 +188,15 @@ class ConfigurationSection(Configuration):
return None
def __getattr__(self, key):
"""Returns the config value from the `user` section.
This is called when the attribute is accessed via dot notation but does not exists.
"""
if key in self.parent.user:
return self.parent.user[key]
return None
def handle_store_boolean(self, *args, **kwargs):
"""Does the add_argument for action='store_boolean'.
@@ -359,9 +369,6 @@ class MILC(object):
logging.root.setLevel(logging.DEBUG)
self.release_lock()
def initialize_arguments(self):
"""Setup the global parser arguments
"""
self.add_argument('-V', '--version', version=self.version, action='version', help='Display the version and exit')
self.add_argument('-v', '--verbose', action='store_true', help='Make the logging more verbose')
self.add_argument('--datetime-fmt', default='%Y-%m-%d %H:%M:%S', help='Format string for datetimes')
@@ -370,6 +377,7 @@ class MILC(object):
self.add_argument('--log-file', help='File to write log messages to')
self.add_argument('--color', action='store_boolean', default=True, help='color in output')
self.add_argument('--config-file', help='The location for the configuration file')
self.arg_only.append('config_file')
def add_subparsers(self, title='Sub-commands', **kwargs):
if self._inside_context_manager:
@@ -479,8 +487,10 @@ class MILC(object):
# Coerce values into useful datatypes
if value.lower() in ['1', 'yes', 'true', 'on']:
value = True
elif value.lower() in ['0', 'no', 'false', 'none', 'off']:
elif value.lower() in ['0', 'no', 'false', 'off']:
value = False
elif value.lower() in ['none']:
continue
elif value.replace('.', '').isdigit():
if '.' in value:
value = Decimal(value)
@@ -501,25 +511,31 @@ class MILC(object):
if argument not in self.arg_only:
# Find the argument's section
argument_found = True
for group in self.default_arguments:
if argument in self.default_arguments[group]:
argument_found = True
section = group
break
# Underscores in command's names are converted to dashes during initialization.
# TODO(Erovia) Find a better solution
entrypoint_name = self._entrypoint.__name__.replace("_", "-")
if entrypoint_name in self.default_arguments and argument in self.default_arguments[entrypoint_name]:
argument_found = True
section = self._entrypoint.__name__
if argument in self.default_arguments['general']:
argument_found = True
section = 'general'
if not argument_found:
raise RuntimeError('Could not find argument in `self.default_arguments`. This should be impossible!')
exit(1)
# Merge this argument into self.config
if argument in self.default_arguments:
if argument in self.default_arguments['general'] or argument in self.default_arguments[entrypoint_name]:
arg_value = getattr(self.args, argument)
if arg_value:
if arg_value is not None:
self.config[section][argument] = arg_value
else:
if argument not in self.config[section]:
self.config[section][argument] = getattr(self.args, argument)
if argument not in self.config[entrypoint_name]:
# Check if the argument exist for this section
arg = getattr(self.args, argument)
if arg is not None:
self.config[section][argument] = arg
self.release_lock()
@@ -542,7 +558,8 @@ class MILC(object):
if section_name == 'general':
if option_name in ['config_file']:
continue
config.set(section_name, option_name, str(value))
if value is not None:
config.set(section_name, option_name, str(value))
# Write out the config file
config_dir = self.config_file.parent
@@ -594,23 +611,25 @@ class MILC(object):
return entrypoint_func
def add_subcommand(self, handler, description, name=None, **kwargs):
def add_subcommand(self, handler, description, name=None, hidden=False, **kwargs):
"""Register a subcommand.
If name is not provided we use `handler.__name__`.
"""
if self._inside_context_manager:
raise RuntimeError('You must run this before the with statement!')
if self._subparsers is None:
self.add_subparsers()
self.add_subparsers(metavar="")
if not name:
name = handler.__name__.replace("_", "-")
self.acquire_lock()
kwargs['help'] = description
if not hidden:
self._subparsers.metavar = "{%s,%s}" % (self._subparsers.metavar[1:-1], name) if self._subparsers.metavar else "{%s%s}" % (self._subparsers.metavar[1:-1], name)
kwargs['help'] = description
self.subcommands[name] = SubparserWrapper(self, name, self._subparsers.add_parser(name, **kwargs))
self.subcommands[name].set_defaults(entrypoint=handler)
@@ -618,11 +637,11 @@ class MILC(object):
return handler
def subcommand(self, description, **kwargs):
def subcommand(self, description, hidden=False, **kwargs):
"""Decorator to register a subcommand.
"""
def subcommand_function(handler):
return self.add_subcommand(handler, description, **kwargs)
return self.add_subcommand(handler, description, hidden=hidden, **kwargs)
return subcommand_function
@@ -672,7 +691,6 @@ class MILC(object):
self.release_lock()
colorama.init()
self.initialize_arguments()
self.parse_args()
self.merge_args_into_config()
self.setup_logging()
+1 -1
View File
@@ -1,3 +1,3 @@
"""A program to help you work with qmk_firmware."""
__version__ = '0.0.20'
__version__ = '0.0.27'
+4 -1
View File
@@ -56,7 +56,10 @@ def find_qmk_firmware():
return Path(milc.cli.config.user.qmk_home).expanduser().resolve()
if 'QMK_HOME' in os.environ:
return Path(os.environ['QMK_HOME']).expanduser().resolve()
path = Path(os.environ['QMK_HOME']).expanduser()
if path.exists():
return path.resolve()
return path
return Path.home() / 'qmk_firmware'
+1 -1
View File
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.20
current_version = 0.0.27
commit = True
tag = True
tag_name = {new_version}
+3 -1
View File
@@ -44,6 +44,8 @@ if __name__ == "__main__":
"appdirs",
"argcomplete",
"colorama",
"hjson"
"flake8",
"hjson",
"yapf"
],
)