Skip to content

Commit

Permalink
Upgrade pre-commit hooks too
Browse files Browse the repository at this point in the history
  • Loading branch information
chiruzzimarco committed Jun 24, 2021
1 parent ff1ecca commit 0e169e6
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 138 deletions.
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: derex/runner/compose_files/openedx_customizations/.*
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.0.0
rev: v4.0.1
hooks:
- id: trailing-whitespace
exclude: .bumpversion.cfg
Expand All @@ -15,7 +15,7 @@ repos:
- id: check-yaml

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.1
rev: 3.9.2
hooks:
- id: flake8
args:
Expand All @@ -25,29 +25,29 @@ repos:
:F821,F405,F403,E266"

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.770
rev: v0.910
hooks:
- id: mypy
args:
- --ignore-missing-imports
["--install-types", "--non-interactive", "--ignore-missing-imports"]
exclude: "^\
examples/.*|\
docker-definition/derex_django/derex_django/settings/default/.*|\
docker-definition/derex_django/setup.py\
$"

- repo: https://github.com/ambv/black
rev: 19.10b0
rev: 21.6b0
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
rev: v5.9.1
hooks:
- id: isort

- repo: https://github.com/prettier/prettier
rev: 2.0.5 # Use the sha or tag you want to point at
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.3.1
hooks:
- id: prettier
exclude: docs/html_templates/layout.html
23 changes: 13 additions & 10 deletions derex/runner/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
@click.pass_context
@setup_logging_decorator
def derex(ctx):
"""Derex directs edX: commands to manage an Open edX installation
"""
"""Derex directs edX: commands to manage an Open edX installation"""
# Optimize --help and bash completion by importing
from derex.runner.project import Project

Expand Down Expand Up @@ -74,17 +73,15 @@ def derex(ctx):
@derex.group()
@click.pass_context
def debug(ctx):
"""Debugging utilities
"""
"""Debugging utilities"""


@derex.command()
@click.pass_obj
def reset_mailslurper(project):
"""Reset the mailslurper database.
"""
from derex.runner.mysql import drop_database
"""Reset the mailslurper database."""
from derex.runner.docker_utils import load_dump
from derex.runner.mysql import drop_database

drop_database("mailslurper")
click.echo("Priming mailslurper database")
Expand Down Expand Up @@ -147,7 +144,10 @@ def reindex_courses(project, course_ids):

@derex.command()
@click.option(
"--tty/--no-tty", required=False, default=True, help="Allocate a tty",
"--tty/--no-tty",
required=False,
default=True,
help="Allocate a tty",
)
@click.pass_obj
@ensure_project
Expand Down Expand Up @@ -268,10 +268,13 @@ def minio_shell():

@debug.command("print-secret")
@click.argument(
"secret", type=str, required=True,
"secret",
type=str,
required=True,
)
def print_secret(secret):
from derex.runner.secrets import get_secret, DerexSecrets
from derex.runner.secrets import DerexSecrets
from derex.runner.secrets import get_secret

