-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEV] Cookiecutter Python Package v1.4.1
- Loading branch information
Showing
16 changed files
with
223 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ build-backend = "poetry.core.masonry.api" | |
## Also renders on pypi as 'subtitle' | ||
[tool.poetry] | ||
name = "cookiecutter_python" | ||
version = "1.4.0" | ||
version = "1.4.1" | ||
description = "Yet another modern Python Package (pypi) with emphasis in CI/CD and automation." | ||
authors = ["Konstantinos Lampridis <[email protected]>"] | ||
maintainers = ["Konstantinos Lampridis <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.4.0' | ||
__version__ = '1.4.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import io | ||
import json | ||
import logging | ||
import typing as t | ||
from json import JSONDecodeError | ||
|
||
import poyo | ||
|
||
GivenInterpreters = t.Mapping[str, t.Sequence[str]] | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def load_yaml(config_file) -> t.Mapping: | ||
# TODO use a proxy to load yaml | ||
with io.open(config_file, encoding='utf-8') as file_handle: | ||
try: | ||
yaml_dict = poyo.parse_string(file_handle.read()) | ||
except poyo.exceptions.PoyoException as error: | ||
raise InvalidYamlFormatError( | ||
'Unable to parse YAML file {}. Error: {}' ''.format(config_file, error) | ||
) from error | ||
return yaml_dict | ||
|
||
|
||
def get_interpreters_from_yaml(config_file: str) -> t.Optional[GivenInterpreters]: | ||
"""Parse the 'interpreters' variable out of the user's config yaml file. | ||
Args: | ||
config_file (str): path to the user's config yaml file | ||
Raises: | ||
InvalidYamlFormatError: if yaml parser fails to load the user's config | ||
UserYamlDesignError: if yaml does not contain the 'default_context' key | ||
Returns: | ||
GivenInterpreters: dictionary with intepreters as a sequence of strings, | ||
mapped to the 'supported-interpreters' key | ||
""" | ||
data = load_yaml(config_file) | ||
if 'default_context' not in data: | ||
raise UserYamlDesignError( | ||
"User config (is valid yaml but) does not contain a 'default_context' outer key!" | ||
) | ||
context = data['default_context'] | ||
if 'interpreters' not in context: | ||
return None | ||
|
||
try: | ||
interpreters_data = json.loads(context['interpreters']) | ||
except JSONDecodeError as error: | ||
logger.warning( | ||
"User's yaml config 'interpreters' value Error: %s", | ||
json.dumps( | ||
{ | ||
'error': error, | ||
'message': "Expected json 'parasable' value for the 'interpreters' key", | ||
}, | ||
sort_keys=True, | ||
indent=4, | ||
), | ||
) | ||
return None | ||
return interpreters_data | ||
|
||
|
||
class UserYamlDesignError(Exception): | ||
pass | ||
|
||
|
||
class InvalidYamlFormatError(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import lib # noqa | ||
from .dialog import InteractiveDialog | ||
|
||
__all__ = ['InteractiveDialog'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from abc import abstractmethod | ||
|
||
from software_patterns import SubclassRegistry | ||
|
||
|
||
class InteractiveDialog(metaclass=SubclassRegistry): | ||
@abstractmethod | ||
def dialog(self, *args, **kwargs): | ||
raise NotImplementedError |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from cookiecutter_python.utils import load | ||
|
||
from ..dialog import InteractiveDialog | ||
|
||
# Import all classes subclassing InteractiveDialog | ||
load(InteractiveDialog) |
33 changes: 33 additions & 0 deletions
33
src/cookiecutter_python/handle/dialogs/lib/interpreters_dialog.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import typing as t | ||
|
||
try: | ||
from PyInquirer import prompt | ||
except ImportError: | ||
|
||
def prompt(*args, **kwargs): | ||
return {} | ||
|
||
|
||
from ..dialog import InteractiveDialog | ||
|
||
|
||
@InteractiveDialog.register_as_subclass('interpreters-checkbox') | ||
class InterpretersCheckbox(InteractiveDialog): | ||
def dialog(self, *args, **kwargs): | ||
return self._dialog(*args, **kwargs) | ||
|
||
def _dialog( | ||
self, choices: t.Dict[str, t.Union[str, bool]] | ||
) -> t.Dict[str, t.Sequence[str]]: | ||
|
||
return prompt( | ||
[ | ||
# Question 1 | ||
{ | ||
'type': 'checkbox', | ||
'name': 'supported-interpreters', | ||
'message': 'Select the python Interpreters you wish to support', | ||
'choices': choices, | ||
}, | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.