Skip to content

Commit 889f218

Browse files
authored
Merge pull request #1 from online-judge-tools/master
Following online-judge-tools repository
2 parents ec1809d + 8e8185e commit 889f218

File tree

12 files changed

+63
-25
lines changed

12 files changed

+63
-25
lines changed

.github/workflows/format.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@ jobs:
1515
- name: Install dependencies
1616
run: pip3 install .[dev]
1717

18-
- name: Run tests
19-
run: |
20-
oj-verify -h
21-
pylint --disable=all --enable=unused-import onlinejudge_verify onlinejudge_bundle tests setup.py
22-
isort --check-only --diff onlinejudge_verify onlinejudge_bundle tests setup.py
23-
yapf --diff --recursive onlinejudge_verify onlinejudge_bundle tests setup.py | tee yapf.patch && test ! -s yapf.patch
24-
mypy onlinejudge_verify onlinejudge_bundle setup.py
18+
- name: Run --help
19+
run: oj-verify -h
20+
21+
- name: Run pylint
22+
run: pylint --disable=all --enable=unused-import onlinejudge_verify onlinejudge_bundle tests setup.py
23+
24+
- name: Run isort
25+
run: isort --check-only --diff onlinejudge_verify onlinejudge_bundle tests setup.py
26+
27+
- name: Run yapf
28+
run: yapf --diff --recursive onlinejudge_verify onlinejudge_bundle tests setup.py
29+
30+
- name: Run mypy
31+
run: mypy onlinejudge_verify onlinejudge_bundle setup.py

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,27 @@ Do the following steps:
1717
1. Register your language at `onlinejudge_verify/languages/list.py`
1818
1. Add tests to `tests/` dir if possible
1919
1. Update documents `.verify-helper/docs/static/document.md` (or `.verify-helper/docs/static/document.ja.md`)
20+
21+
22+
## CI to check format
23+
24+
[.github/workflows/format.yml](https://github.com/online-judge-tools/verification-helper/blob/master/.github/workflows/format.yml) defines the format checking.
25+
26+
You can run the format checking with the following commands. You can automatically run this with copying this script into your `.git/hooks/pre-commit`.
27+
28+
``` sh
29+
#!/bin/bash
30+
set -e
31+
32+
mypy onlinejudge_verify onlinejudge_bundle tests setup.py
33+
pylint --disable=all --enable=unused-import onlinejudge_verify onlinejudge_bundle tests setup.py
34+
isort --check-only --diff onlinejudge_verify onlinejudge_bundle tests setup.py
35+
yapf --diff --recursive onlinejudge_verify onlinejudge_bundle tests setup.py
36+
```
37+
38+
You can automatically fix some errors with the following commands.
39+
40+
``` sh
41+
isort onlinejudge_verify onlinejudge_bundle tests setup.py
42+
yapf --in-place --recursive onlinejudge_verify onlinejudge_bundle tests setup.py
43+
```

DESIGN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ link: [DESIGN.md](https://github.com/online-judge-tools/.github/blob/master/DESI
6161
- 言語個別の処理は [models.py](https://github.com/online-judge-tools/verification-helper/blob/master/onlinejudge_verify/languages/models.py) にある `Language` class と `LanguageEnvironment` class の sub-class として実装される。`Language` class と `LanguageEnvironment` class の区別は、ひとつの言語 (例: C++) が複数の環境 (例: G++, Clang, MSVC++ など) と関連付けられることから来る区別である。
6262
- 競技プログラミングの文脈では end-to-end tests や integration tests と unit tests の区別が比較的曖昧である。
6363
通常の文脈では end-to-end tests などは unit tests と比べて「実際と似た環境で動かせる」という利点と「遅い」「不安定」「失敗の原因が分かりにくい」という欠点がある ([参考](https://testing.googleblog.com/2015/04/just-say-no-to-more-end-to-end-tests.html))。しかしこれは通常の end-to-end tests が「GUI の操作」「ネットワーク通信」「ファイル書き込み」などの複雑で非純粋な要素を含むからである。競技プログラミングにおいてはそのような要素はないのでテストの結果は常に「安定」しており、またファイルの依存関係が疎であることを利用して最適に差分のみテストをすることで十分に「速い」テストが可能である。このため競技プログラミングにおいては end-to-end tests の欠点とされていた特徴の多くは隠れ、unit tests との差も曖昧となる。
64+
- `oj-bundle` コマンドは `#include "..."` の形の include のみを展開し `#include <...>` の形の include は展開しない。この仕様は、`#include <...>` が「システムの標準のヘッダ」に使われることが意図されており、また `#include "..."` が「カレントディレクトリなどにある自作のヘッダ」に使われことが意図されている、という事情による。参考として、プリプロセッサの挙動についての説明は <https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html> にある。
65+
- `oj-bundle` コマンドが [online-judge-tools/verification-helper](https://github.com/online-judge-tools/verification-helper) リポジトリにあるのは便宜上のものである。対応言語が増えるようなら他の新しいリポジトリに移されるだろう。
6466

6567

6668
## Security Considerations

onlinejudge_bundle/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def main(args: Optional[List[str]] = None) -> None:
2222
# parse command-line arguments
2323
parser = argparse.ArgumentParser()
2424
parser.add_argument('path', type=pathlib.Path)
25-
parser.add_argument('-I', metavar='dir', type=pathlib.Path, dest='iquote', default=pathlib.Path.cwd(), help='add the directory dir to the list of directories to be searched for header files during preprocessing (default: ".")')
25+
parser.add_argument('-I', metavar='dir', action='append', type=pathlib.Path, dest='iquote', default=[pathlib.Path.cwd()], help='add the directory dir to the list of directories to be searched for header files during preprocessing (default: ".")')
2626
parsed = parser.parse_args(args)
2727

2828
language = onlinejudge_verify.languages.list.get(parsed.path)
2929
assert language is not None
30-
sys.stdout.buffer.write(language.bundle(parsed.path, basedir=parsed.iquote))
30+
sys.stdout.buffer.write(language.bundle(parsed.path, basedir=parsed.iquote[0], options={'include_paths': parsed.iquote}))
3131

3232

3333
if __name__ == "__main__":

onlinejudge_verify/documentation/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _render_source_code_stat(stat: SourceCodeStat, *, basedir: pathlib.Path) ->
6868
try:
6969
language = onlinejudge_verify.languages.list.get(stat.path)
7070
assert language is not None
71-
bundled_code = language.bundle(stat.path, basedir=basedir).decode()
71+
bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
7272
except Exception:
7373
logger.warning("failed to bundle: %s", str(stat.path))
7474
bundled_code = traceback.format_exc()

onlinejudge_verify/languages/cplusplus.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ def list_dependencies(self, path: pathlib.Path, *, basedir: pathlib.Path) -> Lis
186186
joined_CXXFLAGS = ' '.join(map(shlex.quote, [*env.CXXFLAGS, '-I', str(basedir)]))
187187
return _cplusplus_list_depending_files(path.resolve(), CXX=env.CXX, joined_CXXFLAGS=joined_CXXFLAGS)
188188

189-
def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path) -> bytes:
190-
bundler = Bundler(iquotes=[basedir])
189+
def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path = pathlib.Path.cwd(), options: Dict[str, Any]) -> bytes:
190+
include_paths: List[pathlib.Path] = options['include_paths']
191+
assert isinstance(include_paths, list)
192+
bundler = Bundler(iquotes=include_paths)
191193
bundler.update(path)
192194
return bundler.get()
193195

onlinejudge_verify/languages/csharpscript.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def list_attributes(self, path: pathlib.Path, *, basedir: pathlib.Path) -> Dict[
109109
def list_dependencies(self, path: pathlib.Path, *, basedir: pathlib.Path) -> List[pathlib.Path]:
110110
return list(_get_csx_dependencies(path.resolve()))
111111

112-
def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path) -> bytes:
112+
def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path, options: Dict[str, Any]) -> bytes:
113113
raise NotImplementedError
114114

115115
def list_environments(self, path: pathlib.Path, *, basedir: pathlib.Path) -> Sequence[CSharpScriptLanguageEnvironment]:

onlinejudge_verify/languages/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def list_dependencies(self, path: pathlib.Path, *, basedir: pathlib.Path) -> Lis
4040
raise NotImplementedError
4141

4242
@abc.abstractmethod
43-
def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path) -> bytes:
43+
def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path, options: Dict[str, Any]) -> bytes:
4444
"""
4545
:throws Exception:
4646
:throws NotImplementedError:

onlinejudge_verify/languages/nim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def list_dependencies(self, path: pathlib.Path, *, basedir: pathlib.Path) -> Lis
8282
stk.append(child)
8383
return list(set(dependencies))
8484

85-
def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path) -> bytes:
85+
def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path, options: Dict[str, Any]) -> bytes:
8686
raise NotImplementedError
8787

8888
def is_verification_file(self, path: pathlib.Path, *, basedir: pathlib.Path) -> bool:

onlinejudge_verify/languages/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import textwrap
66
from logging import getLogger
7-
from typing import List, Sequence, Tuple
7+
from typing import Any, Dict, List, Sequence, Tuple
88

99
import importlab.environment
1010
import importlab.fs
@@ -78,7 +78,7 @@ class PythonLanguage(Language):
7878
def list_dependencies(self, path: pathlib.Path, *, basedir: pathlib.Path) -> List[pathlib.Path]:
7979
return _python_list_depending_files(path.resolve(), basedir)
8080

81-
def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path) -> bytes:
81+
def bundle(self, path: pathlib.Path, *, basedir: pathlib.Path, options: Dict[str, Any]) -> bytes:
8282
"""
8383
:throws NotImplementedError:
8484
"""

0 commit comments

Comments
 (0)