Compare commits

..

14 Commits

Author SHA1 Message Date
skullY bbc5ffd6c9 New release: 0.0.27 → 0.0.28 2020-02-13 19:09:10 -08:00
Zach White e0adba4e68 Prevent release from erroring on first run 2020-02-13 18:50:00 -08:00
Zach White 56bcb12ed6 Add support for determining where a config option came from 2020-02-13 18:49:13 -08:00
Mikkel Jeppesen 897fe121e2 Replace rename with replace 2020-02-13 18:48:02 -08:00
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
5 changed files with 45 additions and 22 deletions
+41 -19
View File
@@ -178,8 +178,9 @@ class ConfigurationSection(Configuration):
def __getitem__(self, key): def __getitem__(self, key):
"""Returns a config value, pulling from the `user` section as a fallback. """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] return self._config[key]
elif key in self.parent.user: elif key in self.parent.user:
@@ -187,6 +188,15 @@ class ConfigurationSection(Configuration):
return None 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): def handle_store_boolean(self, *args, **kwargs):
"""Does the add_argument for action='store_boolean'. """Does the add_argument for action='store_boolean'.
@@ -263,7 +273,7 @@ class MILC(object):
self._inside_context_manager = False self._inside_context_manager = False
self.ansi = ansi_colors self.ansi = ansi_colors
self.arg_only = [] self.arg_only = []
self.config = None self.config = self.config_source = None
self.config_file = None self.config_file = None
self.default_arguments = {} self.default_arguments = {}
self.version = 'unknown' self.version = 'unknown'
@@ -463,6 +473,7 @@ class MILC(object):
""" """
self.acquire_lock() self.acquire_lock()
self.config = Configuration() self.config = Configuration()
self.config_source = Configuration()
self.config_file = self.find_config_file() self.config_file = self.find_config_file()
if self.config_file and self.config_file.exists(): if self.config_file and self.config_file.exists():
@@ -488,6 +499,7 @@ class MILC(object):
value = int(value) value = int(value)
self.config[section][option] = value self.config[section][option] = value
self.config_source[section][option] = 'config_file'
self.release_lock() self.release_lock()
@@ -501,25 +513,33 @@ class MILC(object):
if argument not in self.arg_only: if argument not in self.arg_only:
# Find the argument's section # Find the argument's section
argument_found = True # Underscores in command's names are converted to dashes during initialization.
for group in self.default_arguments: # TODO(Erovia) Find a better solution
if argument in self.default_arguments[group]: entrypoint_name = self._entrypoint.__name__.replace("_", "-")
argument_found = True if entrypoint_name in self.default_arguments and argument in self.default_arguments[entrypoint_name]:
section = group argument_found = True
break section = self._entrypoint.__name__
if argument in self.default_arguments['general']:
argument_found = True
section = 'general'
if not argument_found: if not argument_found:
raise RuntimeError('Could not find argument in `self.default_arguments`. This should be impossible!') raise RuntimeError('Could not find argument in `self.default_arguments`. This should be impossible!')
exit(1) exit(1)
# Merge this argument into self.config # 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) arg_value = getattr(self.args, argument)
if arg_value: if arg_value is not None:
self.config[section][argument] = arg_value self.config[section][argument] = arg_value
self.config_source[section][argument] = 'argument'
else: else:
if argument not in self.config[section]: if argument not in self.config[entrypoint_name]:
self.config[section][argument] = getattr(self.args, argument) # Check if the argument exist for this section
arg = getattr(self.args, argument)
if arg is not None:
self.config[section][argument] = arg
self.config_source[section][argument] = 'argument'
self.release_lock() self.release_lock()
@@ -555,7 +575,7 @@ class MILC(object):
# Move the new config file into place atomically # Move the new config file into place atomically
if os.path.getsize(tmpfile.name) > 0: if os.path.getsize(tmpfile.name) > 0:
os.rename(tmpfile.name, str(self.config_file)) os.replace(tmpfile.name, str(self.config_file))
else: else:
self.log.warning('Config file saving failed, not replacing %s with %s.', str(self.config_file), tmpfile.name) self.log.warning('Config file saving failed, not replacing %s with %s.', str(self.config_file), tmpfile.name)
@@ -595,23 +615,25 @@ class MILC(object):
return entrypoint_func 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. """Register a subcommand.
If name is not provided we use `handler.__name__`. If name is not provided we use `handler.__name__`.
""" """
if self._inside_context_manager: if self._inside_context_manager:
raise RuntimeError('You must run this before the with statement!') raise RuntimeError('You must run this before the with statement!')
if self._subparsers is None: if self._subparsers is None:
self.add_subparsers() self.add_subparsers(metavar="")
if not name: if not name:
name = handler.__name__.replace("_", "-") name = handler.__name__.replace("_", "-")
self.acquire_lock() self.acquire_lock()
if not hidden:
kwargs['help'] = description 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] = SubparserWrapper(self, name, self._subparsers.add_parser(name, **kwargs))
self.subcommands[name].set_defaults(entrypoint=handler) self.subcommands[name].set_defaults(entrypoint=handler)
@@ -619,11 +641,11 @@ class MILC(object):
return handler return handler
def subcommand(self, description, **kwargs): def subcommand(self, description, hidden=False, **kwargs):
"""Decorator to register a subcommand. """Decorator to register a subcommand.
""" """
def subcommand_function(handler): def subcommand_function(handler):
return self.add_subcommand(handler, description, **kwargs) return self.add_subcommand(handler, description, hidden=hidden, **kwargs)
return subcommand_function return subcommand_function
+1 -1
View File
@@ -1,3 +1,3 @@
"""A program to help you work with qmk_firmware.""" """A program to help you work with qmk_firmware."""
__version__ = '0.0.22' __version__ = '0.0.28'
+1 -1
View File
@@ -12,7 +12,7 @@ TWINE_USERNAME=$PYPI_USERNAME
export FLIT_USERNAME TWINE_USERNAME export FLIT_USERNAME TWINE_USERNAME
rm dist/* rm -f dist/*
bumpversion patch bumpversion patch
git push origin master --tags git push origin master --tags
+1 -1
View File
@@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 0.0.22 current_version = 0.0.28
commit = True commit = True
tag = True tag = True
tag_name = {new_version} tag_name = {new_version}
+1
View File
@@ -44,6 +44,7 @@ if __name__ == "__main__":
"appdirs", "appdirs",
"argcomplete", "argcomplete",
"colorama", "colorama",
"flake8",
"hjson", "hjson",
"yapf" "yapf"
], ],