Commit Graph

56 Commits

Author SHA1 Message Date
Fraser Waters 16d9f4c167
Enable perfsprint linter ()
<!--- 
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->

Prompted by a comment in another review:
https://github.com/pulumi/pulumi/pull/14654#discussion_r1419995945

This lints that we don't use `fmt.Errorf` when `errors.New` will
suffice, it also covers a load of other cases where `Sprintf` is
sub-optimal.

Most of these edits were made by running `perfsprint --fix`.

## Checklist

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

<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] 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. -->
2023-12-12 12:19:42 +00:00
Zaid Ajaj b52ab81cc4
[typescrypt/program-gen] Fix generated readFile function so that it includes the encoding ()
# Description

Small fix for generated `readFile` function so that it includes the
encoding and returns a string

Fixes 

## Checklist

- [ ] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
  - [x] 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. -->
2023-11-23 00:26:41 +00:00
Kyle Dixler 701a9f6d0d Fix nodejs enum programgen to use package identifier over PackageName. 2023-07-24 14:46:34 -07:00
Zaid Ajaj 62af6b0b1a Fix interpolated strings used as keys of maps 2023-07-18 08:47:37 +02:00
Zaid Ajaj 65ad123780 Implement singleOrNone intrinsic for typescript and python 2023-05-25 22:12:13 +02:00
Zaid Ajaj d37b26874f Allow iterating dynamic entries in TypeScript 2023-05-16 20:11:57 +02:00
Zaid Ajaj e9c9fb5e32 Support range expressions that are of type output 2023-04-26 20:00:32 +02:00
Zaid Ajaj 9f07128175 Fixes the type signature of PCL function "entries" to return list of key-value pair objects 2023-04-05 13:04:46 +02:00
Zaid Ajaj 726caed8ab Object-typed config variables for components 2023-03-23 23:25:21 +01:00
Zaid Ajaj e5a8a7e934 nodejs pcl components, initial commit 2023-03-14 16:17:14 +01:00
Zaid Ajaj b90b5a5bf9 Add "NotImplemented" PCL function intrinsic 2023-03-10 12:14:28 +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
bors[bot] 4f3a1bce17
Merge
12267: chore(all): strings.Replace(..., -1) => strings.Replace(...) r=abhinav a=abhinav

Replaces all instances of `strings.Replace(s, old, new, -1)`
with the equivalent `strings.ReplaceAll(s, old, new)`.
This function has been available since Go 1.12.


12268: chore: WriteString(Sprintf(..)) => Fprintf(..) r=abhinav a=abhinav

Replace `buffer.WriteString(fmt.Sprintf(..))` calls,
where buffer is one of `bytes.Buffer`, `strings.Builder`, or `bufio.Writer`,
with equivalent `fmt.Fprintf` calls -- all those types are io.Writers.


12337: Freeze v3.56.0 r=dixler a=dixler



Co-authored-by: Abhinav Gupta <abhinav@pulumi.com>
Co-authored-by: Kyle Dixler <kyle@pulumi.com>
2023-03-02 21:50:14 +00:00
Abhinav Gupta cc32691bc1
chore(all): strings.Replace(..., -1) => strings.Replace(...)
Replaces all instances of `strings.Replace(s, old, new, -1)`
with the equivalent `strings.ReplaceAll(s, old, new)`.
This function has been available since Go 1.12.
2023-03-01 13:22:33 -08:00
Abhinav Gupta fc081e08e3
pkg/codegen/nodejs: Prefer contract.Assertf over Assert
Incremental step towards 

Migrates uses of contract.{Assert, AssertNoError, Require}
to `*f` variants so that we're required to provide more error context.

Refs 
2023-03-01 13:22:32 -08:00
Fraser Waters 3936ed9b4f Add unsecret intrinsic function 2023-01-31 14:18:01 +00:00
Zaid Ajaj 330676a0d0 Initial implementation of simplified invokes for dotnet and nodejs 2023-01-11 14:17:14 -08:00
Aaron Friel a682a1ab06
Revert "Simplified invokes: SDK-gen and program-gen implementation for dotnet and nodejs" 2022-12-20 17:47:29 -08:00
Zaid Ajaj a6f26d2355 Initial implementation of simplified invokes for dotnet and nodejs 2022-12-16 13:39:03 +01:00
Ian Wahbe 5e9bda092a Don't use *schema.Package in nodejs codegen 2022-12-08 17:49:54 +01:00
aq17 927e9d4a69 Improve error msg for invalid enum values on convert 2022-12-01 15:29:22 -08:00
bors[bot] c0b521dbb3
Merge
11478: Fix capitalization for generated `fs.readdirSync` r=iwahbe a=iwahbe

