8000 Enable custom code generator function by kyuridenamida · Pull Request #68 · kyuridenamida/atcoder-tools · GitHub
[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable custom code generator function #68

Merged
merged 17 commits into from
Jan 12, 2019
Merged

Enable custom code generator function #68

merged 17 commits into from
Jan 12, 2019

Conversation

kyuridenamida
Copy link
Owner
@kyuridenamida kyuridenamida commented Jan 7, 2019

ほとんどリファクタ。
ユーザーは、型が (CodeGenArgs) => strであるmain関数を定義したpythonファイルを実装すればよい。
指定方法としては、以下のような感じ

[codestyle]
code_generator_file="~/myscripts/piyo.py"

というふうにconfigで指定できる。

CodeGenArgsの中身:

class CodeGenArgs:

    def __init__(self,
                 template: str,
                 format_: Format[Variable],
                 constants: ProblemConstantSet,
                 config: CodeStyleConfig):
        self.template = template
        self.format = format_
        self.constants = constants
        self.config = config

実装例:

...
def main(args: CodeGenArgs) -> str:
    code_parameters = CppCodeGenerator(
        args.format, args.config).generate_parameters()
    return render(
        args.template,
        mod=args.constants.mod,
        yes_str=args.constants.yes_str,
        no_str=args.constants.no_str,
        **code_parameters
    )

@codecov-io
Copy link
codecov-io commented Jan 7, 2019

Codecov Report

Merging #68 into master will increase coverage by 0.24%.
The diff coverage is 94.02%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #68      +/-   ##
==========================================
+ Coverage   91.45%   91.69%   +0.24%     
==========================================
  Files          36       37       +1     
  Lines        1731     1770      +39     
==========================================
+ Hits         1583     1623      +40     
+ Misses        148      147       -1
Impacted Files Coverage Δ
atcodertools/fileutils/normalize.py 100% <100%> (ø)
atcodertools/codegen/models/code_gen_args.py 100% <100%> (ø)
atcodertools/fileutils/create_contest_file.py 100% <100%> (ø) ⬆️
atcodertools/codegen/code_style_config.py 96.55% <100%> (+2.8%) ⬆️
atcodertools/codegen/code_generators/java.py 91.48% <100%> (ø)
atcodertools/codegen/code_generators/cpp.py 95.04% <100%> (ø)
atcodertools/tools/envgen.py 82.45% <75%> (-0.18%) ⬇️
...tcodertools/fmtprediction/models/variable_token.py 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f6ce4eb...aa93b31. Read the comment docs.

@kyuridenamida
Copy link
Owner Author
kyuridenamida commented Jan 7, 2019

実はtemplateとかもCodeGenArgsに含めたほうがよかったりするのかなあ。(出力をdictからstrにする)
(他のテンプレートエンジンを使いたいことを想定して)
@asi1024

@kyuridenamida kyuridenamida added this to the 1.0.6 milestone Jan 8, 2019
@kyuridenamida
Copy link
Owner Author

出力をstrにして困ることはないしstrにすることにした

@kyuridenamida kyuridenamida reopened this Jan 12, 2019
@kyuridenamida kyuridenamida merged commit 53946ea into master Jan 12, 2019
@kyuridenamida kyuridenamida self-assigned this Jan 12, 2019
@kyuridenamida kyuridenamida deleted the issue/55 branch April 17, 2021 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0