Skip to content

Commit

Permalink
fixed default __os__
Browse files Browse the repository at this point in the history
TimoEg committed Oct 10, 2024
1 parent e91ffc5 commit 88ce163
Showing 2 changed files with 31 additions and 3 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -114,9 +114,6 @@ description:
pip: Standard python package manager.
```
> [!CAUTION]
> Currently `__os__` automatic detection not working.

* For the package to set the default os to the running system, name the property `__os__`.

```yaml
31 changes: 31 additions & 0 deletions installation_instruction/__main__.py
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@
import click
import json
import platformdirs
import platform

from .__init__ import __version__, __description__, __repository__, __author__, __author_email__, __license__
from .get_flags_and_options_from_schema import _get_flags_and_options
@@ -39,6 +40,29 @@
License: {__license__}
Repository: {__repository__}"""

def _get_system(option_types):
"""
Returns the os from the list of possible os systems defined in the schema.
:param option_types: list of system from the schema.
:type option_types: list
:return: os system from input list or None.
:rtype: string or None
"""

system = platform.system()
system_names = {
'Linux': 'linux',
'Darwin': 'mac',
'Windows': 'win',
}

new_default = system_names.get(system,None)
for type in option_types:
if new_default in type.lower():
return type

return None

class ConfigReadCommand(click.MultiCommand):
"""
@@ -65,6 +89,13 @@ def get_command(self, ctx, config_file: str) -> click.Command|None:
_red_echo("Error (parsing options from schema): " + str(e))
exit(1)

#set new default value for __os__ Option
for option in options:
if '__os__' in option.name:
system_default = _get_system(option.type.choices)
if system_default:
option.default = system_default

def callback(**kwargs):
inst = instruction.validate_and_render(kwargs)
if inst[1]:

0 comments on commit 88ce163

Please sign in to comment.