Skip to content

Commit

Permalink
Introduced Linting (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
coldsofttech authored Apr 8, 2024
1 parent 0d9d901 commit 16f6b89
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 120
exclude = .git,__pycache__,venv
35 changes: 33 additions & 2 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,46 @@ on:
- '*'

jobs:
lint:
name: Python Linux (flake8)
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Run Lint
run: flake8 --verbose --color auto --count --statistics --format=json --output-file=flake8-report.json || echo "::set-output name=flake8_failed::true"
continue-on-error: true

- name: Upload Report
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: flake8-report
path: flake8-report.json

build_and_test:
name: Build and Test
runs-on: ubuntu-latest
needs: lint

steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.10'

Expand Down
26 changes: 15 additions & 11 deletions pyloggermanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,35 @@
"log",
"disable",
"shutdown",
"formatters",
"handlers",
"streams",
"textstyles",
"__author__",
"__description__",
"__name__",
"__version__"
]
__author__ = "coldsofttech"
__description__ = """
The pyloggermanager package is a vital logging framework for Python applications, providing developers with essential
tools to streamline logging operations. Its primary function is to simplify the recording and organization of log
messages, including critical information, debugging messages, errors, and warnings. By offering a centralized interface
The pyloggermanager package is a vital logging framework for Python applications, providing developers with essential
tools to streamline logging operations. Its primary function is to simplify the recording and organization of log
messages, including critical information, debugging messages, errors, and warnings. By offering a centralized interface
and robust functionalities, the package facilitates efficient monitoring and troubleshooting processes.
With its intuitive interface, the pyloggermanager package enables developers to seamlessly integrate logging mechanisms
into their applications. This allows for systematic recording and categorization of log entries based on severity
levels, enhancing readability and prioritization of issues. Moreover, the package offers flexibility in customizing
logging configurations to suit specific project requirements, including formatting, output destinations, and thread
With its intuitive interface, the pyloggermanager package enables developers to seamlessly integrate logging mechanisms
into their applications. This allows for systematic recording and categorization of log entries based on severity
levels, enhancing readability and prioritization of issues. Moreover, the package offers flexibility in customizing
logging configurations to suit specific project requirements, including formatting, output destinations, and thread
safety.
Beyond technical capabilities, the pyloggermanager package contributes to the reliability and maintainability of Python
applications. It establishes consistent logging practices, simplifying collaboration, code reviews, and issue
resolution across development teams. Overall, the pyloggermanager package is an invaluable asset for developers aiming
Beyond technical capabilities, the pyloggermanager package contributes to the reliability and maintainability of Python
applications. It establishes consistent logging practices, simplifying collaboration, code reviews, and issue
resolution across development teams. Overall, the pyloggermanager package is an invaluable asset for developers aiming
to implement robust logging solutions, ensuring efficient and resilient application performance.
"""
__name__ = "pyloggermanager"
__version__ = "0.1.0"
__version__ = "0.1.1"

from pyloggermanager import formatters
from pyloggermanager import handlers
Expand Down
2 changes: 1 addition & 1 deletion pyloggermanager/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def is_colorization_supported(cls) -> bool:
if term is None:
return False

if 'color' in os.popen(f'tput colors').read():
if 'color' in os.popen('tput colors').read():
return True

