Skip to content

Commit

Permalink
Fix fleet installation
Browse files Browse the repository at this point in the history
  • Loading branch information
rfst committed Jul 4, 2024
1 parent 0ccb247 commit 8a51f58
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="mobt start -m R,F b" type="PythonConfigurationType" factoryName="Python">
<configuration default="false" name="mobt start -m R,F b -vv" type="PythonConfigurationType" factoryName="Python">
<module name="mob-tool" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
Expand All @@ -15,7 +15,7 @@
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/venv/bin/mobt" />
<option name="PARAMETERS" value="start -m R,F b" />
<option name="PARAMETERS" value="start -m R,F b -vv -sss" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="true" />
<option name="MODULE_MODE" value="false" />
Expand Down
9 changes: 0 additions & 9 deletions requirements.txt

This file was deleted.

12 changes: 1 addition & 11 deletions src/mobt/Controllers/boostrap_cli_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import logging
import os
import sys
from typing import Union


Expand All @@ -21,19 +18,12 @@ def _check_for_new_version():
mob_logger().debug(f'Failed to check for new version: {e.__class__.__name__} - {str(e)}')


def bootstrap_cli_app(log_level: int, check_for_new_version: bool = True):
from mobt.Logging.logging_utils import set_log_level
set_log_level(log_level)

def bootstrap_cli_app(check_for_new_version: bool = True):
from mobt.MobApp.GitPopenListener import GitPopenListener
from mobt.PopenObserver.PopenWrapper import PopenWrapper

PopenWrapper.add_listener(GitPopenListener())

if log_level > logging.CRITICAL:
sys.stdout = open(os.devnull, 'w')
sys.stderr = open(os.devnull, 'w')

if check_for_new_version:
_check_for_new_version()

Expand Down
32 changes: 4 additions & 28 deletions src/mobt/Controllers/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging

import click

from mobt.Controllers.common_params import common_params, AppContext, pass_state
from mobt.Controllers.done import done
from mobt.Controllers.next import next
from mobt.Controllers.start import start
Expand All @@ -11,39 +10,16 @@

@click.group()
@click.version_option(package_name='mob-tool')
@click.option(
'-v', '--verbose', count=True,
help='Enables verbose mode. The more -v options, the more verbose, up to -vv'
)
@click.option(
'-s', '--silent', count=True,
help='Disable all output except errors. To disable errors, use -sss'
)
def cli(verbose, silent):
log_level = logging.WARNING

if silent == 1:
log_level = logging.ERROR
elif silent == 2:
log_level = logging.CRITICAL
elif silent >= 3:
log_level = logging.CRITICAL + 1
elif verbose == 0:
# Default value set before the if
pass
elif verbose == 1:
log_level = logging.INFO
elif verbose == 2:
log_level = logging.DEBUG

@common_params
def cli():
from mobt.Controllers.boostrap_cli_app import bootstrap_cli_app

bootstrap_cli_app(
log_level=log_level,
check_for_new_version=True,
)



cli.add_command(start, 'start')
cli.add_command(next, 'next')
cli.add_command(done, 'done')
Expand Down
127 changes: 127 additions & 0 deletions src/mobt/Controllers/common_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import functools
import logging
import os
import sys
from dataclasses import dataclass

import click
from click import Context

class AppContext(object):

def __init__(self):
self.verbose = 0
self.silent = 0

@property
def log_level(self)->int:
log_level = logging.WARNING

if self.silent == 1:
log_level = logging.ERROR
elif self.silent == 2:
log_level = logging.CRITICAL
elif self.silent >= 3:
log_level = logging.CRITICAL + 1
elif self.verbose == 0:
# Default value set before the if
pass
elif self.verbose == 1:
log_level = logging.INFO
elif self.verbose == 2:
log_level = logging.DEBUG

return log_level

pass_state = click.make_pass_decorator(AppContext, ensure=True)

def verbosity_option(f):
def callback(ctx: Context, param, value):
state = ctx.ensure_object(AppContext)
state.verbose = value
return value
return click.option('-v', '--verbose', count=True,
help='Enables verbose mode. The more -v options, the more verbose, up to -vv',
is_eager=False,
expose_value=False,
callback=callback)(f)

def silent_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(AppContext)
state.silent = value
return value
return click.option('-s', '--silent', count=True,
help='Disable all output except errors. To disable errors, use -sss',
is_eager=True,
expose_value=False,
callback=callback)(f)

def common_options(f):
f = verbosity_option(f)
f = silent_option(f)
return f


