Skip to content

Commit 780f84b

Browse files
authored
Merge pull request #351 from online-judge-tools/update/pylint
Enable pylint
2 parents f2424e8 + 24ad511 commit 780f84b

File tree

16 files changed

+126
-81
lines changed

16 files changed

+126
-81
lines changed

.github/workflows/format.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v1
10+
- uses: actions/checkout@v2
1111

1212
- name: Set up Python
13-
uses: actions/setup-python@v1
13+
uses: actions/setup-python@v2
14+
with:
15+
python-version: '3.8'
1416

1517
- name: Install dependencies
1618
run: pip3 install .[dev]
@@ -19,7 +21,7 @@ jobs:
1921
run: oj-verify -h
2022

2123
- name: Run pylint
22-
run: pylint --disable=all --enable=unused-import onlinejudge_verify onlinejudge_bundle tests setup.py
24+
run: pylint --rcfile=setup.cfg onlinejudge_verify onlinejudge_bundle tests setup.py
2325

2426
- name: Run isort
2527
run: isort --check-only --diff onlinejudge_verify onlinejudge_bundle tests setup.py

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ You can run the format checking with the following commands. You can automatical
3030
set -e
3131

3232
mypy onlinejudge_verify onlinejudge_bundle tests setup.py
33-
pylint --disable=all --enable=unused-import onlinejudge_verify onlinejudge_bundle tests setup.py
33+
pylint --rcfile=setup.cfg onlinejudge_verify onlinejudge_bundle tests setup.py
3434
isort --check-only --diff onlinejudge_verify onlinejudge_bundle tests setup.py
3535
yapf --diff --recursive onlinejudge_verify onlinejudge_bundle tests setup.py
3636
```

onlinejudge_verify/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
def set_config_path(config_path: pathlib.Path) -> None:
16-
global _loaded_config
16+
global _loaded_config # pylint: disable=invalid-name
1717
assert _loaded_config is None
1818
if not config_path.exists():
1919
_loaded_config = {}

onlinejudge_verify/documentation/build.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
logger = getLogger(__name__)
1919

20-
_resource_package = 'onlinejudge_verify_resources'
21-
_copied_static_file_paths: List[str] = [
20+
_RESOURCE_PACKAGE = 'onlinejudge_verify_resources'
21+
_COPIED_STATIC_FILE_PATHS: List[str] = [
2222
'_layouts/page.html',
2323
'_layouts/document.html',
2424
'_layouts/toppage.html',
@@ -107,9 +107,9 @@ def ext(relative_path: pathlib.Path) -> Dict[str, Any]:
107107
'icon': _get_verification_status_icon(stat.verification_status),
108108
}
109109

110-
data['_extendedDependsOn'] = [ext(path) for path in sorted(stat.depends_on, key=lambda x: str(x))]
111-
data['_extendedRequiredBy'] = [ext(path) for path in sorted(stat.required_by, key=lambda x: str(x))]
112-
data['_extendedVerifiedWith'] = [ext(path) for path in sorted(stat.verified_with, key=lambda x: str(x))]
110+
data['_extendedDependsOn'] = [ext(path) for path in sorted(stat.depends_on, key=str)]
111+
data['_extendedRequiredBy'] = [ext(path) for path in sorted(stat.required_by, key=str)]
112+
data['_extendedVerifiedWith'] = [ext(path) for path in sorted(stat.verified_with, key=str)]
113113

114114
return data
115115

@@ -120,13 +120,13 @@ def _render_source_code_stats_for_top_page(
120120
page_title_dict: Dict[pathlib.Path, str],
121121
basedir: pathlib.Path,
122122
) -> Dict[str, Any]:
123-
libraryCategories: Dict[str, List[Dict[str, str]]] = {}
124-
verificationCategories: Dict[str, List[Dict[str, str]]] = {}
123+
library_categories: Dict[str, List[Dict[str, str]]] = {}
124+
verification_categories: Dict[str, List[Dict[str, str]]] = {}
125125
for stat in source_code_stats:
126126
if utils.is_verification_file(stat.path, basedir=basedir):
127-
categories = verificationCategories
127+
categories = verification_categories
128128
else:
129-
categories = libraryCategories
129+
categories = library_categories
130130
category = str(stat.path.parent)
131131
if category not in categories:
132132
categories[category] = []
@@ -138,13 +138,13 @@ def _render_source_code_stats_for_top_page(
138138

139139
data: Dict[str, Any] = {}
140140
data['libraryCategories'] = []
141-
for category, pages in libraryCategories.items():
141+
for category, pages in library_categories.items():
142142
data['libraryCategories'].append({
143143
'name': category,
144144
'pages': pages,
145145
})
146146
data['verificationCategories'] = []
147-
for category, pages in verificationCategories.items():
147+
for category, pages in verification_categories.items():
148148
data['verificationCategories'].append({
149149
'name': category,
150150
'pages': pages,
@@ -195,8 +195,8 @@ def load_static_files(*, site_render_config: SiteRenderConfig) -> Dict[pathlib.P
195195
files[site_render_config.destination_dir / '_config.yml'] = yaml.safe_dump(site_render_config.config_yml).encode()
196196

197197
# load files in onlinejudge_verify_resources/
198-
for path in _copied_static_file_paths:
199-
files[site_render_config.destination_dir / pathlib.Path(path)] = pkg_resources.resource_string(_resource_package, path)
198+
for path in _COPIED_STATIC_FILE_PATHS:
199+
files[site_render_config.destination_dir / pathlib.Path(path)] = pkg_resources.resource_string(_RESOURCE_PACKAGE, path)
200200

201201
# overwrite with docs/static
202202
for src in site_render_config.static_dir.glob('**/*'):

onlinejudge_verify/documentation/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
logger = getLogger(__name__)
1515

16-
_resource_package = 'onlinejudge_verify_resources'
17-
_config_yml_path: str = '_config.yml'
16+
_RESOURCE_PACKAGE = 'onlinejudge_verify_resources'
17+
_CONFIG_YML_PATH: str = '_config.yml'
1818

1919

2020
def print_stats_json(*, jobs: int = 1) -> None:
@@ -31,7 +31,7 @@ def print_stats_json(*, jobs: int = 1) -> None:
3131

3232
def load_render_config(*, basedir: pathlib.Path) -> SiteRenderConfig:
3333
# load default _config.yml
34-
default_config_yml = yaml.safe_load(pkg_resources.resource_string(_resource_package, _config_yml_path))
34+
default_config_yml = yaml.safe_load(pkg_resources.resource_string(_RESOURCE_PACKAGE, _CONFIG_YML_PATH))
3535
assert default_config_yml is not None
3636
config_yml = default_config_yml
3737

onlinejudge_verify/languages/cplusplus_bundle.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
logger = getLogger(__name__)
1313

14-
bits_stdcxx_h = 'bits/stdc++.h'
14+
BITS_STDCXX_H = 'bits/stdc++.h'
1515

16-
cxx_standard_libs = {
16+
CXX_STANDARD_LIBS = {
1717
'algorithm',
1818
'array',
1919
'bitset',
@@ -61,7 +61,7 @@
6161
'vector',
6262
}
6363

64-
c_standard_libs = {
64+
C_STANDARD_LIBS = {
6565
'assert.h',
6666
'complex.h',
6767
'ctype.h',
@@ -93,11 +93,11 @@
9393
'wctype.h',
9494
}
9595

96-
cxx_c_origin_libs = {'c' + name[:-len('.h')] for name in c_standard_libs}
96+
CXX_C_ORIGIN_LIBS = {'c' + name[:-len('.h')] for name in C_STANDARD_LIBS}
9797

98-
bits_extcxx_h = 'bits/extc++.h'
98+
BITS_EXTCXX_H = 'bits/extc++.h'
9999

100-
ext_libs = {
100+
EXT_LIBS = {
101101
'ext/algorithm',
102102
'ext/array_allocator.h',
103103
'ext/atomicity.h',
@@ -134,9 +134,9 @@
134134
'ext/pb_ds/trie_policy.hpp',
135135
}
136136

137-
bits_stdtr1cxx_h = 'bits/stdtr1c++.h'
137+
BITS_STDTR1CXX_H = 'bits/stdtr1c++.h'
138138

139-
tr1_libs = {
139+
TR1_LIBS = {
140140
'tr1/array',
141141
'tr1/cctype',
142142
'tr1/cfenv',
@@ -219,15 +219,17 @@ def __init__(self, path: pathlib.Path, line: int, message: str, *args, **kwargs)
219219
super().__init__(message, *args, **kwargs) # type: ignore
220220

221221

222-
class Bundler(object):
222+
class Bundler:
223223
iquotes: List[pathlib.Path]
224224
pragma_once: Set[pathlib.Path]
225225
pragma_once_system: Set[str]
226226
result_lines: List[bytes]
227227
path_stack: Set[pathlib.Path]
228228
compiler: str
229229

230-
def __init__(self, *, iquotes: List[pathlib.Path] = [], compiler: str = os.environ.get('CXX', 'g++')) -> None:
230+
def __init__(self, *, iquotes: Optional[List[pathlib.Path]] = None, compiler: str = os.environ.get('CXX', 'g++')) -> None:
231+
if iquotes is None:
232+
iquotes = []
231233
self.iquotes = iquotes
232234
self.pragma_once = set()
233235
self.pragma_once_system = set()
@@ -362,20 +364,20 @@ def update(self, path: pathlib.Path) -> None:
362364
elif not is_toplevel:
363365
# #pragma once 系の判断ができない場合はそっとしておく
364366
self.result_lines.append(line)
365-
elif included in c_standard_libs or included in cxx_standard_libs or included in cxx_c_origin_libs:
366-
if bits_stdcxx_h in self.pragma_once_system:
367+
elif included in C_STANDARD_LIBS or included in CXX_STANDARD_LIBS or included in CXX_C_ORIGIN_LIBS:
368+
if BITS_STDCXX_H in self.pragma_once_system:
367369
self._line(i + 2, path)
368370
else:
369371
self.pragma_once_system.add(included)
370372
self.result_lines.append(line)
371-
elif included in ext_libs:
372-
if bits_extcxx_h in self.pragma_once_system:
373+
elif included in EXT_LIBS:
374+
if BITS_EXTCXX_H in self.pragma_once_system:
373375
self._line(i + 2, path)
374376
else:
375377
self.pragma_once_system.add(included)
376378
self.result_lines.append(line)
377-
elif included in tr1_libs:
378-
if bits_stdtr1cxx_h in self.pragma_once_system:
379+
elif included in TR1_LIBS:
380+
if BITS_STDTR1CXX_H in self.pragma_once_system:
379381
self._line(i + 2, path)
380382
else:
381383
self.pragma_once_system.add(included)
@@ -384,8 +386,8 @@ def update(self, path: pathlib.Path) -> None:
384386
# possibly: bits/*, tr2/* boost/*, c-posix library, etc.
385387
self.pragma_once_system.add(included)
386388
self.result_lines.append(line)
387-
if included in [bits_extcxx_h, bits_stdtr1cxx_h]:
388-
self.pragma_once_system.add(bits_stdcxx_h)
389+
if included in [BITS_EXTCXX_H, BITS_STDTR1CXX_H]:
390+
self.pragma_once_system.add(BITS_STDCXX_H)
389391
continue
390392

391393
# #include "..."

onlinejudge_verify/languages/list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def _get_dict() -> Dict[str, Language]:
23-
global _dict
23+
global _dict # pylint: disable=invalid-name
2424
if _dict is None:
2525
_dict = {}
2626
_dict['.cpp'] = CPlusPlusLanguage()
@@ -42,7 +42,7 @@ def _get_dict() -> Dict[str, Language]:
4242
if key in config:
4343
raise RuntimeError("You cannot overwrite existing language: .{}".format(ext))
4444
else:
45-
logger.warn("config.toml: languages.%s: Adding new languages using `config.toml` is supported but not recommended. Please consider making pull requests for your languages, see https://github.com/kmyk/online-judge-verify-helper/issues/116", ext)
45+
logger.warning("config.toml: languages.%s: Adding new languages using `config.toml` is supported but not recommended. Please consider making pull requests for your languages, see https://github.com/kmyk/online-judge-verify-helper/issues/116", ext)
4646
_dict['.' + ext] = UserDefinedLanguage(extension=ext, config=config)
4747
return _dict
4848

onlinejudge_verify/languages/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import onlinejudge_verify.languages.special_comments as special_comments
77

88

9-
class LanguageEnvironment(object):
9+
class LanguageEnvironment:
1010
@abc.abstractmethod
1111
def compile(self, path: pathlib.Path, *, basedir: pathlib.Path, tempdir: pathlib.Path) -> None:
1212
"""
@@ -20,7 +20,7 @@ def get_execute_command(self, path: pathlib.Path, *, basedir: pathlib.Path, temp
2020
raise NotImplementedError
2121

2222

23-
class Language(object):
23+
class Language:
2424
def list_attributes(self, path: pathlib.Path, *, basedir: pathlib.Path) -> Dict[str, Any]:
2525
"""
2626
:throws Exception:

onlinejudge_verify/languages/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def _python_list_depending_files(path: pathlib.Path, basedir: pathlib.Path) -> L
5656
res_graph = importlab.graph.ImportGraph.create(env, [str(path)])
5757
try:
5858
node_deps_pairs = res_graph.deps_list() # type: List[Tuple[str, List[str]]]
59-
except Exception:
60-
raise RuntimeError(f"Failed to analyze the dependency graph (circular imports?): {path}")
59+
except Exception as e:
60+
raise RuntimeError(f"Failed to analyze the dependency graph (circular imports?): {path}") from e
6161
logger.debug('the dependency graph of %s: %s', str(path), node_deps_pairs)
6262

6363
# collect Python files which are depended by the `path` and under `basedir`

onlinejudge_verify/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import onlinejudge.service
88
except ModuleNotFoundError:
99
print("Due to a known bug, the online-judge-tools is not yet properly installed. Please re-run $ pip3 install --force-reinstall online-judge-api-client")
10-
exit(1)
10+
exit(1) # pylint: disable=consider-using-sys-exit
1111
# pylint: enable=unused-import,ungrouped-imports
1212

1313
import argparse
@@ -99,7 +99,7 @@ def push_timestamp_to_branch() -> None:
9999
logger.info('$ git add %s && git commit && git push', str(path))
100100
if path.exists():
101101
subprocess.check_call(['git', 'add', str(path)])
102-
if subprocess.run(['git', 'diff', '--quiet', '--staged']).returncode:
102+
if subprocess.run(['git', 'diff', '--quiet', '--staged'], check=False).returncode:
103103
message = '[auto-verifier] verify commit {}'.format(os.environ['GITHUB_SHA'])
104104
subprocess.check_call(['git', 'commit', '-m', message])
105105
subprocess.check_call(['git', 'push', url, 'HEAD'])
@@ -149,7 +149,7 @@ def push_documents_to_gh_pages(*, src_dir: pathlib.Path, dst_branch: str = 'gh-p
149149
subprocess.check_call(['git', 'config', '--global', 'user.name', 'GitHub'])
150150
subprocess.check_call(['git', 'config', '--global', 'user.email', '[email protected]'])
151151
subprocess.check_call(['git', 'add', '.'])
152-
if subprocess.run(['git', 'diff', '--quiet', '--staged']).returncode:
152+
if subprocess.run(['git', 'diff', '--quiet', '--staged'], check=False).returncode:
153153
message = '[auto-verifier] docs commit {}'.format(os.environ['GITHUB_SHA'])
154154
subprocess.check_call(['git', 'commit', '-m', message])
155155
subprocess.check_call(['git', 'push', url, 'HEAD'])
@@ -219,7 +219,7 @@ def _delete_gitignore() -> None:
219219

220220
# check if .verify-helper/.gitignore exists
221221
gitignore_path = pathlib.Path('.verify-helper', '.gitignore')
222-
gitignore_checked_in = (subprocess.run(['git', 'ls-files', '--error-unmatch', str(gitignore_path)]).returncode == 0)
222+
gitignore_checked_in = (subprocess.run(['git', 'ls-files', '--error-unmatch', str(gitignore_path)], check=False).returncode == 0)
223223
if not gitignore_checked_in:
224224
return
225225
logger.warning('file %s exists in this Git repository. It should not be checked in.', str(gitignore_path))

0 commit comments

Comments
 (0)