Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X/dev #18

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/workflows/label.yml

This file was deleted.

31 changes: 31 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

# Install Python dependencies, run tests

name: PyTest

on:
push:
branches: [ "x/dev", "main" ]
pull_request:
branches: [ "x/dev", "main" ]

permissions:
contents: read

jobs:

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.13
- name: Install dependencies and run Test
run: |
python -m pip install --upgrade pip
python -m venv .venv
source .venv/bin/activate
pip install .[dev]
pytest -vv
31 changes: 27 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@

Dev maintenance Notes :

- Update version - python -m _version
- Run with debug-level logging : python -m dataset-tools.main --log debug
- Run with warning-level logging : python -m dataset-tools.main --log warn
- Run with info-level logging : python -m dataset-tools.main --log info
> - Dev Installation:
> ```
> pip install -e .
> ```

> - Reinstallation:
> ```
> pip uninstall dataset-tools
> ```

> - Update version:
> ```
> python -m _version
> ```

>
> ```
> - Run with debug logging :
> ```
> dataset-tools -d
> ```

> or

> ```
> python -m main --log debug
> ```
4 changes: 2 additions & 2 deletions _version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '0.6.dev2+ga1b3e8a.d20250103'
__version_tuple__ = version_tuple = (0, 6, 'dev2', 'ga1b3e8a.d20250103')
__version__ = version = '0.6.dev6+g6364d8d.d20250104'

Check warning

Code scanning / Pylint (reported by Codacy)

Constant name "version" doesn't conform to UPPER_CASE naming style Warning

Constant name "version" doesn't conform to UPPER_CASE naming style

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Constant name "version" doesn't conform to UPPER_CASE naming style Warning

Constant name "version" doesn't conform to UPPER_CASE naming style
__version_tuple__ = version_tuple = (0, 6, 'dev6', 'g6364d8d.d20250104')

Check warning

Code scanning / Pylint (reported by Codacy)

Constant name "version_tuple" doesn't conform to UPPER_CASE naming style Warning

Constant name "version_tuple" doesn't conform to UPPER_CASE naming style
55 changes: 41 additions & 14 deletions dataset_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
from importlib.metadata import version, PackageNotFoundError # setuptools-scm versioning
try:
__version__ = version("dataset-tools")
except PackageNotFoundError:
# package is not installed
pass
""" 初始化"""
# pylint: disable=line-too-long

Check warning

Code scanning / Prospector (reported by Codacy)

indentation is not a multiple of four (comment) (E114) Warning

indentation is not a multiple of four (comment) (E114)

Check warning

Code scanning / Prospector (reported by Codacy)

unexpected indentation (comment) (E116) Warning

unexpected indentation (comment) (E116)

import logging
import logging
from logging import Logger
# from re import I # setuptools-scm versioning

Check warning

Code scanning / Prospector (reported by Codacy)

indentation is not a multiple of four (comment) (E114) Warning

indentation is not a multiple of four (comment) (E114)

Check warning

Code scanning / Prospector (reported by Codacy)

unexpected indentation (comment) (E116) Warning

unexpected indentation (comment) (E116)
import os

Check warning

Code scanning / Prospector (reported by Codacy)

'os' imported but unused (F401) Warning

'os' imported but unused (F401)
import sys
from importlib.metadata import version, PackageNotFoundError

Check warning

Code scanning / Pylint (reported by Codacy)

No name 'metadata' in module 'importlib' Warning

No name 'metadata' in module 'importlib'

Check warning

Code scanning / Prospector (reported by Codacy)

Unable to import 'importlib.metadata' (import-error) Warning

Unable to import 'importlib.metadata' (import-error)
import logging
import argparse
from typing import Literal

Check warning

Code scanning / Pylint (reported by Codacy)

No name 'Literal' in module 'typing' Warning

No name 'Literal' in module 'typing'

Check warning

Code scanning / Prospector (reported by Codacy)

'typing.Literal' imported but unused (F401) Warning

'typing.Literal' imported but unused (F401)

log_level = "INFO"
msg_init = None
from rich.logging import RichHandler
from rich.console import Console
from rich.logging import RichHandler

if "pytest" not in sys.modules:
parser = argparse.ArgumentParser(description="Set logging level.")

Check warning

Code scanning / Pylint (reported by Codacy)

Constant name "parser" doesn't conform to UPPER_CASE naming style Warning

Constant name "parser" doesn't conform to UPPER_CASE naming style
group = parser.add_mutually_exclusive_group()

Check warning

Code scanning / Pylint (reported by Codacy)

Constant name "group" doesn't conform to UPPER_CASE naming style Warning

Constant name "group" doesn't conform to UPPER_CASE naming style


levels = {"d": "DEBUG", "w": "WARNING", "e": "ERROR", "c": "CRITICAL", "i": "INFO"}

Check warning

Code scanning / Pylint (reported by Codacy)

Constant name "levels" doesn't conform to UPPER_CASE naming style Warning

Constant name "levels" doesn't conform to UPPER_CASE naming style
choices = list(levels.keys()) + list(levels.values()) + [v.upper() for v in levels.values()]

Check warning

Code scanning / Pylint (reported by Codacy)

Constant name "choices" doesn't conform to UPPER_CASE naming style Warning

Constant name "choices" doesn't conform to UPPER_CASE naming style
for short, long in levels.items():
group.add_argument(f'-{short}', f'--{long.lower()}', f'--{long}',
action='store_true', help=f"Set logging level {long}")

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong continued indentation (add 3 spaces). Warning

Wrong continued indentation (add 3 spaces).

group.add_argument('--log-level', default='i', type=str,
choices=choices, help=f"Set the logging level ({choices})")

Check warning

Code scanning / Pylint (reported by Codacy)

Wrong continued indentation (remove 1 space). Warning

Wrong continued indentation (remove 1 space).

args = parser.parse_args()

Check warning

Code scanning / Pylint (reported by Codacy)

Constant name "args" doesn't conform to UPPER_CASE naming style Warning

Constant name "args" doesn't conform to UPPER_CASE naming style

# Resolve log_level from args dynamically
LOG_LEVEL = levels[next(iter([k for k,v in levels.items() if getattr(args, v.lower(), False)]), args.log_level)]

Check warning

Code scanning / Pylint (reported by Codacy)

Exactly one space required after comma Warning

Exactly one space required after comma
else:
LOG_LEVEL = "DEBUG"

EXC_INFO: bool = LOG_LEVEL != "i"

#begin routine
msg_init = None # pylint: disable=invalid-name

handler = RichHandler(console=Console(stderr=True))

if handler is None:
Expand All @@ -26,13 +49,17 @@
datefmt="%Y-%m-%d %H:%M:%S",
)
handler.setFormatter(formatter)
logging.root.setLevel(log_level)
logging.root.setLevel(LOG_LEVEL)
logging.root.addHandler(handler)

if msg_init is not None:
logger = logging.getLogger(__name__)
logger.info(msg_init)

log_level = getattr(logging, log_level)
log_level = getattr(logging, LOG_LEVEL)

Check warning

Code scanning / Pylint (reported by Codacy)

Constant name "log_level" doesn't conform to UPPER_CASE naming style Warning

Constant name "log_level" doesn't conform to UPPER_CASE naming style
logger = logging.getLogger(__name__)

try:
__version__ = version("dataset-tools")
except PackageNotFoundError:
logger.info("dataset-tools package is not installed. Did you run `pip install .`?", exc_info=EXC_INFO)
20 changes: 8 additions & 12 deletions dataset_tools/main.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
"""啟動程式,退出程式"""

import sys
import logging

from PyQt6 import QtWidgets # ignore

Check warning

Code scanning / Prospector (reported by Codacy)

Unable to import 'PyQt6' (import-error) Warning

Unable to import 'PyQt6' (import-error)

from dataset_tools import logger
from dataset_tools.ui import MainWindow # Import our main window class
import argparse

def main():
parser = argparse.ArgumentParser(description="Set the logging level via command line")

parser.add_argument('--log', default='WARNING', help='Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)')

args = parser.parse_args()

log_level = getattr(logging, args.log.upper())
logger = logging.getLogger(__name__)
"""Launch application"""
logger.info("%s","Launching application...")

Check warning

Code scanning / Pylint (reported by Codacy)

Exactly one space required after comma Warning

Exactly one space required after comma

from PyQt6.QtWidgets import QApplication
app = QApplication(sys.argv)
app = QtWidgets.QApplication(sys.argv) # pylint: disable=c-extension-no-member
window = MainWindow() # Initialize our main window.
window.show()
sys.exit(app.exec())
Expand Down
Loading
Loading