Skip to content
Open
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
12 changes: 6 additions & 6 deletions problemtools/ProblemPlasTeX/ProblemsetMacros.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import os
import os.path
import sys

from plasTeX.Base import Command, DimenCommand
from plasTeX.DOM import Node
from plasTeX.Base import Command
from plasTeX.Base import DimenCommand
from plasTeX.Logging import getLogger

log = getLogger()
Expand Down Expand Up @@ -56,7 +56,7 @@ def invoke(self, tex):
status.info(') ( verbatim %s ' % file2)
self.attributes['data2'] = self.read_sample_file(file2)
status.info(') ')
except (OSError, IOError):
except OSError:
log.warning('\nProblem opening files "%s" and "%s"', file1, file2)


Expand Down Expand Up @@ -97,7 +97,7 @@ def invoke(self, tex):
status.info(' ( sampletableinteractive %s ' % file)
self.attributes['messages'] = self.read_sample_interaction(file)
status.info(') ')
except (OSError, IOError):
except OSError:
log.warning('\nProblem opening file "%s"', file)


Expand Down Expand Up @@ -131,7 +131,7 @@ def invoke(self, tex):
try:
img = os.path.abspath(basetex.kpsewhich(f + e))
break
except (OSError, IOError):
except OSError:
pass

if img is None or not os.path.isfile(img):
Expand Down
14 changes: 7 additions & 7 deletions problemtools/ProblemPlasTeX/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import re
import os
import re
import shutil
import subprocess
from plasTeX.Renderers.PageTemplate import Renderer

from plasTeX.Filenames import Filenames
from plasTeX.Imagers import Image
from plasTeX.Logging import getLogger
from plasTeX.Renderers.PageTemplate import Renderer

log = getLogger()


# Adapted from plasTeX.Imagers.Imager class
class ImageConverter(object):
class ImageConverter:
fileExtension = '.png'
imageAttrs = ''
imageUnits = ''
Expand Down Expand Up @@ -74,7 +75,6 @@ def getImage(self, node):

except Exception as msg:
log.warning('%s in image "%s".' % (msg, name))
pass
return None


Expand Down Expand Up @@ -117,12 +117,12 @@ def processFileContent(self, document, s):
s = Renderer.processFileContent(self, document, s)

# Force XHTML syntax on empty tags
s = re.compile(r'(<(?:hr|br|img|link|meta)\b.*?)\s*/?\s*(>)', re.I | re.S).sub(r'\1 /\2', s)
s = re.compile(r'(<(?:hr|br|img|link|meta)\b.*?)\s*/?\s*(>)', re.IGNORECASE | re.DOTALL).sub(r'\1 /\2', s)

# Remove empty paragraphs
s = re.compile(r'<p>\s*</p>', re.I).sub(r'', s)
s = re.compile(r'<p>\s*</p>', re.IGNORECASE).sub(r'', s)

# Add a non-breaking space to empty table cells
s = re.compile(r'(<(td|th)\b[^>]*>)\s*(</\2>)', re.I).sub(r'\1&nbsp;\3', s)
s = re.compile(r'(<(td|th)\b[^>]*>)\s*(</\2>)', re.IGNORECASE).sub(r'\1&nbsp;\3', s)

return s
3 changes: 2 additions & 1 deletion problemtools/ProblemPlasTeX/graphicx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import plasTeX.Packages.graphics as graphics
from plasTeX.Packages import graphics

from problemtools.ProblemPlasTeX.ProblemsetMacros import _graphics_command, clean_width

# Reimplementation of graphicx package because plasTeX is broken and
Expand Down
3 changes: 2 additions & 1 deletion problemtools/ProblemPlasTeX/import.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import codecs
import os

from plasTeX.Base import Command
from plasTeX.Logging import getLogger

Expand All @@ -22,7 +23,7 @@ def invoke(self, tex):
try:
encoding = self.config['files']['input-encoding']
tex.input(codecs.open(fullpath, 'r', encoding, 'replace'))
except (OSError, IOError):
except OSError:
log.warning('\nProblem opening file "%s"', fullpath)
status.info(' ) ')
return []
7 changes: 3 additions & 4 deletions problemtools/ProblemPlasTeX/listingsutf8.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os