# def pass_custom_context(f):
# @click.pass_context
# def new_func(ctx: Context, *args, **kwargs):
# if ctx.obj is None:
# ctx.obj = CustomContext()
# return ctx.invoke(f, ctx.obj, *args, **kwargs)
#
# return new_func


# @dataclass
# class CustomContext(object):
# verbose: int = 0
# silent: int = 0
# @property
# def log_level(self)->int:
# log_level = logging.WARNING
#
# if self.silent == 1:
# log_level = logging.ERROR
# elif self.silent == 2:
# log_level = logging.CRITICAL
# elif self.silent >= 3:
# log_level = logging.CRITICAL + 1
# elif self.verbose == 0:
# # Default value set before the if
# pass
# elif self.verbose == 1:
# log_level = logging.INFO
# elif self.verbose == 2:
# log_level = logging.DEBUG
#
# return log_level




ORIGINAL_STDOUT = sys.stdout
ORIGINAL_STDERR = sys.stderr
DEVNULL_STDOUT = click.open_file(os.devnull, 'w')
DEVNULL_STDERR = click.open_file(os.devnull, 'w')

def common_params(func):
# @pass_custom_context
@common_options
@functools.wraps(func)
@pass_state
def wrapper(state: AppContext, *args, **kwargs):
from mobt.Logging.logging_utils import set_log_level
log_level = state.log_level
set_log_level(log_level)

if log_level > logging.CRITICAL:
sys.stdout = DEVNULL_STDOUT
sys.stderr = DEVNULL_STDERR
else:
sys.stdout = ORIGINAL_STDOUT
sys.stderr = ORIGINAL_STDERR

return func(*args, **kwargs)

return wrapper
5 changes: 3 additions & 2 deletions src/mobt/Controllers/done.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click

from mobt import echo
from mobt.Controllers.common_params import common_params
from mobt.GitCli.BranchName import BranchName


Expand All @@ -18,8 +19,8 @@
help='Rebase all changes after squashing. If the rebase fails, the mob will be ended as usual, but the rebase '
'will be aborted.',
)
@click.pass_context
def done(ctx, branch_name: BranchName = None, message: str = None, do_not_try_to_rebase: bool = False) -> None:
@common_params
def done(branch_name: BranchName = None, message: str = None, do_not_try_to_rebase: bool = False) -> None:
"""
End the current mob session.
Expand Down
2 changes: 2 additions & 0 deletions src/mobt/Controllers/next.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import click

from mobt import echo
from mobt.Controllers.common_params import common_params


@click.command()
@common_params
def next():
"""
Pass the mob to the next team member. You must call this command even if you didn't make any changes in the code.
Expand Down
5 changes: 3 additions & 2 deletions src/mobt/Controllers/squash.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click

from mobt import echo
from mobt.Controllers.common_params import common_params
from mobt.GitCli.BranchName import BranchName


Expand All @@ -24,8 +25,8 @@
help='Rebase all changes after squashing. If the rebase fails, the mob will be ended as usual, but the rebase '
'will be aborted.',
)
@click.pass_context
def squash(ctx, branch_name: BranchName = None, push: bool = False, message: str = None, do_not_try_to_rebase: bool = False) -> None:
@common_params
def squash(branch_name: BranchName = None, push: bool = False, message: str = None, do_not_try_to_rebase: bool = False) -> None:
"""
Squash all the commits.
All git hooks will be executed for this final commit.
Expand Down
3 changes: 3 additions & 0 deletions src/mobt/Controllers/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import click

from mobt import echo, prompt

from mobt.Controllers.common_params import common_params
from mobt.GitCli.BranchName import BranchName
from mobt.LastTeamMembers.TeamMembers import TeamMembers
from mobt.SessionSettings.SessionSettings import SessionSettings
Expand Down Expand Up @@ -58,6 +60,7 @@ def __fetch_member_names(reset_members: bool) -> TeamMembers:
help='Force start a mob session even if the branch already exists and is not a mob branch, turning it into a mob '
'branch.',
)
@common_params
def start(
branch_name: BranchName = None, members: str = None, reset_members: bool = False,
force_if_non_mob_branch: bool = False
Expand Down
2 changes: 2 additions & 0 deletions src/mobt/Controllers/wip_commit.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import click

from mobt import echo
from mobt.Controllers.common_params import common_params


@click.command()
@common_params
def wip_commit():
"""
Create a WIP commit with all the local changes and push it.
Expand Down

0 comments on commit 8a51f58

Please sign in to comment.