try:
Expand Down
6 changes: 3 additions & 3 deletions pyloggermanager/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
as CSV (Comma-Separated Values), JSON (JavaScript Object Notation), and the default text format.
Below listed formatter classes enable users to customize the appearance and structure of log messages
according to their requirements. By supporting different formats such as CSV and JSON, users have the
flexibility to choose the most suitable format for their logging needs, whether it's for human-readable
according to their requirements. By supporting different formats such as CSV and JSON, users have the
flexibility to choose the most suitable format for their logging needs, whether it's for human-readable
output, structured data storage, or integration with external systems.
Overall, the pyloggermanager.formatters package enhances the logger manager framework by offering
Overall, the pyloggermanager.formatters package enhances the logger manager framework by offering
versatile formatting options for log messages, catering to a wide range of logging use cases and
preferences.
"""
Expand Down
10 changes: 5 additions & 5 deletions pyloggermanager/formatters/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def format_str(self, value: str | dict) -> None:

self._format_str = value

def format(self, record: 'Record') -> str:
def format(self, record) -> str:
"""
Formats the log record into a string based on the provided record object.
Expand Down Expand Up @@ -172,7 +172,7 @@ def format_exception(
else:
return ''

def _log_attributes(self, record: 'Record', date_format: str) -> dict:
def _log_attributes(self, record, date_format: str) -> dict:
"""
Extracts and organizes various attributes of a 'Record' object into a dictionary format.
Expand Down Expand Up @@ -226,7 +226,7 @@ def __init__(self, format_str: str = DEFAULT_FORMAT, date_format: str = DATE_FOR

super().__init__(format_str, date_format)

def format(self, record: 'Record') -> str:
def format(self, record) -> str:
"""
Formats the given log record according to the format string.
Expand Down Expand Up @@ -293,7 +293,7 @@ def _is_valid_csv_format(format_str: str) -> bool:
"""
return len(format_str.split(',')) >= 2

def format(self, record: 'Record') -> str:
def format(self, record) -> str:
"""
Formats the given log record into a CSV string based on the specified format string.
Expand Down Expand Up @@ -356,7 +356,7 @@ def _validate_format_str(format_str: dict) -> None:
except ValueError:
raise ValueError("Invalid JSON format string.")

def format(self, record: 'Record') -> str:
def format(self, record) -> str:
"""
Formats the given log record into a JSON string.
Expand Down
4 changes: 2 additions & 2 deletions pyloggermanager/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
__name__ = "pyloggermanager.handlers"
__description__ = """
The pyloggermanager.handlers package provides classes responsible for handling log records
generated within the logger manager framework. It includes various handlers for processing log
generated within the logger manager framework. It includes various handlers for processing log
messages, directing them to different destinations, and performing actions based on logging levels.
Below listed handler classes offer flexibility and customization options for managing log records
within the logger manager framework. They enable users to define how log messages are processed,
within the logger manager framework. They enable users to define how log messages are processed,
where they are directed, and how they are formatted, catering to various logging scenarios and
deployment environments.
Expand Down
24 changes: 12 additions & 12 deletions pyloggermanager/handlers/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
self,
name: str = None,
level: int = 20,
colorization: 'Colorization' = None,
colorization=None,
formatter: Formatter = DefaultFormatter()
) -> None:
"""
Expand Down Expand Up @@ -79,7 +79,7 @@ def __init__(
self._release_lock()

@property
def colorization(self) -> 'Colorization':
def colorization(self):
"""
Gets the colorization object for the handler.
Expand All @@ -88,7 +88,7 @@ def colorization(self) -> 'Colorization':
return self._colorization

@colorization.setter
def colorization(self, value: 'Colorization') -> None:
def colorization(self, value) -> None:
"""
Sets the colorization object for the handler.
Expand Down Expand Up @@ -199,7 +199,7 @@ def close(self) -> None:
finally:
self._release_lock()

def emit(self, record: 'Record', ignore_display: bool) -> None:
def emit(self, record, ignore_display: bool) -> None:
"""
Abstract method to emit a log record.
Expand All @@ -208,7 +208,7 @@ def emit(self, record: 'Record', ignore_display: bool) -> None:
"""
raise NotImplementedError('emit() method must be implemented in subclasses.')

def format(self, record: 'Record') -> str:
def format(self, record) -> str:
"""
Formats a log record using the handler's formatter.
Expand All @@ -232,7 +232,7 @@ def get_handlers() -> list[Any]:
"""
return _handlersList

def handle(self, record: 'Record', ignore_display: bool) -> None:
def handle(self, record, ignore_display: bool) -> None:
"""
Handles a log record.
Expand Down Expand Up @@ -262,7 +262,7 @@ def __init__(
self,
name: str = None,
level: int = 20,
colorization: 'Colorization' = None,
colorization=None,
formatter: Formatter = DefaultFormatter(),
stream: Stream = TerminalStream()
) -> None:
Expand Down Expand Up @@ -317,7 +317,7 @@ def close(self) -> None:
self._stream.close()
super().close()