This lets us reenable the `"aws-s3-folder"` programgen test for nodejs.

Co-authored-by: Ian Wahbe <ian@wahbe.com>
2022-11-29 00:23:47 +00:00
Ian Wahbe 9f5e5b5db7 Fix capitalization for generated `fs.readdirSync` 2022-11-28 11:26:32 -08:00
Ian Wahbe 25e4c49375 Add `.` between `?` and `]` 2022-11-28 11:14:55 -08:00
Ian Wahbe d62390e70a Parenthesize lambda generation
Fix map iteration lambdas
2022-11-23 19:19:08 -08:00
aq17 575c2549aa Fix codegen for __apply functions 2022-09-28 10:32:33 -07:00
Ian Wahbe a4803f43ea
Remove programgen conversion assertions () 2022-07-13 14:29:34 -07:00
Zaid Ajaj 515cf6191c
Fixes panic when generating go from pulumi yaml ()
* Fixes  panic when generating go from pulumi yaml

Co-authored-by: Aaron Friel <friel@pulumi.com>
Co-authored-by: Zaid Ajaj <zaid@pulumi.com>

* rewrite rewriteConversions to accumulate diagnostics, improve errors

* rewrite diags

* update java dependency

* chore: fix go.mod/go.sum

* fix: traversal of multi-part template string expressions

Co-authored-by: Aaron Friel <mayreply@aaronfriel.com>
Co-authored-by: Aaron Friel <friel@pulumi.com>
Co-authored-by: Zaid Ajaj <zaid@pulumi.com>
2022-07-07 13:15:47 -07:00
Ian Wahbe 860ddc0865
Use exising module name infrastrucure () 2022-04-29 09:56:02 -07:00
Aaron Friel be2501e245
codegen for all assets and archives types ()
* codegen for all assets and archives types

* chore: add changelog entry

* Update CHANGELOG_PENDING.md

Co-authored-by: Fraser Waters <fraser@pulumi.com>

* fix C# codegen with explicit AssetOrArchive type

Co-authored-by: Fraser Waters <fraser@pulumi.com>
2022-04-25 12:59:30 -07:00
Ian Wahbe 183fa89163
Add an EnumType to the PCL model ()
* Add an EnumType to the PCL model

Languages implementation:
- [X] C#
- [X] Python
- [X] TypeScript
- [X] Go

* Fix assert

* Take namespace settings into account

* Implement enums for Go

* Update tests and add documentation.

* Add a test + handle output&unsafe

* Get outputs compiling for Go

* Line up types for Go

* Add nodejs

* Add Python

* Change expression form

* Fix nil check (`==` -> `!=`)

* Standardize nodejs & python checks

This should fix the Node OOM error.

* Rename enum-py to typed-enum-pp

* Don't reference schema types in `hcl2/model`

* Fix nits
2022-04-18 11:03:42 +02:00
Ian Wahbe 66f8b357e2
Expand pcl intrinsic functions ()
* Add TS support

* Add python support

* Add go support

* Add C# support
2022-03-15 17:05:36 -07:00
T-Vova 8f3e7f40ce
Implemented filebase64sha256 & fileArchive support for codegen ()
Co-authored-by: Vova Ivanov <jetvova@gmail.com>
2022-01-21 16:03:25 +02:00
Anton Tayanovskyy 06a19b53ed
Programgen support for fnOutput forms in node () ()
* Teach PCL about fnOutput forms

* Teach PCL about fnOutput forms

* Teach Node program gen to emit fnOutput forms

* TypeCheck fix

* AWS package bump

* Add tests

* CHANGELOG

* Temporarily skip non-Node affected tests

* Address PR feedback: restrict new form to Output args only
2021-11-17 15:27:50 -05: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
T-Vova e696fb6c50
Implemented filebase64() support for Code Generator ()
* Added filebase64 support for Golang

* Fixed function signature

* Added filebase64 support for Typescript

* Added filebase64 support for Python

* Added filebase64 support for Dotnet, fixed Sha1

* Fixed helper method list

