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

Output flag #2452

Merged
merged 2 commits into from
Sep 30, 2021
Merged

Output flag #2452

merged 2 commits into from
Sep 30, 2021

Conversation

benjiqq
Copy link
Contributor

@benjiqq benjiqq commented Sep 6, 2021

What I did

add the flag "-o" to generate output files. this will write abi, bin and combined files. other options like ast, lll, opcodes need to be handled separately.

How I did it

add a flag to argparser and write the files

How to verify it

Description for the changelog

@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2021

Codecov Report

Attention: Patch coverage is 46.66667% with 8 lines in your changes missing coverage. Please review.

Project coverage is 84.67%. Comparing base (366e133) to head (cc4e024).
Report is 1076 commits behind head on master.

Files with missing lines Patch % Lines
vyper/cli/vyper_compile.py 46.66% 5 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2452      +/-   ##
==========================================
+ Coverage   84.66%   84.67%   +0.01%     
==========================================
  Files          94       94              
  Lines        9446     9453       +7     
  Branches     2208     2209       +1     
==========================================
+ Hits         7997     8004       +7     
  Misses        939      939              
  Partials      510      510              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR will read a lot cleaner if you use a single branch, and just select a file handle depending on the option. If -o is set, set f to args.output_path. Otherwise, set it to sys.stdout.

vyper/cli/vyper_compile.py Outdated Show resolved Hide resolved
vyper/cli/vyper_compile.py Outdated Show resolved Hide resolved
@benjiqq
Copy link
Contributor Author

benjiqq commented Sep 8, 2021

I think this PR will read a lot cleaner if you use a single branch, and just select a file handle depending on the option. If -o is set, set f to args.output_path. Otherwise, set it to sys.stdout.

agreed, will do

@benjiqq
Copy link
Contributor Author

benjiqq commented Sep 10, 2021

@charles-cooper changed the PR as you suggested. if two arguments for the flags are passed doesn't work well.

vyper foo.vy -f bytecode,abi -o foo.txt writes 1 file without breakline

not really sure, in that case auto recognizing the format would be useful (write an abi and bin file separately).

vyper/cli/vyper_compile.py Outdated Show resolved Hide resolved
vyper/cli/vyper_compile.py Outdated Show resolved Hide resolved
@benjiqq benjiqq force-pushed the outputflag branch 2 times, most recently from 011aafd to a11b0a4 Compare September 23, 2021 10:00
@charles-cooper
Copy link
Member

In order to avoid managing the resource manually (i.e. inserting calls to f.close() before every escape path), i think a bit of refactoring is in order. To abstract which file handle is being used, you could use a helper function

def cli_helper(f):
  ...

and then you would do something like

if args.output_path:
  with open(...) as f:
    cli_helper(f)
else:
  cli_helper(f)

@charles-cooper
Copy link
Member

Also, please use print(..., file=f) instead of f.write(). The latter is a break with existing semantics -- it breaks existing flags (like -f ir)

@benjiqq
Copy link
Contributor Author

benjiqq commented Sep 29, 2021

@charles-cooper updated. I added end="" so that the output does not end with newline.

@charles-cooper
Copy link
Member

charles-cooper commented Sep 29, 2021

@charles-cooper updated. I added end="" so that the output does not end with newline.

I think we can accept this PR but without the end="". That breaks the existing output format. I am open to the format change, but we should have an explicit discussion about it - either going through the VIP process or at least asking the major consumers of vyper if that's a breaking change for them first.

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final nit: (style guide: functions private to a module should be prefixed with _)

vyper/cli/vyper_compile.py Outdated Show resolved Hide resolved
vyper/cli/vyper_compile.py Outdated Show resolved Hide resolved
vyper/cli/vyper_compile.py Outdated Show resolved Hide resolved
@charles-cooper charles-cooper merged commit 030bde6 into vyperlang:master Sep 30, 2021
skellet0r pushed a commit to skellet0r/vyper that referenced this pull request Oct 3, 2021
Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants