Skip to content

Commit

Permalink
Merge branch 'write-endline'
Browse files Browse the repository at this point in the history
Resolve a merge conflict from Github.
  • Loading branch information
Daniele-Tentoni committed Apr 21, 2022
2 parents 667af39 + 46de8a6 commit 674d9f6
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 74 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/fsfe/reuse-tool
rev: latest
rev: v0.14.0
hooks:
- id: reuse

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.931
rev: v0.942
hooks:
- id: mypy

Expand All @@ -35,7 +35,7 @@ repos:
- id: pydocstyle

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.0
rev: v2.31.1
hooks:
- id: pyupgrade
args: [--py310-plus]
Expand Down
1 change: 1 addition & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Files:
*.rst
**/*.md
**/*.rst
examples/*
pyproject.toml
Copyright: 2022 Daniele Tentoni <[email protected]>
License: MIT
Expand Down
44 changes: 18 additions & 26 deletions cc_codechecker/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
class Configuration():
"""Define a complete configuration for code checker.
Raises:
ValueError: thrown if no challenges are given
ValueError: thrown if no projects are given
:raises [ValueError]: thrown if no challenges are given
:raises [ValueError]: thrown if no projects are given
"""

challenges: list[Challenge]
Expand Down Expand Up @@ -98,9 +97,8 @@ def dump(self) -> dict[str, Any]:
def run(self):
"""Run the configuration.
Args:
context (Namespace):
Application context from argparse.
:param context: Application context from argparse
:type context: Namespace
"""
score: int = 0
for challenge in self.challenges:
Expand All @@ -111,7 +109,7 @@ def run(self):

try:
with open('score.txt', 'w', encoding='locale') as score_writer:
score_writer.write(str(score))
score_writer.write(f'{str(score)}\n')
except OSError as ex:
print(f'Exception in writing scores: {ex}')

Expand All @@ -125,9 +123,8 @@ def set_configuration(configuration: Configuration):
Write the .codechecker.yml file in the root directory to save the current
configuration.
Args:
configuration (Configuration):
Configuration object to save.
:param configuration: Configuration object to save
:type configuration: Configuration
"""
try:
with open(FILE_NAME, 'w', encoding='locale') as file:
Expand All @@ -145,20 +142,15 @@ def get_configuration(
Read the codechecker.yml file in the root directory and read it to get the
actual configuration provided. If something given in dic, convert it.
Args:
dic (dict[str, Any], optional):
Dictionary of a yaml object. If left None, configuration will be read
from ``.codechecker.yml`` file inside root dir.
:param dic: Dictionary of a yaml object. If left None, configuration will be
read from ``.codechecker.yml`` file inside root dir.
Defaults to None.
Returns:
Optional[Configuration]:
The Configuration object produced. None if dictionary or file input is
invalid.
:type dic: dict[str, Any], optional
:return: The Configuration object produced. None if dictionary or file input
is invalid.
:rtype: Optional[Configuration]
"""
raw_configuration: dict[str, Any] = {}
if dic is not None:
raw_configuration = dic
raw_configuration: dict[str, Any] = dic if dic is not None else {}

if 'projects' not in raw_configuration:
raise ValueError('Necessary at least one project')
Expand All @@ -184,11 +176,11 @@ def get_configuration(
def load_projects(raw_projects: Any | dict) -> list[Project]:
"""Load projects from raw dictionary.
Args:
raw_projects (Any | dict): raw projects collection.
:param raw_projects: raw projects collection
:type raw_projects: Any | dict
Returns:
list[Project]: Projects list.
:return: Projects list
:rtype: list[Project]
"""
projects: list[Project] = []
if isinstance(raw_projects, str):
Expand Down
28 changes: 16 additions & 12 deletions cc_codechecker/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@

class Singleton(type):
"""Pythonic implementation of singleton."""

_instances: WeakValueDictionary = WeakValueDictionary()
_lock: Lock = Lock()

def __call__(cls, *args: Any, **kwargs: Any):
"""Call the single instance of a class.
:return: class instance
"""
with cls._lock:
if cls not in cls._instances:
instance = super().__call__(*args, **kwargs)
Expand All @@ -34,27 +39,26 @@ def __init__(
self,
options: Namespace = Namespace(verbose = False),
):
"""Creates a new Context object.
"""Create a new Context object.
This method instance a new Context object the first time, any other time it
return the instance created the first time.
Args:
options (Namespace, optional):
Options from command line for the current execution.
Defaults to Namespace(verbose = False).
:param options: Options from command line for the current execution.
Defaults to Namespace(verbose = False)
:type options: Namespace, optional
"""
self._options = options

@classmethod
def get(cls, name, default):
"""Gets the value of a specific option in the context.
def get(cls, name: str, default):
"""Get the value of a specific option in the context.
Args:
name ([type]): [description]
:param name: [description]
:type name: str
:return: Value of the options or the default value
Returns:
[type]: [description]
.. todo:: make this class more generic
"""
opts = Context().options()
if name in opts:
Expand All @@ -63,7 +67,7 @@ def get(cls, name, default):
return default

def options(self) -> Namespace:
"""Gets a deepcopy of options.
"""Get a deepcopy of options.
To update an options, use the set_option method. It will be implemented
before next major release.
Expand Down
3 changes: 2 additions & 1 deletion cc_codechecker/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# SPDX-License-Identifier: MIT

"""
Abstract Runner Module.
Abstract Runner Module
----------------------
Runner helps you to write plugins for cc_codechecker, providing facilities to
check requirements on current machine about installed softwares and running
Expand Down
5 changes: 5 additions & 0 deletions cc_codechecker/runners/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from cc_codechecker.runner import Runner

NOT_EXECUTABLE_ERROR = 126
MISSING_FILE_ERROR = 127


class Bash(Runner):
Expand Down Expand Up @@ -95,9 +96,13 @@ def run(self, *args, **kwargs) -> tuple[int, str]:
if run_verbose:
print(f'Bash run {bash_run}')

# TODO: Convert this if-chain into a map[err, str].
if bash_run.returncode is NOT_EXECUTABLE_ERROR and not bash_run.stdout:
bash_run.stdout = f'{program_file_name} is not executable'

if bash_run.returncode is MISSING_FILE_ERROR and not bash_run.stdout:
bash_run.stdout = f'{program_file_name} is missing'

return (bash_run.returncode, bash_run.stdout)

def _check_position(self) -> str:
Expand Down
Loading

0 comments on commit 674d9f6

Please sign in to comment.