derex_secret = getattr(DerexSecrets, secret, None)
if not derex_secret:
Expand Down
14 changes: 11 additions & 3 deletions derex/runner/cli/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def mongodb(context: click.core.Context):
"Database", "Tables", "Django users", show_lines=True
)
table.add_row(
db["name"], str(db["sizeOnDisk"]), str(db["empty"]),
db["name"],
str(db["sizeOnDisk"]),
str(db["empty"]),
)
console.print(table)
break
Expand Down Expand Up @@ -113,7 +115,10 @@ def list_users():
@click.argument("user", type=str)
@click.argument("password", type=str)
@click.option(
"--role", type=str, multiple=True, help="Role to assign to the user",
"--role",
type=str,
multiple=True,
help="Role to assign to the user",
)
def create_user_cmd(user: str, password: str, role: Optional[Tuple]):
"""Create a mongodb user."""
Expand Down Expand Up @@ -166,7 +171,10 @@ def copy_mongodb(
@mongodb.command(name="reset-root-password")
@click.argument("current_password", type=str, required=False)
@click.option(
"--force", is_flag=True, default=False, help="Do not ask for confirmation",
"--force",
is_flag=True,
default=False,
help="Do not ask for confirmation",
)
def reset_mongodb_password_cmd(current_password: Optional[str], force: bool):
"""Reset the mongodb root user password with the one derived
Expand Down
5 changes: 4 additions & 1 deletion derex/runner/cli/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ def reset_mysql_cmd(context, force):
@mysql.command(name="reset-root-password")
@click.argument("current_password", type=str, required=True)
@click.option(
"--force", is_flag=True, default=False, help="Do not ask for confirmation",
"--force",
is_flag=True,
default=False,
help="Do not ask for confirmation",
)
def reset_mysql_password_cmd(current_password: str, force: bool):
"""Reset the mysql root user password with the one derived from
Expand Down
15 changes: 5 additions & 10 deletions derex/runner/compose_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class BaseServices:
@staticmethod
@hookimpl
def ddc_services_options() -> Dict[str, Union[str, List[str]]]:
"""See derex.runner.plugin_spec.ddc_services_options docstring.
"""
"""See derex.runner.plugin_spec.ddc_services_options docstring."""
services_compose_path = generate_ddc_services_compose()
options = [
"--project-name",
Expand All @@ -64,8 +63,7 @@ class BaseProject:
@staticmethod
@hookimpl
def ddc_project_options(project: Project) -> Dict[str, Union[str, List[str]]]:
"""See derex.runner.plugin_spec.ddc_project_options docstring
"""
"""See derex.runner.plugin_spec.ddc_project_options docstring"""
project_compose_path = generate_ddc_project_compose(project)
options = ["--project-name", project.name, "-f", str(project_compose_path)]
return {"options": options, "name": "base-project", "priority": "_begin"}
Expand All @@ -75,8 +73,7 @@ class LocalServices:
@staticmethod
@hookimpl
def ddc_services_options() -> Dict[str, Union[str, List[str]]]:
"""See derex.runner.plugin_spec.ddc_services_options docstring.
"""
"""See derex.runner.plugin_spec.ddc_services_options docstring."""
local_path = (
Path(os.getenv("DEREX_ETC_PATH", DEREX_ETC_PATH))
/ "docker-compose-services.yml"
Expand All @@ -95,8 +92,7 @@ class LocalProject:
@staticmethod
@hookimpl
def ddc_project_options(project: Project) -> Dict[str, Union[str, List[str]]]:
"""See derex.runner.plugin_spec.ddc_project_options docstring
"""
"""See derex.runner.plugin_spec.ddc_project_options docstring"""
options: List[str] = []
if project.local_compose:
options = ["-f", str(project.local_compose)]
Expand All @@ -111,8 +107,7 @@ class LocalProjectRunmode:
@staticmethod
@hookimpl
def ddc_project_options(project: Project) -> Dict[str, Union[str, List[str]]]:
"""See derex.runner.plugin_spec.ddc_project_options docstring
"""
"""See derex.runner.plugin_spec.ddc_project_options docstring"""
local_path = project.root / f"docker-compose-{project.runmode.value}.yml"
options: List[str] = []
if local_path.is_file():
Expand Down
3 changes: 1 addition & 2 deletions derex/runner/compose_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
def run_docker_compose(
compose_argv: List[str], dry_run: bool = False, exit_afterwards: bool = False
):
"""Run a docker-compose command with the specified arguments.
"""
"""Run a docker-compose command with the specified arguments."""
system_argv = sys.argv
try:
sys.argv = ["docker-compose"] + compose_argv
Expand Down
4 changes: 3 additions & 1 deletion derex/runner/ddc.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def check_docker():


def run_ddc_services(
argv: List[str], dry_run: bool = False, exit_afterwards: bool = False,
argv: List[str],
dry_run: bool = False,
exit_afterwards: bool = False,
):
"""Run a docker-compose command relative to the system services.
Plugin arguments are added to arguments passed in this function sorted by
Expand Down
18 changes: 6 additions & 12 deletions derex/runner/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@


def is_docker_working() -> bool:
"""Check if we can successfully connect to the docker daemon.
"""
"""Check if we can successfully connect to the docker daemon."""
try:
client.ping()
return True
Expand Down Expand Up @@ -113,8 +112,7 @@ def check_services(services: Iterable[str], max_seconds: int = 1) -> bool:


def load_dump(relpath):
"""Loads a mysql dump into the derex mysql database.
"""
"""Loads a mysql dump into the derex mysql database."""
from derex.runner.mysql import MYSQL_ROOT_PASSWORD

dump_path = abspath_from_egg("derex.runner", relpath)
Expand Down Expand Up @@ -180,8 +178,7 @@ def build_image(


def pull_images(image_names: List[str]):
"""Pull the given image to the local docker daemon.
"""
"""Pull the given image to the local docker daemon."""
# digest = client.api.inspect_distribution(image_name)["Descriptor"]["digest"]
for image_name in image_names:
print(f"Pulling image {image_name}")
Expand All @@ -193,8 +190,7 @@ def pull_images(image_names: List[str]):


def image_exists(needle: str) -> bool:
"""If the given image tag exist in the local docker repository, return True.
"""
"""If the given image tag exist in the local docker repository, return True."""
docker_client = docker.APIClient()
images = docker_client.images()
images.sort(key=lambda el: el["Created"], reverse=True)
Expand All @@ -207,8 +203,7 @@ def image_exists(needle: str) -> bool:


class BuildError(RuntimeError):
"""An error occurred while building a docker image
"""
"""An error occurred while building a docker image"""


def get_running_containers() -> Dict:
Expand Down Expand Up @@ -240,8 +235,7 @@ def get_exposed_container_names() -> List:


def run_minio_shell(command: str = "sh", tty: bool = True):
"""Invoke a minio shell
"""
"""Invoke a minio shell"""
minio_key = get_secret(DerexSecrets.minio)
os.system(
f"docker run {'-ti ' if tty else ''}--rm --network derex --entrypoint /bin/sh minio/mc -c '"
Expand Down
3 changes: 1 addition & 2 deletions derex/runner/logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def setup_logging():


def setup_logging_decorator(func):
"""Decorator to run the setup_logging function before the decorated one.
"""
"""Decorator to run the setup_logging function before the decorated one."""

def inner(*args, **kwargs):
setup_logging()
Expand Down
2 changes: 1 addition & 1 deletion derex/runner/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_mysql_client(
host: str,
user: str,
password: str,
port: Optional[int] = 3306,
port: int = 3306,
database: Optional[str] = None,
**kwargs,
) -> pymysql.cursors.Cursor:
Expand Down
4 changes: 2 additions & 2 deletions derex/runner/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def setup_plugin_manager():
# Used internally by `Registry` for each item in its sorted list.
# Provides an easier to read API when editing the code later.
# For example, `item.name` is more clear than `item[0]`.
_PriorityItem = namedtuple("PriorityItem", ["name", "priority"])
_PriorityItem = namedtuple("_PriorityItem", ["name", "priority"])


class Registry(object):
Expand Down Expand Up @@ -158,7 +158,7 @@ def _sort(self):
self._is_sorted = True

def add(self, key, value, location):
""" Register a key by location. """
"""Register a key by location."""
if len(self) == 0:
# This is the first item. Set priority to 50.
priority = 50
Expand Down
15 changes: 5 additions & 10 deletions derex/runner/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ def runmode(self, value: ProjectRunMode):

@property
def settings(self):
"""Name of the module to use as DJANGO_SETTINGS_MODULE
"""
"""Name of the module to use as DJANGO_SETTINGS_MODULE"""
current_status = self._get_status("settings", "default")
return self.get_available_settings()[current_status]

Expand All @@ -229,8 +228,7 @@ def settings_directory_path(self) -> Path:
return DEREX_DJANGO_SETTINGS_PATH

def _get_status(self, name: str, default: Optional[str] = None) -> Optional[str]:
"""Read value for the desired status from the project directory.
"""
"""Read value for the desired status from the project directory."""
filepath = self.private_filepath(name)
if filepath.exists():
return filepath.read_text()
Expand Down Expand Up @@ -265,8 +263,7 @@ def __init__(self, path: Union[Path, str] = None, read_only: bool = False):
(self.root / DEREX_RUNNER_PROJECT_DIR).mkdir()

def _load(self, path: Union[Path, str] = None):
"""Load project configuraton from the given directory.
"""
"""Load project configuraton from the given directory."""
if not path:
path = os.getcwd()
self.root = find_project_root(Path(path))
Expand Down Expand Up @@ -493,8 +490,7 @@ def get_openedx_customizations(self) -> dict:


def get_requirements_hash(path: Path) -> str:
"""Given a directory, return a hash of the contents of the text files it contains.
"""
"""Given a directory, return a hash of the contents of the text files it contains."""
hasher = hashlib.sha256()
logger.debug(
f"Calculating hash for requirements dir {path}; initial (empty) hash is {hasher.hexdigest()}"
Expand Down Expand Up @@ -537,5 +533,4 @@ def requirements_image_name(self, value):


class ProjectNotFound(ValueError):
"""No derex project could be found.
"""
"""No derex project could be found."""
3 changes: 1 addition & 2 deletions derex/runner/restore_dump.py.source
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def run_fixtures():


def execfile_py3(filepath, globals=None, locals=None):
"""Taken from https://stackoverflow.com/a/41658338
"""
"""Taken from https://stackoverflow.com/a/41658338"""
if globals is None:
globals = {}
globals.update({"__file__": filepath, "__name__": "__main__"})
Expand Down
Loading

0 comments on commit 0e169e6

Please sign in to comment.