variants icon indicating copy to clipboard operation
variants copied to clipboard

Fix Code Generation with GYB

Open arthurpalves opened this issue 3 years ago • 4 comments

What does this PR do

  • When capturing the output of a Bash command, select either stdout or stderr to be captured.
  • Require python2.7 to run gyb and default to a fatalError if not available. This prints an appropriate message to the user.
  • It defaults to a fatalError when generating Variants.Secrets if environment variable used by a custom config doesn't exist.

How can it be tested

  • Run variants switch or variants setup without python2.7 installed or in your executables path.
  • Run variants switch or variants setup with at least one custom config whose env: true but value points to a non-existing environment variable.

Task

resolves #204

Checklist:

  • [x] I ran make validation locally with success
  • [x] I have not introduced new bugs
  • [x] My code follows the style guidelines of this project
  • [x] I have performed a self-review of my own code
  • [x] I have commented on my code, particularly in hard-to-understand areas
  • [x] I have made corresponding changes to the documentation
  • [x] My changes generate no new errors

arthurpalves avatar Dec 14 '22 17:12 arthurpalves

@arthurpalves Can we update GYB to latest so we use python3 instead of python2? Since Mac doesn't include python2 by default anymore users need to manually install in the end, so it's better if we install the later version already. It seems GYB already have support to python3: https://github.com/apple/swift/blob/main/utils/gyb.py

GMinucci avatar Dec 23 '22 09:12 GMinucci

@arthurpalves Can we update GYB to latest so we use python3 instead of python2? Since Mac doesn't include python2 by default anymore users need to manually install in the end, so it's better if we install the later version already. It seems GYB already have support to python3: https://github.com/apple/swift/blob/main/utils/gyb.py

this is a very valid point. Using python2 require extra configuration and probably will cause issues for CI. can we move on with this PR @arthurpalves ?

ghost avatar Jan 18 '23 12:01 ghost

@GMinucci @obackbase can one of you try using gyb with python3 support? I've tried it before changing this PR but it fails every time:

Traceback (most recent call last):
  File "/usr/local/lib/variants/utils/gyb", line 3, in <module>
    gyb.main()
  File "/usr/local/lib/variants/utils/gyb.py", line 1254, in main
    f.write(execute_template(ast, args.line_directive, **bindings))
  File "/usr/local/lib/variants/utils/gyb.py", line 1124, in execute_template
    ast.execute(execution_context)
  File "/usr/local/lib/variants/utils/gyb.py", line 626, in execute
    x.execute(context)
  File "/usr/local/lib/variants/utils/gyb.py", line 712, in execute
    result = eval(self.code, context.local_bindings)
  File "/Users/arthura/Projects/PERSONAL/variants/samples/ios/Proj/Proj/Variants/Variants.swift.gyb", line 38, in <module>
    %{ salt = [ord(byte) for byte in os.urandom(64)] }%
  File "/Users/arthura/Projects/PERSONAL/variants/samples/ios/Proj/Proj/Variants/Variants.swift.gyb", line 38, in <listcomp>
    %{ salt = [ord(byte) for byte in os.urandom(64)] }%
TypeError: ord() expected string of length 1, but int found

arthurpalves avatar Mar 02 '23 09:03 arthurpalves

@GMinucci had the chance to check this?

arthurpalves avatar Jun 13 '23 10:06 arthurpalves

This PR also fixes #240

GMinucci avatar Dec 10 '24 10:12 GMinucci

Fails
:no_entry_sign:

danger-swift failed.

Log

[31mERROR: Failed to parse JSON: valueNotFound(Swift.Dictionary<Swift.String, Foundation.JSONValue>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "danger", intValue: nil), CodingKeys(stringValue: "github", intValue: nil), CodingKeys(stringValue: "reviews", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0), CodingKeys(stringValue: "user", intValue: nil)], debugDescription: "Cannot get keyed decoding container -- found null value instead", underlyingError: nil))
[0;0m[31mERROR: Dangerfile eval failed at Dangerfile.swift
[0;0m[31mERROR: Could not get the results JSON file at /tmp/danger/6EE1AE74-A513-4C32-AB71-9D569D881742/danger-response.json
[0;0m

Generated by :no_entry_sign: dangerJS against 1f939e8d124cc632c3ae6401682c3a1bd5dcbf24

github-actions[bot] avatar Dec 10 '24 16:12 github-actions[bot]