def emit(self, record: 'Record', ignore_display: bool = True) -> None:
def emit(self, record, ignore_display: bool = True) -> None:
"""
Emits the log record by formatting it, colorizing the message, and writing it to the stream.
Expand Down Expand Up @@ -356,7 +356,7 @@ def __init__(
self,
name: str = None,
level: int = 20,
colorization: 'Colorization' = None,
colorization=None,
formatter: Formatter = DefaultFormatter(),
stream: Stream = StdoutStream()
) -> None:
Expand Down Expand Up @@ -416,7 +416,7 @@ def close(self) -> None:
self._stream.close()
super().close()

def emit(self, record: 'Record', ignore_display: bool) -> None:
def emit(self, record, ignore_display: bool) -> None:
"""
Emits a log record to the stream.
Expand Down Expand Up @@ -461,7 +461,7 @@ def __init__(
self,
name: str = None,
level: int = 20,
colorization: 'Colorization' = None,
colorization=None,
formatter: Formatter = DefaultFormatter(),
file_name: str = 'default.log',
file_mode: str = 'a',
Expand Down Expand Up @@ -596,7 +596,7 @@ def close(self) -> None:
self._close_file_stream()
super().close()

def emit(self, record: 'Record', ignore_display: bool) -> None:
def emit(self, record, ignore_display: bool) -> None:
"""
Emits a log record by writing it to the log file.
Expand Down
10 changes: 5 additions & 5 deletions pyloggermanager/streams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
can be directed to, allowing for flexible and customizable logging behaviour.
Below listed stream classes offer versatility in directing log messages to different output
channels, allowing users to customize logging behavior based on their application's requirements
and environment configuration. By supporting various stream types, the logger manager framework
enables users to control where log records are displayed or stored, facilitating effective logging
channels, allowing users to customize logging behavior based on their application's requirements
and environment configuration. By supporting various stream types, the logger manager framework
enables users to control where log records are displayed or stored, facilitating effective logging
and troubleshooting processes.
Overall, the pyloggermanager.streams package enhances the functionality of the logger manager framework
Overall, the pyloggermanager.streams package enhances the functionality of the logger manager framework
by providing a range of stream classes for directing log messages to different output channels. Users can
leverage these classes to tailor their logging setup to suit their specific needs and preferences, ensuring
leverage these classes to tailor their logging setup to suit their specific needs and preferences, ensuring
efficient management and processing of log records.
"""

Expand Down
12 changes: 6 additions & 6 deletions pyloggermanager/textstyles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
__name__ = "pyloggermanager.textstyles"
__description__ = """
The pyloggermanager.textstyles package provides utilities for defining and applying text styles
to log messages within the logger manager framework. It includes classes for specifying text
colors, background colors, and text effects, allowing users to customize the appearance of log
to log messages within the logger manager framework. It includes classes for specifying text
colors, background colors, and text effects, allowing users to customize the appearance of log
messages according to their preferences.
This package is designed to enhance the visual representation of log messages by providing a
flexible and intuitive way to apply various text styles. By incorporating these text styles
This package is designed to enhance the visual representation of log messages by providing a
flexible and intuitive way to apply various text styles. By incorporating these text styles
into log messages, users can improve readability, emphasize important information, and differentiate
between different types of log entries.
Overall, the pyloggermanager.textstyles package complements the logger manager framework by
offering tools for creating visually appealing and informative log messages, contributing to a
Overall, the pyloggermanager.textstyles package complements the logger manager framework by
offering tools for creating visually appealing and informative log messages, contributing to a
more effective logging experience.
"""

Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_get_handlers_none(self):

def test_get_handlers_valid(self):
"""Test if the get handlers returns expected values."""
handler = Handler()
Handler()
assert len(Handler.get_handlers()) > 0

def test_handle_valid(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_colorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_colorize_message_regex(self):
f'Test error message'
f'{Colorization.RESET}'
) if Colorization.is_colorization_supported() else (
f'Test error message'
'Test error message'
)
self.assertEqual(Colorization.colorize_message('Test error message'), expected_output)

Expand All @@ -114,7 +114,7 @@ def test_colorize_message_regex(self):
f'Test warning message'
f'{Colorization.RESET}'
) if Colorization.is_colorization_supported() else (
f'Test warning message'
'Test warning message'
)
self.assertEqual(Colorization.colorize_message('Test warning message'), expected_output)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_pyloggermanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def tearDown(self) -> None:
if self.logger is not None:
for handler in self.logger.handlers:
handler.close()
if type(handler) == FileHandler:
if handler is FileHandler:
try:
file_name = str(handler.filename)
os.remove(file_name)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pyloggermanager_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def cleanup(logger):
"""Clean up method"""
for handler in logger.handlers:
handler.close()
if type(handler) == FileHandler:
if handler is FileHandler:
try:
file_name = str(handler.filename)
os.remove(file_name)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pyloggermanager_critical.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def cleanup(logger):
"""Clean up method"""
for handler in logger.handlers:
handler.close()
if type(handler) == FileHandler:
if handler is FileHandler:
try:
file_name = str(handler.filename)
os.remove(file_name)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pyloggermanager_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def cleanup(logger):
"""Clean up method"""
for handler in logger.handlers:
handler.close()
if type(handler) == FileHandler:
if handler is FileHandler:
try:
file_name = str(handler.filename)
os.remove(file_name)
Expand Down
Loading

0 comments on commit 16f6b89

Please sign in to comment.