Skip to content

Commit

Permalink
fix(linter): Fix the linter configuration (#131)
Browse files Browse the repository at this point in the history
Fix the linter configuration for the project and the template.

Co-authored-by: Anavelyz <42752529+Anavelyz@users.noreply.github.com>
  • Loading branch information
xmnlab and Anavelyz authored Jun 16, 2023
1 parent eb6f64d commit e9843e2
Show file tree
Hide file tree
Showing 13 changed files with 519 additions and 713 deletions.
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
991 changes: 386 additions & 605 deletions poetry.lock

Large diffs are not rendered by default.

90 changes: 47 additions & 43 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@ include = [
python = "^3.8.1"
cookieninja = "1.0.0"
sh = "^2.0.4"
pyyaml = "<6.0"
pyyaml = ">=5"
colorama = "^0.4.6"
inquirer = "^3.1.3"

[tool.poetry.group.dev.dependencies]
pytest = "^7"
black = "^22"
isort = "^5"
pre-commit = "^2"
flake8 = "^4"
ruff = "^0.0.272"
mypy = "^0.931"
pytest-cov = "^3.0.0"
pytest-cookies = "^0.6.1"
Sphinx = "^4.4.0"
Flake8-pyproject = "^0.9.0"
jupyterlab = "^3.5.1"
jupyter-book = "^0.12.3"
myst-parser = "^0.15"
pytest = ">=7"
black = ">=22"
isort = ">=5"
pre-commit = ">=3"
ruff = ">=0.0.272"
mypy = ">=1"
pytest-cov = ">=3"
pytest-cookies = ">=0.6.1"
Sphinx = ">=4.4"
jupyterlab = ">=3.5.1"
jupyter-book = ">=0.12.3"
myst-parser = ">=0.15"
makim = "1.8.1"

[build-system]
Expand All @@ -47,42 +45,48 @@ 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}}/*'
'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
6 changes: 0 additions & 6 deletions src/scicookie/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ def clean_up_project_layout():
shutil.move('{{cookiecutter.package_slug}}', 'src')


def clean_up_bandit():
if not USE_BANDIT:
remove_project_file(PROJECT_DIRECTORY / '.bandit')


def clean_up_code_of_conduct():
if COC_PATH:
shutil.move(
Expand Down Expand Up @@ -192,7 +187,6 @@ def post_gen():
# keep this one first, because it changes the package folder
clean_up_project_layout()

clean_up_bandit()
clean_up_cli()
clean_up_code_of_conduct()
clean_up_conda()
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 a warning message."""
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

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
Loading

0 comments on commit e9843e2

Please sign in to comment.