Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): Fix the linter configuration #131

Merged
merged 8 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
---
default_stages:
- commit

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: end-of-file-fixer

- repo: local
hooks:
- entry: black
exclude: |
(?x)(
^{{cookiecutter.project_slug}}/
)
files: ""
id: black
language: system
- id: black
entry: black
name: black
language: system
pass_filenames: true
stages:
- commit
types:
- python
- file
- python
- entry: mypy
exclude: ^$
files: "{{ cookiecutter.package_slug }}/"
id: mypy
language: python

- id: mypy
name: mypy
entry: mypy
files: "src/scicookie/"
language: system
pass_filenames: true
stages:
- commit
# pre-commit + mypy doesn't honor the exclusion defined in the config
exclude: |
(?x)(
src/scicookie/{{cookiecutter.project_slug}}/
| src/scicookie/hooks
)
types:
- python

- id: ruff
name: ruff
entry: ruff
language: python
entry: ruff --no-cache
language: system
pass_filenames: true
files: "src/scicookie/"
# pre-commit + ruff doesn't honor the exclusion defined in the config
exclude: |
(?x)^(
tests/.*|
src/scicookie/.*|
docs/.*|
)$
stages:
- commit
(?x)(
src/scicookie/{{cookiecutter.project_slug}}
| src/scicookie/hooks
)
types:
- python
65 changes: 37 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,42 +47,51 @@ line-length = 79
# note: for support "py39", we need to update black using poetry
# currently, it has conflicts with typing-extensions.
target-version = ["py38"]
force-exclude = '''
/(
| docs/*
| hooks/*
| {{cookiecutter.project_slug}}/*
force-exclude = '''(?x)(
docs/*
| src/scicookie/{{cookiecutter.project_slug}}/*
| src/scicookie/hooks/*
|.*\\.egg-info
)/
'''
)''' # TOML's single-quoted strings do not require escaping backslashes

[tool.flake8]
max-line-length = 79
# Ignoring these erros will prevent conflicts with Flake8 and Jinja2 syntax.
exclude = [
'.git/*',
'__pycache__/*',
'docs/*',
'src/scicookie/hooks/*',
'src/scicookie/{{cookiecutter.project_slug}}/*'
[tool.mypy]
no_strict_optional = false
exclude = '''(?x)(
src/scicookie/{{cookiecutter.project_slug}}/
| src/scicookie/hooks/*
)''' # TOML's single-quoted strings do not require escaping backslashes

[[tool.mypy.overrides]]
module = [
"colorama",
"inquirer",
"sh",
"yaml",
]
ignore_missing_imports = true

[tool.ruff]
line-length = 79
force-exclude = true
src = ["src/scicookie"]
exclude = [
'.git/*',
'__pycache__/*',
'docs/*',
'src/scicookie/hooks/*',
'src/scicookie/{{cookiecutter.project_slug}}/*'
'.git',
'__pycache__',
'docs',
'src/scicookie/\{\{cookiecutter.project_slug\}\}',
'src/scicookie/hooks',
]
select = [
"E", # pycodestyle
"F", # pyflakes
"D", # pydocstyle
"YTT", # flake8-2020
"PL", # PL
"RUF", # Ruff-specific rules
]

[tool.isort]
ensure_newline_before_comments = true
line_length = 79
multi_line_output = 3
include_trailing_comma = true
skip_glob = ["docs/*", "*.egg-info"]

[tool.ruff.pydocstyle]
convention = "numpy"

[tool.pytest.ini_options]
testpaths = [
Expand Down
1 change: 1 addition & 0 deletions src/scicookie/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""SciCookie is a wrap around cookiecutter/cookieninja with a better TUI."""
1 change: 1 addition & 0 deletions src/scicookie/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Interface for the `python -m scicookie`."""
from scicookie.cli import app

if __name__ == "__main__":
Expand Down
5 changes: 3 additions & 2 deletions src/scicookie/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Module with CLI functions."""
import json
import os
import sys
Expand Down Expand Up @@ -30,6 +31,7 @@ def _get_cookiecutter_default_answer(


def call_cookiecutter(profile: Profile, answers: dict):
"""Call coociecutter/cookieninja with the parameters from the TUI."""
answers_profile = {}
cookie_args = []
questions = profile.config
Expand Down Expand Up @@ -96,8 +98,7 @@ def call_cookiecutter(profile: Profile, answers: dict):


def app():
"""CLI main function."""

"""Run SciCookie."""
# note: this parameter should be provided by a CLI argument
profile = Profile("osl")

Expand Down
8 changes: 8 additions & 0 deletions src/scicookie/logs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Module for functions and classes for systen logs."""
import os
from enum import Enum

from colorama import Fore


class SciCookieErrorType(Enum):
"""Enum class for the error codes."""

SH_ERROR_RETURN_CODE = 1
SH_KEYBOARD_INTERRUPT = 2
SCICOOKIE_INVALID_PARAMETER = 3
Expand All @@ -13,15 +16,20 @@ class SciCookieErrorType(Enum):


class SciCookieLogs:
"""Main log for print and raise messages to the system."""

@staticmethod
def raise_error(message: str, message_type: SciCookieErrorType):
"""Print an error message and exit with the given error code."""
print(Fore.RED, f"[EE] {message}", Fore.RESET)
os._exit(message_type.value)

@staticmethod
def info(message: str):
"""Print an info message."""
print(Fore.BLUE, message, Fore.RESET)

@staticmethod
def warning(message: str):
"""Print an warning message."""
xmnlab marked this conversation as resolved.
Show resolved Hide resolved
print(Fore.YELLOW, message, Fore.RESET)
6 changes: 5 additions & 1 deletion src/scicookie/profile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Profile handles "profiles" defined in the .yaml files."""
from pathlib import Path

import yaml
Expand All @@ -9,9 +10,11 @@


class Profile:
"""Profile class that handles profiles defined in the .yaml files."""

profile_name: str = ""
config: dict = {}
profiles_available = []
profiles_available: list = []

def __init__(self, profile_name: str):
self._load_profiles_available()
Expand All @@ -30,6 +33,7 @@ def _load_profiles_available(self):
self.profiles_available = ["osl"]

def read_config(self):
"""Read the config file."""
config = {}
with open(PROFILE_DIR_PATH / "base.yaml") as f:
config = yaml.safe_load(f)
Expand Down
18 changes: 11 additions & 7 deletions src/scicookie/ui.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"""Define functions for the interface with the user."""
from typing import Optional, Type, Dict
import inquirer

from scicookie.logs import SciCookieErrorType, SciCookieLogs


def _create_question(question_id: str, question: dict):
def _create_question(
question_id: str, question: dict
) -> Optional[inquirer.questions.Question]:
# validation
if not question.get("enabled", False):
return
return None

# config required
default_answer = question.get("default")
question_message = question.get("message")
question_type = question.get("type")
default_answer = question.get("default", "")
question_message = question.get("message", "")
question_type = question.get("type", "")
# todo: implement help text int he prompt
# question_help = question.get("help")
# todo: implement depends on workflow, it needs refactoring the code
Expand Down Expand Up @@ -43,7 +46,7 @@ def _create_question(question_id: str, question: dict):
if question.get("choices"):
content["choices"] = question.get("choices")

fn_questions = {
fn_questions: Dict[str, Type[inquirer.questions.Question]] = {
"text": inquirer.Text,
"single-choice": inquirer.List,
"multiple-choices": inquirer.Checkbox,
Expand All @@ -57,6 +60,7 @@ def _create_question(question_id: str, question: dict):


def make_questions(questions: dict):
"""Generate all the enabled questions."""
questions_ui = []

for question_id, question in questions.items():
Expand Down
3 changes: 0 additions & 3 deletions src/scicookie/{{cookiecutter.project_slug}}/.bandit
xmnlab marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ repos:
entry: ruff
language: system
pass_filenames: true
files: "{{ package_path }}"
types:
- python
{%- endif %}
Expand Down
23 changes: 21 additions & 2 deletions src/scicookie/{{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ pre-commit = "^3.3.2"
{%- if cookiecutter.use_flake8 == "yes" -%}
flake8 = ">=4.0.1, <7"
{% endif %}
{%- if cookiecutter.use_ruff == "yes" -%}
ruff = "^0.0.272"
{%- if cookiecutter.use_ruff == "yes" -%}
ruff = "^0.0.272"
{% endif %}
{%- if cookiecutter.use_mypy == "yes" -%}
mypy = "^1.3.0"
Expand Down Expand Up @@ -166,4 +166,23 @@ paths = ["{{ package_path }}"]
sort_by_size = true
verbose = false
{% endif %}
{%- if cookiecutter.use_ruff == "yes" %}
[tool.ruff]
line-length = 79
force-exclude = true
src = ["{{ package_path }}"]
exclude = [
'docs',
]
select = [
"F", # pyflakes
]

[tool.ruff.pydocstyle]
convention = "numpy"
{% endif %}
{%- if cookiecutter.use_mypy == "yes" %}
[tool.mypy]
no_strict_optional = false
{% endif %}
{#- keep this line at the end of the file -#}