cookiejar / cookietemple

A collection of best practice cookiecutter templates for all domains and languages with extensive Github support ⛺
https://cookietemple.com
Apache License 2.0
156 stars 10 forks source link

Linting without a cookietemple.cfg file leads to bump-version linting check errors #350

Closed Zethson closed 4 years ago

Zethson commented 4 years ago
Traceback (most recent call last):
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/configparser.py", line 1146, in _unify_values                                                                                       │
│    1143         """                                                                                                                                                                        │
│    1144         sectiondict = {}                                                                                                                                                           │
│    1145         try:                                                                                                                                                                       │
│  ❱ 1146             sectiondict = self._sections[section]                                                                                                                                  │
│    1147         except KeyError:                                                                                                                                                           │
│    1148             if section != self.default_section:                                                                                                                                    │
│    1149                 raise NoSectionError(section) from None                                                                                                                            │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'bumpversion'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ File "/home/zeth/anaconda3/envs/mlf-core/bin/mlf-core", line 8, in <module>                                                                                                                │
│    5 from mlf_core.cli import main                                                                                                                                                         │
│    6 if __name__ == '__main__':                                                                                                                                                            │
│    7     sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                                                                                                                  │
│  ❱ 8     sys.exit(main())                                                                                                                                                                  │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/mlf_core/cli.py", line 40, in main                                                                                    │
│     37     # Is the latest mlf-core version installed? Upgrade if not!                                                                                                                     │
│     38     if not UpgradeCommand.check_mlf_core_latest():                                                                                                                                  │
│     39         print('[bold blue]Run [green]mlf-core upgrade [blue]to get the latest version.')                                                                                            │
│  ❱  40     mlf_core_cli()                                                                                                                                                                  │
│     41                                                                                                                                                                                     │
│     42                                                                                                                                                                                     │
│     43 @click.group(cls=HelpErrorHandling)                                                                                                                                                 │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/click/core.py", line 829, in __call__                                                                                 │
│     826                                                                                                                                                                                    │
│     827     def __call__(self, *args, **kwargs):                                                                                                                                           │
│     828         """Alias for :meth:`main`."""                                                                                                                                              │
│  ❱  829         return self.main(*args, **kwargs)                                                                                                                                          │
│     830                                                                                                                                                                                    │
│     831                                                                                                                                                                                    │
│     832 class Command(BaseCommand):                                                                                                                                                        │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/click/core.py", line 782, in main                                                                                     │
│     779         try:                                                                                                                                                                       │
│     780             try:                                                                                                                                                                   │
│     781                 with self.make_context(prog_name, args, **extra) as ctx:                                                                                                           │
│  ❱  782                     rv = self.invoke(ctx)                                                                                                                                          │
│     783                     if not standalone_mode:                                                                                                                                        │
│     784                         return rv                                                                                                                                                  │
│     785                     # it's not safe to `ctx.exit(rv)` here!                                                                                                                        │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/click/core.py", line 1259, in invoke                                                                                  │
│    1256                 Command.invoke(self, ctx)                                                                                                                                          │
│    1257                 sub_ctx = cmd.make_context(cmd_name, args, parent=ctx)                                                                                                             │
│    1258                 with sub_ctx:                                                                                                                                                      │
│  ❱ 1259                     return _process_result(sub_ctx.command.invoke(sub_ctx))                                                                                                        │
│    1260                                                                                                                                                                                    │
│    1261         # In chain mode we create the contexts step by step, but after the                                                                                                         │
│    1262         # base command has been invoked.  Because at that point we do not                                                                                                          │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/click/core.py", line 1066, in invoke                                                                                  │
│    1063         """                                                                                                                                                                        │
│    1064         _maybe_show_deprecated_notice(self)                                                                                                                                        │
│    1065         if self.callback is not None:                                                                                                                                              │
│  ❱ 1066             return ctx.invoke(self.callback, **ctx.params)                                                                                                                         │
│    1067                                                                                                                                                                                    │
│    1068                                                                                                                                                                                    │
│    1069 class MultiCommand(Command):                                                                                                                                                       │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/click/core.py", line 610, in invoke                                                                                   │
│     607         args = args[2:]                                                                                                                                                            │
│     608         with augment_usage_errors(self):                                                                                                                                           │
│     609             with ctx:                                                                                                                                                              │
│  ❱  610                 return callback(*args, **kwargs)                                                                                                                                   │
│     611                                                                                                                                                                                    │
│     612     def forward(*args, **kwargs):  # noqa: B902                                                                                                                                    │
│     613         """Similar to :meth:`invoke` but fills in default keyword                                                                                                                  │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/mlf_core/cli.py", line 70, in create                                                                                  │
│     67     Next, you will be asked whether you want to use mlf-core's Github support create a repository, push your template and enable a few settings.                                    │
│     68     After the project has been created it will be linted and you will be notified of any TODOs.                                                                                     │
│     69     """                                                                                                                                                                             │
│  ❱  70     choose_domain(domain, None)                                                                                                                                                     │
│     71                                                                                                                                                                                     │
│     72                                                                                                                                                                                     │
│     73 @mlf_core_cli.command(short_help='Lint your existing mlf-core project.', cls=CustomHelpSubcommand)                                                                                  │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/mlf_core/create/create.py", line 29, in choose_domain                                                                 │
│    26     }                                                                                                                                                                                │
│    27                                                                                                                                                                                      │
│    28     creator_obj = switcher.get(domain.lower())()                                                                                                                                     │
│  ❱ 29     creator_obj.create_template(dot_mlf_core)                                                                                                                                        │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/mlf_core/create/domains/mlflow_creator.py", line 72, in create_template                                               │
│    69             self.cli_struct.language), f'mlflow-{self.cli_struct.language.lower()}'                                                                                                  │
│    70                                                                                                                                                                                      │
│    71         # perform general operations like creating a GitHub repository and general linting                                                                                           │
│  ❱ 72         super().process_common_operations(domain='mlflow', language=self.cli_struct.language, dot_mlf_core=dot_mlf_core)                                                             │
│    73                                                                                                                                                                                      │
│    74     def mlflow_pytorch_options(self, dot_mlf_core: dict or None):                                                                                                                    │
│    75         """ Prompts for cli-python specific options and saves them into the MlflowTemplateStruct """                                                                                 │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/mlf_core/create/template_creator.py", line 64, in process_common_operations                                           │
│     61             fix_short_title_underline(f'{project_path}/docs/index.rst')                                                                                                             │
│     62                                                                                                                                                                                     │
│     63         # Lint the project to verify that the new template adheres to all standards                                                                                                 │
│  ❱  64         lint_project(project_path)                                                                                                                                                  │
│     65                                                                                                                                                                                     │
│     66         if self.creator_ctx.is_github_repo and not dot_mlf_core:                                                                                                                    │
│     67             # rename the currently created template to a temporary name, create Github repo, push, remove temporary template                                                        │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/mlf_core/lint/lint.py", line 33, in lint_project                                                                      │
│    30     try:                                                                                                                                                                             │
│    31         # Run non project specific linting                                                                                                                                           │
│    32         print('[bold blue]Running general linting')                                                                                                                                  │
│  ❱ 33         lint_obj.lint_project(super(lint_obj.__class__, lint_obj), is_subclass_calling=False)                                                                                        │
│    34                                                                                                                                                                                      │
│    35         # Run the project specific linting                                                                                                                                           │
│    36         print('[bold blue]Running {template_handle} linting')                                                                                                                        │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/mlf_core/lint/template_linter.py", line 74, in lint_project                                                           │
│     71                 if fun_name == 'check_files_exist':                                                                                                                                 │
│     72                     getattr(calling_class, fun_name)(is_subclass_calling)                                                                                                           │
│     73                 else:                                                                                                                                                               │
│  ❱  74                     getattr(calling_class, fun_name)()                                                                                                                              │
│     75                                                                                                                                                                                     │
│     76     def check_files_exist(self, is_subclass_calling=True):                                                                                                                          │
│     77         """Checks a given project directory for required files.                                                                                                                     │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/site-packages/mlf_core/lint/template_linter.py", line 232, in check_version_consistent                                              │
│    229         parser.read(f'{self.path}/mlf_core.cfg')                                                                                                                                    │
│    230         sections = ['bumpversion_files_whitelisted', 'bumpversion_files_blacklisted']                                                                                               │
│    231                                                                                                                                                                                     │
│  ❱ 232         current_version = parser.get('bumpversion', 'current_version')                                                                                                              │
│    233                                                                                                                                                                                     │
│    234         cwd = os.getcwd()                                                                                                                                                           │
│    235         os.chdir(self.path)                                                                                                                                                         │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/configparser.py", line 781, in get                                                                                                  │
│     778         The section DEFAULT is special.                                                                                                                                            │
│     779         """                                                                                                                                                                        │
│     780         try:                                                                                                                                                                       │
│  ❱  781             d = self._unify_values(section, vars)                                                                                                                                  │
│     782         except NoSectionError:                                                                                                                                                     │
│     783             if fallback is _UNSET:                                                                                                                                                 │
│     784                 raise                                                                                                                                                              │
│ File "/home/zeth/anaconda3/envs/mlf-core/lib/python3.8/configparser.py", line 1149, in _unify_values                                                                                       │
│    1146             sectiondict = self._sections[section]                                                                                                                                  │
│    1147         except KeyError:                                                                                                                                                           │
│    1148             if section != self.default_section:                                                                                                                                    │
│  ❱ 1149                 raise NoSectionError(section) from None                                                                                                                            │
│    1150         # Update with the entry specific variables                                                                                                                                 │
│    1151         vardict = {}                                                                                                                                                               │
│    1152         if vars:                                                                                                                                                                   │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
NoSectionError: No section: 'bumpversion'

Should fail at file cookietemple.cfg does not exist first.

Imipenem commented 4 years ago

Interesting, thought we are already checking if the file exists in the first place, will fix this.