Skip to content

Commit

Permalink
chore(autoformat): Change blue to ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Nov 9, 2023
1 parent a14914b commit b39e493
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 48 deletions.
31 changes: 6 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ repos:

- repo: local
hooks:
- id: blue
name: blue
entry: blue
- id: ruff-format
name: ruff-format
entry: ruff format
exclude: |
(?x)(
docs
Expand All @@ -21,23 +21,15 @@ repos:
types:
- python

- id: ruff
name: ruff
- id: ruff-linter
name: ruff-linter
entry: ruff check
language: system
exclude: "docs/"
pass_filenames: true
types:
- python

- id: isort
name: isort
entry: isort
language: system
pass_filenames: true
types:
- python

- id: mypy
name: mypy
entry: mypy
Expand All @@ -47,7 +39,6 @@ repos:
types:
- python


- id: bandit
name: bandit
entry: bandit
Expand All @@ -59,20 +50,10 @@ repos:

- id: vulture
name: vulture
entry: vulture
entry: vulture --min-confidence 80
language: system
files: "makim/"
description: Find unused Python code.
pass_filenames: true
types:
- python

- id: pydocstyle
name: pydocstyle
entry: pydocstyle
exclude: ^$
files: "makim/"
language: system
pass_filenames: true
types:
- python
1 change: 1 addition & 0 deletions makim/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import os
import sys

from pathlib import Path

from makim import Makim, __version__
Expand Down
24 changes: 15 additions & 9 deletions makim/makim.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@
import sys
import tempfile
import warnings

from copy import deepcopy
from pathlib import Path
from typing import Dict, Optional, Tuple

import dotenv
import sh
import yaml # type: ignore

from colorama import Fore
from jinja2 import Template

from makim.errors import MakimError

SCOPE_GLOBAL = 0
SCOPE_GROUP = 1
SCOPE_TARGET = 2


def escape_template_tag(v: str) -> str:
"""Escape template tag when processing the template config file."""
Expand Down Expand Up @@ -150,7 +156,7 @@ def _change_group_data(self, group_name=None):
self.group_name = group_name
shell_app_default = self.global_data.get('shell', 'xonsh')
if self.group_name == 'default' and len(groups) == 1:
group = list(groups)[0]
group = next(iter(groups))
self.group_data = groups[group]

shell_app = self.group_data.get('shell', shell_app_default)
Expand All @@ -174,8 +180,8 @@ def _load_config_data(self):
with open(self.makim_file, 'r') as f:
# escape template tags
content = escape_template_tag(f.read())
f = io.StringIO(content)
self.global_data = yaml.safe_load(f)
content_io = io.StringIO(content)
self.global_data = yaml.safe_load(content_io)

def _load_shell_app(self, shell_app: str = ''):
if not shell_app:
Expand Down Expand Up @@ -219,19 +225,19 @@ def _render_env_inplace(
env = deepcopy(dict(os.environ))
variables: dict = {}

if scope_id >= 0:
if scope_id >= SCOPE_GLOBAL:
env_user = self.global_data.get('env', {})
env_file = self._load_dotenv(self.global_data)
_render_env_inplace(env_user, env_file, variables, env)
variables.update(self._load_scoped_vars('global', env=env))

if scope_id >= 1:
if scope_id >= SCOPE_GROUP:
env_user = self.group_data.get('env', {})
env_file = self._load_dotenv(self.group_data)
_render_env_inplace(env_user, env_file, variables, env)
variables.update(self._load_scoped_vars('group', env=env))

if scope_id == 2:
if scope_id == SCOPE_TARGET:
env_user = self.target_data.get('env', {})
env_file = self._load_dotenv(self.target_data)
_render_env_inplace(env_user, env_file, variables, env)
Expand All @@ -247,21 +253,21 @@ def _load_scoped_vars(self, scope: str, env) -> dict:

variables = {}

if scope_id >= 0:
if scope_id >= SCOPE_GLOBAL:
variables.update(
{
k: v.strip()
for k, v in self.global_data.get('vars', {}).items()
}
)
if scope_id >= 1:
if scope_id >= SCOPE_GROUP:
variables.update(
{
k: v.strip()
for k, v in self.group_data.get('vars', {}).items()
}
)
if scope_id == 2:
if scope_id == SCOPE_TARGET:
variables.update(
{
k: v.strip()
Expand Down
41 changes: 27 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ colorama = ">=0.4.6"
[tool.poetry.group.dev.dependencies]
containers-sugar = "1.9.0"
pytest = ">=7"
blue = ">=0.9.1"
isort = ">=5"
pre-commit = ">=3"
mypy = ">=1"
pytest-cov = ">=3.0.0"
Expand All @@ -63,10 +61,9 @@ mkdocs-literate-nav = ">=0.4.1"
mkdocs-macros-plugin = ">=0.6.3"
mkdocs-material = ">=8"
mkdocstrings = {version=">=0.19.0", extras=["python"]}
ruff = ">=0.0.278"
ruff = ">=0.1.5"
bandit = ">=1.7.5"
vulture = ">=2.7"
pydocstyle = ">=6.3.0"
compose-go = ">=2.20.2"

[build-system]
Expand All @@ -78,24 +75,40 @@ testpaths = [
"tests",
]

[tool.blue]
line-length = 79 # this is the default

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

[tool.mypy]
ignore_missing_imports = true


[tool.ruff]
line-length = 79
force-exclude = true
src = ["./makim", "./tests"]
ignore = ["RUF012"]
exclude = [
"docs",
]
select = [
"E", # pycodestyle
"F", # pyflakes
"D", # pydocstyle
"YTT", # flake8-2020
"PL", # PL
"RUF", # Ruff-specific rules
"I001", # isort
]
# fixable = ["I001"]
fix = true

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

[tool.ruff.isort]
# Use a single line between direct and from import
lines-between-types = 1

[tool.ruff.format]
quote-style = "single"


[tool.bandit]
exclude_dirs = ["tests"]
Expand Down
3 changes: 3 additions & 0 deletions tests/test_failure.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Tests for `makim` package."""
import os
import sys

from pathlib import Path

import pytest

import makim

from makim.errors import MakimError


Expand All @@ -18,6 +20,7 @@
],
)
def test_failure(target, args, error_code):
"""Test makim with expected failures."""
makim_file = Path(__file__).parent / '.makim-unittest.yaml'

m = makim.Makim()
Expand Down
1 change: 1 addition & 0 deletions tests/test_success.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
],
)
def test_success(target, args):
"""Test makim when expects success."""
makim_file = Path(__file__).parent / '.makim-unittest.yaml'

m = makim.Makim()
Expand Down

0 comments on commit b39e493

Please sign in to comment.