From 0fdcda9b144c5041294af688d2b27fb476987eb0 Mon Sep 17 00:00:00 2001 From: koba-e964 <3303362+koba-e964@users.noreply.github.com> Date: Fri, 3 May 2024 13:18:36 +0900 Subject: [PATCH 1/2] Bump minimum Python version to 3.8 --- .github/workflows/test.yml | 13 +++++-------- onlinejudge_command/subcommand/generate_input.py | 4 ++-- onlinejudge_command/subcommand/test.py | 4 ++-- onlinejudge_command/utils.py | 5 +---- setup.cfg | 5 +++-- setup.py | 2 +- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 608717d6..d2919a9f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,18 +10,15 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: [3.6, 3.7, 3.8] - include: - - os: ubuntu-20.04 - python-version: 3.6 - exclude: - - os: ubuntu-latest - python-version: 3.6 + python-version: + - '3.8' + - '3.10' + - '3.12' runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 diff --git a/onlinejudge_command/subcommand/generate_input.py b/onlinejudge_command/subcommand/generate_input.py index 2aa47496..cbeea835 100644 --- a/onlinejudge_command/subcommand/generate_input.py +++ b/onlinejudge_command/subcommand/generate_input.py @@ -71,7 +71,7 @@ def submit(f, *args, **kwargs): def write_result(input_data: bytes, output_data: Optional[bytes], *, input_path: pathlib.Path, output_path: pathlib.Path, print_data: bool, lock: Optional[threading.Lock] = None) -> None: # acquire lock to print logs properly, if in parallel - nullcontext = contextlib.ExitStack() # TODO: use contextlib.nullcontext after Python 3.7 + nullcontext = contextlib.nullcontext() with lock or nullcontext: if not input_path.parent.is_dir(): @@ -125,7 +125,7 @@ def check_randomness_of_generator(input_data: bytes, *, name: str, lock: Optiona return None input_digest = hashlib.sha1(input_data).digest() - nullcontext = contextlib.ExitStack() # TODO: use contextlib.nullcontext after Python 3.7 + nullcontext = contextlib.nullcontext() with lock or nullcontext: if len(generated_input_hashes) < limit: if input_digest in generated_input_hashes: diff --git a/onlinejudge_command/subcommand/test.py b/onlinejudge_command/subcommand/test.py index 4945a7a7..e4587012 100644 --- a/onlinejudge_command/subcommand/test.py +++ b/onlinejudge_command/subcommand/test.py @@ -255,8 +255,8 @@ def test_single_case(test_name: str, test_input_path: pathlib.Path, test_output_ elapsed: float = info['elapsed'] memory: Optional[float] = info['memory'] - # lock is require to avoid mixing logs if in parallel - nullcontext = contextlib.ExitStack() # TODO: use contextlib.nullcontext() after updating Python to 3.7 + # lock is required to avoid mixing logs if in parallel + nullcontext = contextlib.nullcontext() with lock or nullcontext: if lock is not None: logger.info('') diff --git a/onlinejudge_command/utils.py b/onlinejudge_command/utils.py index 4f404011..24c420d6 100644 --- a/onlinejudge_command/utils.py +++ b/onlinejudge_command/utils.py @@ -190,10 +190,7 @@ def webbrowser_register_explorer_exe() -> None: if not is_windows_subsystem_for_linux(): return instance = webbrowser.GenericBrowser('explorer.exe') - if sys.version_info < (3, 7): - webbrowser.register('explorer', None, instance) # TODO: remove this after Python 3.6 supprot is finished - else: - webbrowser.register('explorer', None, instance, preferred=True) # `preferred=True` solves the issue that terminal logs are cleared on cmd.exe with stopping using wslview via www-browser. TODO: remove `preferred=True` after https://github.com/wslutilities/wslu/issues/199 is fixed. + webbrowser.register('explorer', None, instance, preferred=True) # `preferred=True` solves the issue that terminal logs are cleared on cmd.exe with stopping using wslview via www-browser. TODO: remove `preferred=True` after https://github.com/wslutilities/wslu/issues/199 is fixed. def get_default_command() -> str: diff --git a/setup.cfg b/setup.cfg index bcc72cea..2c6a3e84 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,8 +7,9 @@ classifiers = Intended Audience :: Developers License :: OSI Approved :: MIT License Operating System :: OS Independent - Programming Language :: Python :: 3.5 - Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.12 Topic :: Internet :: WWW/HTTP Topic :: Software Development Topic :: Text Processing :: Markup :: HTML diff --git a/setup.py b/setup.py index 37665f5d..e36d7049 100755 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ url=version.__url__, license=version.__license__, description=version.__description__, - python_requires='>=3.6', + python_requires='>=3.8', install_requires=[ 'online-judge-api-client >= 10.9.0, < 11', 'colorama >= 0.3, < 1', From 03fb3c5d058cebcc1d63587da3e2a7a049c7d9b2 Mon Sep 17 00:00:00 2001 From: koba-e964 <3303362+koba-e964@users.noreply.github.com> Date: Fri, 3 May 2024 13:27:52 +0900 Subject: [PATCH 2/2] fix: upgrade mypy, pylint --- .github/workflows/format.yml | 15 +++++++++++---- .github/workflows/test.yml | 2 +- onlinejudge_command/download_history.py | 2 +- onlinejudge_command/main.py | 6 ++---- onlinejudge_command/subcommand/download.py | 6 ++---- onlinejudge_command/subcommand/generate_input.py | 3 +-- onlinejudge_command/subcommand/generate_output.py | 3 +-- onlinejudge_command/subcommand/login.py | 4 ++-- onlinejudge_command/subcommand/submit.py | 12 +++++++----- onlinejudge_command/subcommand/test.py | 4 +--- onlinejudge_command/subcommand/test_reactive.py | 2 +- onlinejudge_command/utils.py | 2 +- setup.cfg | 9 ++++++--- tests/implementation_language_guessing.py | 2 +- 14 files changed, 38 insertions(+), 34 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 64a989cf..764fb579 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -4,18 +4,25 @@ on: [push, pull_request] jobs: format: + strategy: + matrix: + python-version: + - '3.12' + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v1 + uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: ${{ matrix.python-version }} - name: Install dependencies - run: pip3 install .[dev] + run: | + pip3 install --upgrade setuptools + pip3 install .[dev] - name: Run --version run: oj --version diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2919a9f..acbe8953 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} diff --git a/onlinejudge_command/download_history.py b/onlinejudge_command/download_history.py index cb87db65..8be5372e 100644 --- a/onlinejudge_command/download_history.py +++ b/onlinejudge_command/download_history.py @@ -5,8 +5,8 @@ from logging import getLogger from typing import * -import onlinejudge_command.utils as utils from onlinejudge.type import Problem +from onlinejudge_command import utils logger = getLogger(__name__) diff --git a/onlinejudge_command/main.py b/onlinejudge_command/main.py index 1bd14509..66351be9 100644 --- a/onlinejudge_command/main.py +++ b/onlinejudge_command/main.py @@ -8,7 +8,6 @@ import onlinejudge.__about__ as api_version import onlinejudge_command.__0_workaround_for_conflict # pylint: disable=unused-import import onlinejudge_command.__about__ as version -import onlinejudge_command.log_formatter as log_formatter import onlinejudge_command.subcommand.download as subcommand_download import onlinejudge_command.subcommand.generate_input as subcommand_generate_input import onlinejudge_command.subcommand.generate_output as subcommand_generate_output @@ -16,8 +15,7 @@ import onlinejudge_command.subcommand.submit as subcommand_submit import onlinejudge_command.subcommand.test as subcommand_test import onlinejudge_command.subcommand.test_reactive as subcommand_test_reactive -import onlinejudge_command.update_checking as update_checking -import onlinejudge_command.utils as utils +from onlinejudge_command import log_formatter, update_checking, utils logger = getLogger(__name__) @@ -99,7 +97,7 @@ def main(args: Optional[List[str]] = None) -> 'NoReturn': try: sys.exit(run_program(parsed, parser=parser)) - except NotImplementedError as e: + except NotImplementedError: logger.debug('\n' + traceback.format_exc()) logger.error('NotImplementedError') logger.info('The operation you specified is not supported yet. Pull requests are welcome.') diff --git a/onlinejudge_command/subcommand/download.py b/onlinejudge_command/subcommand/download.py index bbd287e6..fd53a4ab 100644 --- a/onlinejudge_command/subcommand/download.py +++ b/onlinejudge_command/subcommand/download.py @@ -8,14 +8,12 @@ import requests.exceptions -import onlinejudge.dispatch as dispatch import onlinejudge_command.download_history -import onlinejudge_command.format_utils as format_utils -import onlinejudge_command.pretty_printers as pretty_printers -import onlinejudge_command.utils as utils +from onlinejudge import dispatch from onlinejudge.service.atcoder import AtCoderProblem from onlinejudge.service.yukicoder import YukicoderProblem from onlinejudge.type import SampleParseError, TestCase +from onlinejudge_command import format_utils, pretty_printers, utils logger = getLogger(__name__) diff --git a/onlinejudge_command/subcommand/generate_input.py b/onlinejudge_command/subcommand/generate_input.py index cbeea835..9c4fba98 100644 --- a/onlinejudge_command/subcommand/generate_input.py +++ b/onlinejudge_command/subcommand/generate_input.py @@ -11,8 +11,7 @@ from typing import * import onlinejudge_command.format_utils as fmtutils -import onlinejudge_command.pretty_printers as pretty_printers -import onlinejudge_command.utils as utils +from onlinejudge_command import pretty_printers, utils logger = getLogger(__name__) diff --git a/onlinejudge_command/subcommand/generate_output.py b/onlinejudge_command/subcommand/generate_output.py index 9637490b..6f59a2d0 100644 --- a/onlinejudge_command/subcommand/generate_output.py +++ b/onlinejudge_command/subcommand/generate_output.py @@ -8,8 +8,7 @@ from typing import * import onlinejudge_command.format_utils as fmtutils -import onlinejudge_command.pretty_printers as pretty_printers -import onlinejudge_command.utils as utils +from onlinejudge_command import pretty_printers, utils logger = getLogger(__name__) diff --git a/onlinejudge_command/subcommand/login.py b/onlinejudge_command/subcommand/login.py index 392c6587..0c30910d 100644 --- a/onlinejudge_command/subcommand/login.py +++ b/onlinejudge_command/subcommand/login.py @@ -9,9 +9,9 @@ import requests -import onlinejudge.dispatch as dispatch -import onlinejudge_command.utils as utils +from onlinejudge import dispatch from onlinejudge.type import LoginError, Service +from onlinejudge_command import utils logger = getLogger(__name__) diff --git a/onlinejudge_command/subcommand/submit.py b/onlinejudge_command/subcommand/submit.py index e50ccca8..075ed77a 100644 --- a/onlinejudge_command/subcommand/submit.py +++ b/onlinejudge_command/subcommand/submit.py @@ -7,11 +7,10 @@ from logging import getLogger from typing import * -import onlinejudge.dispatch as dispatch import onlinejudge_command.download_history -import onlinejudge_command.pretty_printers as pretty_printers -import onlinejudge_command.utils as utils +from onlinejudge import dispatch from onlinejudge.type import * +from onlinejudge_command import pretty_printers, utils logger = getLogger(__name__) @@ -142,7 +141,7 @@ def run(args: argparse.Namespace) -> bool: return False # confirm - guessed_unmatch = ([problem.get_url()] != guessed_urls) + guessed_unmatch = [problem.get_url()] != guessed_urls if guessed_unmatch: samples_text = ('samples of "{}'.format('", "'.join(guessed_urls)) if guessed_urls else 'no samples') logger.warning('the problem "%s" is specified to submit, but %s were downloaded in this directory. this may be mis-operation', problem.get_url(), samples_text) @@ -321,7 +320,10 @@ def guess_lang_ids_of_file(filename: pathlib.Path, code: bytes, language_dict, c saved_lang_ids = lang_ids lang_ids = [] for compiler in ('gcc', 'clang'): # use the latest for each compiler - ids = list(filter(lambda lang_id: parse_cplusplus_compiler(language_dict[lang_id]) in (compiler, None), saved_lang_ids)) + ids = [] + for lang_id in saved_lang_ids: + if parse_cplusplus_compiler(language_dict[lang_id]) in (compiler, None): + ids.append(lang_id) if not ids: continue ids.sort(key=lambda lang_id: (parse_cplusplus_version(language_dict[lang_id]) or '', language_dict[lang_id])) diff --git a/onlinejudge_command/subcommand/test.py b/onlinejudge_command/subcommand/test.py index e4587012..465b5ab0 100644 --- a/onlinejudge_command/subcommand/test.py +++ b/onlinejudge_command/subcommand/test.py @@ -14,9 +14,7 @@ from typing import * import onlinejudge_command.format_utils as fmtutils -import onlinejudge_command.output_comparators as output_comparators -import onlinejudge_command.pretty_printers as pretty_printers -import onlinejudge_command.utils as utils +from onlinejudge_command import output_comparators, pretty_printers, utils from onlinejudge_command.output_comparators import CompareMode logger = getLogger(__name__) diff --git a/onlinejudge_command/subcommand/test_reactive.py b/onlinejudge_command/subcommand/test_reactive.py index c31a9a64..31c58318 100644 --- a/onlinejudge_command/subcommand/test_reactive.py +++ b/onlinejudge_command/subcommand/test_reactive.py @@ -6,7 +6,7 @@ from logging import getLogger from typing import * -import onlinejudge_command.utils as utils +from onlinejudge_command import utils logger = getLogger(__name__) diff --git a/onlinejudge_command/utils.py b/onlinejudge_command/utils.py index 24c420d6..6bc21685 100644 --- a/onlinejudge_command/utils.py +++ b/onlinejudge_command/utils.py @@ -19,8 +19,8 @@ import colorama import requests -import onlinejudge.utils as utils import onlinejudge_command.__about__ as version +from onlinejudge import utils from onlinejudge.type import * logger = getLogger(__name__) diff --git a/setup.cfg b/setup.cfg index 2c6a3e84..79d48daf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,8 +20,8 @@ selenium = selenium >= 3.141.0 dev = isort == 5.7.0 - mypy == 0.812 - pylint == 2.7.0 + mypy == 1.10.0 + pylint == 3.1.0 yapf == 0.30.0 pytest >= 6.2.2, < 7 @@ -38,6 +38,8 @@ known_first_party = onlinejudge disable = broad-except, consider-using-enumerate, + consider-using-f-string, # TODO: remove this + consider-using-with, # TODO: remove this duplicate-code, fixme, invalid-name, @@ -50,7 +52,6 @@ disable = no-else-raise, no-else-return, no-member, - no-self-use, redefined-builtin, too-few-public-methods, too-many-arguments, @@ -62,6 +63,8 @@ disable = too-many-public-methods, too-many-return-statements, too-many-statements, + unnecessary-lambda-assignment, # TODO: remove this + unspecified-encoding, # TODO: remove this unused-argument, unused-wildcard-import, wildcard-import, diff --git a/tests/implementation_language_guessing.py b/tests/implementation_language_guessing.py index 8a17d639..fadcfd6b 100644 --- a/tests/implementation_language_guessing.py +++ b/tests/implementation_language_guessing.py @@ -2,8 +2,8 @@ import textwrap import unittest -import onlinejudge_command.subcommand.submit as submit from onlinejudge.type import Language, LanguageId +from onlinejudge_command.subcommand import submit # https://atcoder.jp/contests/language-test-ver1 languages_atcoder_3 = [