Commit Graph

22 Commits

Author SHA1 Message Date
Fraser Waters 3560333ae6
Clean up uses of .Error() ()
Combination of a few cleanups.

1. Don't call .Error() on errors that are being passed to "%s" format
functions. Format will call `Error()` itself.
2. Don't call assert.Error then assert.Equal/Contains, just use
assert.ErrorEqual/ErrorContains instead.
3. Use "%w" if appropriate, instead of "%v"/"%s".
2023-12-20 15:54:06 +00:00
Zaid Ajaj ef628d7ab0 Propagate SkipRangeTypechecking option down to program components 2023-07-14 19:00:38 +02:00
Zaid Ajaj 5841f220b1 Consistently use the same non-strict bind options when applicable 2023-07-13 15:16:06 +02:00
Zaid Ajaj fe5e65f0f4 Allow binding unsupported range and collection types in non-strict mode for pulumi convert 2023-07-12 19:13:57 +02:00
Zaid Ajaj ed02926277 Allow generating code for unknown invokes in non-strict mode 2023-07-10 15:05:18 +02:00
Zaid Ajaj 7ab7ad5a58 Prefer output-versioned invokes in generated programs for nodejs and python 2023-06-23 02:42:18 +02:00
bors[bot] d69e5f2d26
Merge
13131: [pcl/components] Fixes range scoping for PCL components r=Zaid-Ajaj a=Zaid-Ajaj

# Description

This PR implements proper `range` block scoping for `pcl.Component` so that when binding the component body, it understands references to the `range` expression. This fixes a couple of the PCL binder issues we have been seeing in TF converter such as  https://github.com/pulumi/pulumi-terraform-bridge/issues/1184, https://github.com/pulumi/pulumi-terraform-bridge/issues/1150, https://github.com/pulumi/pulumi-terraform-bridge/issues/1148 at least locally these errors are resolved for the linked TF example. 

Also small fix for the error we are seeing for `length(...)` because fields of object-typed config were implicitly optional and errored before. Now it flattens `option<T>` to just `T` and no longer errors. https://github.com/pulumi/pulumi-terraform-bridge/issues/1186

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
  - [ ] I have formatted my code using `gofumpt`

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Zaid Ajaj <zaid.naom@gmail.com>
2023-06-08 23:37:53 +00:00
Zaid Ajaj 604d0f9b77 Fixes range scoping for PCL components 2023-06-08 21:43:54 +02:00
Fraser Waters ef7b123bba Don't return empty hcl.Diagnostics
Fixes https://github.com/pulumi/pulumi-terraform-bridge/issues/1201

hcl.Diagnostics implements the Error interface, but this means a list of
zero diagnostics still looks like a non-nil error, which throws of
normal "if err == nil" checks.