Co-authored-by: Vova Ivanov <jetvova@gmail.com>
2021-09-10 23:09:28 +01:00
T-Vova 87e4c92c66
Implemented `sha1()` support for Code Generator ()
Co-authored-by: Justin Van Patten <jvp@justinvp.com>
Co-authored-by: Vova Ivanov <jetvova@gmail.com>
2021-09-10 21:40:38 +03:00
Pat Gavlin 1409d88438
[codegen/*] Add join and toBase64 functions. ()
Co-authored-by: Komal Ali <komal@pulumi.com>
2021-07-28 20:41:23 -07:00
Pat Gavlin 7b1d6ec1ac
Reify `Input` and `Optional` types in the schema type system. ()
These changes support arbitrary combinations of input + plain types
within a schema. Handling plain types at the property level was not
sufficient to support such combinations. Reifying these types
required updating quite a bit of code. This is likely to have caused
some temporary complications, but should eventually lead to
substantial simplification in the SDK and program code generators.

With the new design, input and optional types are explicit in the schema
type system. Optionals will only appear at the outermost level of a type
(i.e. Input<Optional<>>, Array<Optional<>>, etc. will not occur). In
addition to explicit input types, each object type now has a "plain"
shape and an "input" shape. The former uses only plain types; the latter
uses input shapes wherever a plain type is not specified. Plain types
are indicated in the schema by setting the "plain" property of a type spec
to true.
2021-06-24 09:17:55 -07:00
pulumi-bot 73a66f48ea [breaking] Changing the version of go.mod in sdk / pkg to be v3 2021-04-14 19:32:18 +01:00
Mikhail Shilkov 428225f992
[codegen/nodejs] Format dashed import for invokes () 2020-09-17 18:23:54 +02:00
Levi Blackstone ba18683d9a
[codegen] Generate null values for model.NoneType () 2020-08-06 14:12:27 -06:00
Pat Gavlin a8a20ecb4b
[codegen/*] Add support for explicit secrets. ()
- Add a new builtin function, secret, that marks its input value as
  secret
- Add support for this function to the various code generators

Fixes .
2020-06-30 11:35:24 -07:00
Pat Gavlin 69ba47cff2
[codegen/*] Add support for resource options. ()
The PCL binder has supported resource options for some time, but these
options haven't been used or processed by the various code generators.
These options--particularly the parent and provider options0--are
critical for import codegen. These changes implement the basic set of
options, and add a note about fleshing out the rest as necessary.

One component of these changes is a new rewriter that rewrites property
references into property paths that are understood by the Pulumi engine.
This rewriter is used to preprocess the contents of the `ignoreChanges`
resource option.

These changes also hack around a weakness in the HCL2 type system:
In Go, references to resources should be typed as `hcl2.ResourceType`.
Unfortunately, this breaks the existing collection semantics associated
with resources. Because of this, the Go code generator does not have
enough information to know that it should generate a `[]pulumi.Resource`
for lists of resources. These changes hack around that limitation using
a Go-specific opaque type and some hardcoded comparisons in
`argumentTypeName`.

Fixes .
2020-06-29 16:33:52 -07:00
Mikhail Shilkov 7e3b60b3d1
Fix C# (and a bit of Node.js) program gen based on errors from AWS samples () 2020-05-22 08:46:25 +02:00
Mikhail Shilkov f66100ce28
Initial support for C# program gen ()
Initial support for C# program gen
2020-05-19 10:18:38 +02:00
Pat Gavlin 255620ea1e
[codegen/nodejs] Await invokes in async contexts. ()
If we are generating code into an async context (e.g. an async main),
await calls to invoke rather than leaving them as promises. This results
in more idiomatic code withing such contexts.
2020-05-11 10:21:56 -07:00
Pat Gavlin f23b98a7df
[codegen/nodejs] Fix . ()
Do not wrap non-output-typed arguments to `pulumi.all` in
`pulumi.output`. `pulumi.all` does this implicitly.

Fixes .
2020-05-06 10:09:20 -07:00
Pat Gavlin 96300f12d9
[codegen/*] Improve range type binding + codegen. ()
- Determine variable types for ranged resources by typechecking an
  equivalent expression
- Detect top-level await in NodeJS and generate an async main
- Fix `pulumi.all` generation for NodeJS
- Fix a bug in the lowering of relative traversals in Python
2020-05-04 15:04:35 -07:00
Pat Gavlin 2e9499a000
[codegen/hcl2] Fix the apply rewriter. ()
Some of the apply rewriter's assumptions were broken by the richer
expressions available in HCL2. These changes fix those broken
assumptions, in particular the assumption that only scope traversal
expressions are sources of eventual values.
2020-04-24 22:04:24 -07:00