from plasTeX.Base import Command
from plasTeX.Logging import getLogger

import os
import io

log = getLogger()

# Implementation of (parts) of listingsutf8 package since PlasTeX does
Expand All @@ -14,7 +13,7 @@ class lstinputlisting(Command):
args = '* [ options:dict ] file:str'

def read_file(self, filename) -> str:
return io.open(filename, 'r', encoding='utf-8').read()
return open(filename, 'r', encoding='utf-8').read()

def invoke(self, tex) -> None:
super().invoke(tex)
Expand Down
5 changes: 3 additions & 2 deletions problemtools/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import collections
import os
import yaml
from collections.abc import Mapping
from pathlib import Path
from typing import Mapping

import yaml


class ConfigError(Exception):
Expand Down
6 changes: 4 additions & 2 deletions problemtools/context.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

import concurrent.futures
from concurrent.futures import ThreadPoolExecutor
import re
from typing import Callable, Pattern, ParamSpec, TypeVar
from collections.abc import Callable
from concurrent.futures import ThreadPoolExecutor
from re import Pattern
from typing import ParamSpec, TypeVar

_T = TypeVar('_T')
_P = ParamSpec('_P')
Expand Down
3 changes: 2 additions & 1 deletion problemtools/formatversion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import yaml
from enum import StrEnum
from pathlib import Path

import yaml


class FormatVersion(StrEnum):
LEGACY = 'legacy'
Expand Down
1 change: 0 additions & 1 deletion problemtools/judge/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import signal
import tempfile
from pathlib import Path

from typing import TYPE_CHECKING

from ..diagnostics import Diagnostics
Expand Down
6 changes: 2 additions & 4 deletions problemtools/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
class LanguageConfigError(Exception):
"""Exception class for errors in language configuration."""

pass


class Language(object):
class Language:
"""
Class representing a single language.
"""
Expand Down Expand Up @@ -151,7 +149,7 @@ def __matches_shebang(self, filename):
return self.shebang.search(shebang_line) is not None


class Languages(object):
class Languages:
"""A set of languages."""

def __init__(self, data=None):
Expand Down
3 changes: 1 addition & 2 deletions problemtools/md2html.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import hashlib
import html
import os
from pathlib import Path
import re
import shutil
import string
import subprocess
from pathlib import Path

import nh3

Expand Down
20 changes: 10 additions & 10 deletions problemtools/metadata.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import builtins
import copy
import datetime
import re
from dataclasses import dataclass, field
from enum import StrEnum
from pathlib import Path
from typing import Any, Literal, Self, Type, Union
from typing import Any, Literal, Self, Union
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field
import yaml
from pydantic import BaseModel, ConfigDict, Field

from . import config
from . import statement_util
from . import config, statement_util
from .formatversion import FormatVersion


Expand Down Expand Up @@ -41,7 +41,7 @@ class Person:
kattis: str | None = None

@classmethod
def from_string(cls: Type[Self], s: str) -> Self:
def from_string(cls: type[Self], s: str) -> Self:
match = re.match(r'^(.*?)\s+<(.*)>$', s.strip())
if match:
return cls(name=match.group(1), email=match.group(2))
Expand Down Expand Up @@ -99,7 +99,7 @@ class InputCredits:
"""

# Type in the input format is messy
PersonOrPersons = Union[str | list[Union[Person, str]]]
PersonOrPersons = Union[str | list[Person | str]]

authors: PersonOrPersons = field(default_factory=list)
contributors: PersonOrPersons = field(default_factory=list)
Expand All @@ -120,7 +120,7 @@ class Metadata2023_07(BaseModel):
type: list[ProblemType] | ProblemType = ProblemType.PASS_FAIL
version: str | None = None
credits: dict | str | None = None
source: list[Union[str, Source]] | Source | str = []
source: list[str | Source] | Source | str = []
license: License = License.UNKNOWN
rights_owner: str | None = None
embargo_until: datetime.datetime | None = None
Expand Down Expand Up @@ -165,7 +165,7 @@ class MetadataLegacy(BaseModel):
"""

