Skip to content

Commit

Permalink
Merge pull request #927 from online-judge-tools/python-3.8
Browse files Browse the repository at this point in the history
feat!: bump minimum Python version to 3.8
  • Loading branch information
koba-e964 authored May 3, 2024
2 parents c9f92ac + 03fb3c5 commit f748599
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 53 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ 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
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
2 changes: 1 addition & 1 deletion onlinejudge_command/download_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
6 changes: 2 additions & 4 deletions onlinejudge_command/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
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
import onlinejudge_command.subcommand.login as subcommand_login
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__)

Expand Down Expand Up @@ -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.')
Expand Down
6 changes: 2 additions & 4 deletions onlinejudge_command/subcommand/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
7 changes: 3 additions & 4 deletions onlinejudge_command/subcommand/generate_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -71,7 +70,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():
Expand Down Expand Up @@ -125,7 +124,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:
Expand Down
3 changes: 1 addition & 2 deletions onlinejudge_command/subcommand/generate_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
4 changes: 2 additions & 2 deletions onlinejudge_command/subcommand/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
12 changes: 7 additions & 5 deletions onlinejudge_command/subcommand/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]))
Expand Down
8 changes: 3 additions & 5 deletions onlinejudge_command/subcommand/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -255,8 +253,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('')
Expand Down
2 changes: 1 addition & 1 deletion onlinejudge_command/subcommand/test_reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
7 changes: 2 additions & 5 deletions onlinejudge_command/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 9 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,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

Expand All @@ -37,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,
Expand All @@ -49,7 +52,6 @@ disable =
no-else-raise,
no-else-return,
no-member,
no-self-use,
redefined-builtin,
too-few-public-methods,
too-many-arguments,
Expand All @@ -61,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,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/implementation_language_guessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit f748599

Please sign in to comment.