This changes a few use sites of hcl.Diagnostics to ensure we return nil
when there aren't any diagnostics rather than an empty slice. This
ensures if they get cast to `Error` they don't trip up standard `err ==
nil` checks.
2023-06-08 19:14:41 +01:00
Fraser Waters 46332e7d17 Make convert more lenient
Fixes https://github.com/pulumi/pulumi/issues/13117

This adds a new "--strict" flag to `pulumi convert` which defaults to
false. When strict is NOT set we bind the PCL with the extra options of
`SkipResourceTypechecking`, `AllowMissingVariables`, and
`AllowMissingProperties`. This will change some errors to warnings in
code generation.

The `strict` flag is sent over the gRPC interface to the Go/Node plugins
for their `GenerateProject` methods as they have to do PCL binding
plugin side currently.
2023-06-08 11:14:31 +01:00
Fraser Waters 5c999e28ca Test components in convert 2023-06-01 20:54:44 +01:00
Zaid Ajaj 588e21fde7 Impleneted python program-gen for PCL components 2023-04-05 13:19:52 +02:00
Zaid Ajaj 0988177853 Implement description as comments or docstring for config variables in program-gen 2023-03-21 15:01:16 +01:00
Zaid Ajaj fe66a67ba1 Export fields from component binder args 2023-03-16 22:09:08 +01:00
Zaid Ajaj ba639d555a PCL components and dotnet program-gen implementation 2023-03-08 14:21:34 +01:00
Abhinav Gupta 7aa5b77a0c
all: Reformat with gofumpt
Per team discussion, switching to gofumpt.

[gofumpt][1] is an alternative, stricter alternative to gofmt.
It addresses other stylistic concerns that gofmt doesn't yet cover.

  [1]: https://github.com/mvdan/gofumpt

See the full list of [Added rules][2], but it includes:

- Dropping empty lines around function bodies
- Dropping unnecessary variable grouping when there's only one variable
- Ensuring an empty line between multi-line functions
- simplification (`-s` in gofmt) is always enabled
- Ensuring multi-line function signatures end with
  `) {` on a separate line.

  [2]: https://github.com/mvdan/gofumpt#Added-rules

gofumpt is stricter, but there's no lock-in.
All gofumpt output is valid gofmt output,
so if we decide we don't like it, it's easy to switch back
without any code changes.

gofumpt support is built into the tooling we use for development
so this won't change development workflows.

- golangci-lint includes a gofumpt check (enabled in this PR)
- gopls, the LSP for Go, includes a gofumpt option
  (see [installation instrutions][3])

  [3]: https://github.com/mvdan/gofumpt#installation

This change was generated by running:

```bash
gofumpt -w $(rg --files -g '*.go' | rg -v testdata | rg -v compilation_error)
```

The following files were manually tweaked afterwards:

- pkg/cmd/pulumi/stack_change_secrets_provider.go:
  one of the lines overflowed and had comments in an inconvenient place
- pkg/cmd/pulumi/destroy.go:
  `var x T = y` where `T` wasn't necessary
- pkg/cmd/pulumi/policy_new.go:
  long line because of error message
- pkg/backend/snapshot_test.go:
  long line trying to assign three variables in the same assignment

I have included mention of gofumpt in the CONTRIBUTING.md.
2023-03-03 09:00:24 -08:00
Ian Wahbe 0d3fca4b37 Type check resource attributes
Fix assets-archives-pp test so it type checks

Skip type checking on 2 transpiled tests

- azure-app-service
- aws-static-website
2022-11-15 18:46:10 -08:00
aq17 525849bf17 Support options.version on pulumi convert 2022-09-23 09:41:17 -07:00
Aaron Friel c2e196bf3f
[codegen] Simplify program generation for explicit providers () 2022-07-19 09:26:40 -07:00
Pat Gavlin 36cbf572f4
[schema] Add support for on-demand binding. ()
These changes extend the public API of `pkg/codegen/schema` to support
on-demand binding of package members. On-demand binding is appropriate for
scenarios that do not require the entire package, especially those such as
program code generation or the YAML LSP server that require only specific
types/functions/etc.

The extensions to the public API consist of two new types and several new
methods. The most notable of these are `PackageReference` and
`Loader.LoadPackageReference`. The former provides the on-demand binding
interface, while the latter creates instances of the former (n.b. it was
my intent to make a breaking change to the signature of `Loader.LoadPackage`
s.t. it returns a `PackageReference`, but the circular dependency between
this Go module and those for YAML and Java prevented that change).

These changes _dramatically_ reduce the memory required to interace with
Pulumi Packages, and only require memory proportional to the number of
accessed package members. We may be able to improve on this in the future
by removing type/resource/function interning, which would allow those
values to be garbage collected at a granaular level rather than at a
package level. That is a more radical change, though, as it requires new
equality semantics for each of the affected types (some of which are
currently used as map keys).
2022-05-23 15:44:35 -07:00
Aaron Friel 98e48f4cc4
codegen: preserve externally visible names of a resources and outputs ()
* codegen: preserve externally visible names of a resources and outputs

* refactor: rename unique name to logical name
2022-04-25 15:07:25 -07:00
Pat Gavlin f21eda521f
[codegen] Rename the PCL package. ()
It's just confusing that PCL lives in a package named `hcl2`.
2021-09-29 20:11:56 -07:00