problem_format_version: FormatVersion = FormatVersion.LEGACY
type: Literal['pass-fail'] | Literal['scoring'] = 'pass-fail'
type: Literal['pass-fail', 'scoring'] = 'pass-fail'
name: str | None = None
uuid: UUID | None = None
author: str | None = None
Expand Down Expand Up @@ -243,7 +243,7 @@ def is_submit_answer(self) -> bool:
return ProblemType.SUBMIT_ANSWER in self.type

@classmethod
def from_legacy(cls: Type[Self], legacy: MetadataLegacy, names_from_statements: dict[str, str]) -> Self:
def from_legacy(cls: builtins.type[Self], legacy: MetadataLegacy, names_from_statements: dict[str, str]) -> Self:
metadata = legacy.model_dump()
metadata['type'] = [metadata['type']]
# Support for *ancient* problems where names_from_statements is empty
Expand Down Expand Up @@ -293,7 +293,7 @@ def parse_author_field(author: str) -> list[Person]:
return cls.model_validate(metadata)

@classmethod
def from_2023_07(cls: Type[Self], md2023_07: Metadata2023_07) -> Self:
def from_2023_07(cls: builtins.type[Self], md2023_07: Metadata2023_07) -> Self:
metadata = md2023_07.model_dump()
metadata['type'] = [metadata['type']] if isinstance(metadata['type'], str) else metadata['type']
metadata['name'] = {'en': metadata['name']} if isinstance(metadata['name'], str) else metadata['name']
Expand Down
4 changes: 2 additions & 2 deletions problemtools/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .includes import DEFAULT_LANGUAGE, IncludeFile, LanguageIncludes, Includes, load_includes
from .includes import DEFAULT_LANGUAGE, IncludeFile, Includes, LanguageIncludes, load_includes

__all__ = [
'DEFAULT_LANGUAGE',
'IncludeFile',
'LanguageIncludes',
'Includes',
'LanguageIncludes',
'load_includes',
]
5 changes: 1 addition & 4 deletions problemtools/problem2html.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import os.path
import re
Expand All @@ -8,9 +7,7 @@
import sys
from pathlib import Path

from . import tex2html
from . import md2html
from . import statement_util
from . import md2html, statement_util, tex2html
from .version import add_version_arg


Expand Down
4 changes: 1 addition & 3 deletions problemtools/problem2pdf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import os
import re
Expand All @@ -10,8 +9,7 @@
import tempfile
from pathlib import Path

from . import template
from . import statement_util
from . import statement_util, template
from .version import add_version_arg


Expand Down
7 changes: 4 additions & 3 deletions problemtools/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
Problemtools.
"""

import re
import os
import re

from . import rutil
from .buildrun import BuildRun
from .checktestdata import Checktestdata
from .errors import ProgramError as ProgramError
from .program import Program
from .source import SourceCode
from .tools import get_tool as get_tool
from .tools import get_tool_path as get_tool_path
from .viva import Viva
from .tools import get_tool as get_tool, get_tool_path as get_tool_path
from . import rutil


def find_programs(
Expand Down
7 changes: 3 additions & 4 deletions problemtools/run/buildrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
Implementation of programs provided by a directory with build/run scripts.
"""

import logging
import os
import tempfile
import subprocess
import tempfile

import logging

from . import rutil
from .errors import ProgramError
from .program import Program
from . import rutil

log = logging.getLogger(__file__)

Expand Down
3 changes: 2 additions & 1 deletion problemtools/run/checktestdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import sys

from .executable import Executable


Expand Down Expand Up @@ -54,7 +55,7 @@ def run(
runtime (float): runtime of the Checktestdata process
in seconds
"""
(status, runtime) = super(Checktestdata, self).run(
(status, runtime) = super().run(
infile=infile, outfile=outfile, errfile=errfile, args=args, timelim=timelim, memlim=memlim, work_dir=work_dir
)
# This is ugly, switches the accept exit status and our accept
Expand Down
2 changes: 0 additions & 2 deletions problemtools/run/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@

class ProgramError(Exception):
"""Base exception class for errors within the run package."""

pass
Loading