Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/packages/jsii-pacmak/test/gen…
Browse files Browse the repository at this point in the history
…erated-code/pip-23.1.2
  • Loading branch information
vinayak-kukreja authored May 11, 2023
2 parents 06fe858 + 14f5d10 commit ade54ad
Show file tree
Hide file tree
Showing 16 changed files with 571 additions and 854 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.81.0](https://github.com/aws/jsii/compare/v1.80.0...v1.81.0) (2023-05-10)


### Features

* **jsii-diff:** allow external stability to be treated as error ([#4076](https://github.com/aws/jsii/issues/4076)) ([95689ea](https://github.com/aws/jsii/commit/95689ea840a99f38f8449aab2bc452cf489e3e3f))
* **jsii-pacmak:** parsing arguments in non-strict mode ([#4068](https://github.com/aws/jsii/issues/4068)) ([3d49d6f](https://github.com/aws/jsii/commit/3d49d6fd2dc64db45aa3f1164bb976c8cfe75175)), closes [#3465](https://github.com/aws/jsii/issues/3465)


### Bug Fixes

* **pacmak:** go docs overview displays repeating description ([#4081](https://github.com/aws/jsii/issues/4081)) ([4fd596a](https://github.com/aws/jsii/commit/4fd596a467cdb422ebea3fdf01d068bc360b3757)), closes [/github.com/aws/jsii/pull/3698/files#diff-0a99c713a1282d6efe349c932d74dbfbdf1d926834c46ebfb5d65daeb27073f3R263](https://github.com/aws//github.com/aws/jsii/pull/3698/files/issues/diff-0a99c713a1282d6efe349c932d74dbfbdf1d926834c46ebfb5d65daeb27073f3R263) [/github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/package.json#L4](https://github.com/aws//github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/package.json/issues/L4) [/github.com/aws/jsii/blob/main/packages/jsii-reflect/lib/assembly.ts#L46-L52](https://github.com/aws//github.com/aws/jsii/blob/main/packages/jsii-reflect/lib/assembly.ts/issues/L46-L52)
* **rosetta:** flakey trim-cache test ([#4043](https://github.com/aws/jsii/issues/4043)) ([f70c0f7](https://github.com/aws/jsii/commit/f70c0f77069c8beb30010395cfd5817ac013feba))

## [1.80.0](https://github.com/aws/jsii/compare/v1.79.0...v1.80.0) (2023-04-04)


Expand Down
4 changes: 2 additions & 2 deletions gh-pages/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mkdocs~=1.4.2
mkdocs~=1.4.3
mkdocs-awesome-pages-plugin~=2.9.0
mkdocs-material~=9.1.6
mkdocs-material~=9.1.11
mkdocs-git-revision-date-plugin~=0.3.2
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"rejectCycles": true
}
},
"version": "1.80.0"
"version": "1.81.0"
}
2 changes: 1 addition & 1 deletion packages/@jsii/python-runtime/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
black~=23.3
mypy==1.2.0
pip~=23.1
pytest~=7.2
pytest~=7.3
pytest-mypy~=0.10
setuptools~=67.3.2
types-python-dateutil~=2.8
Expand Down
8 changes: 8 additions & 0 deletions packages/codemaker/src/codemaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ export class CodeMaker {
return caseutils.toSnakeCase(s, sep);
}

/**
* Gets currently opened file path.
* @returns Currently opened file path.
*/
public getCurrentFilePath(): string | undefined {
return this.currentFile?.filePath;
}

private makeIndent(): string {
const length = this.currentIndentLength;
if (length <= 0) {
Expand Down
67 changes: 45 additions & 22 deletions packages/jsii-diff/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,97 @@

__jsii-diff__ compares two jsii assemblies for compatibility.

In the future, it will be able to do generic comparisons, but for
In the future, it will be able to do generic comparisons.
But for
now it will compare assemblies for API compatibility, and exit
with a non-zero exit code if any **stable** APIs have had incompatible
changes.
with a non-zero exit code if any __stable__ or __deprecated__ APIs have had incompatible changes.

API items that have no stability are treated as **stable**. To treat
unmarked API items as experimental, pass the `--default-experimental` flag.
API items that have no stability are treated as __stable__.
To treat unmarked API items as experimental, pass the `--default-experimental` flag.

## Usage

To compare two JSII packages:

jsii-diff <old> [new]
```console
jsii-diff <old> [new]
```

Packages can be identified by either:

* **A path**, in which case it should be the path to a JSII package directory,
* __A path__, in which case it should be the path to a JSII package directory,
or to a `.jsii` file.
* **An NPM package specifier** of the form `npm:[<package>[@version]]`, in
* __An NPM package specifier__ of the form `npm:[<package>[@version]]`, in
which case the indicated version is downloaded and used. If `@version` is
left out, the latest version will be used. If `package` is left out,
the assembly name of `.jsii` in the current directory will be used.

To compare current package against latest published NPM release:

jsii-diff npm:
```console
jsii-diff npm:<package>
```

### Stability Error Classes

By default only incompatible changes to `stable` or `deprecated` APIs are treated as errors and will fail the command.
Changes to `experimental` or `external` APIs emit a warning.

Change this behavior with the `--error-on` flag:

```console
jsii-diff npm:<package> --error-on=all
```

The following `--error-on` groups are available:

| `--error-on` | Stabilities that cause an ERROR |
| ------------------ | -------------------------------------------------- |
| `prod` (default) | `stable`, `deprecated` |
| `non-experimental` | `stable`, `deprecated`, `external` |
| `all` | `stable`, `deprecated`, `experimental`, `external` |

## Details

__jsii-diff__ will assert that code written against version **A** of a library
will still typecheck when compiled against version **B** of that library. It
__jsii-diff__ will assert that code written against version __A__ of a library
will still typecheck when compiled against version __B__ of that library. It
does this by verifying the following properties:

- Any type (class/interface/enum) in **A** must also exist in **B**.
- Enums have only added members.
- Classes and interfaces have only added members, or modified existing
* Any type (class/interface/enum) in __A__ must also exist in __B__.
* Enums have only added members.
* Classes and interfaces have only added members, or modified existing
members in an allowed way.
- Property types are the same or have been strengthened (see below).
- Methods have only added optional arguments, existing argument types have
* Property types are the same or have been strengthened (see below).
* Methods have only added optional arguments, existing argument types have
only been weakened, and the return type has only been strengthened (see below).

### Strengthening and weakening

- *Strengthening* a type refers to *excluding* more possible values. Changing
* *Strengthening* a type refers to *excluding* more possible values. Changing
a field from `optional` to `required`, or changing a type from `any` to
`string` are examples of strengthening.

- As the opposite of strengthening, *weakening* refers to *allowing* more
* As the opposite of strengthening, *weakening* refers to *allowing* more
possible values. Changing a field from `required` to `optional`, or
changing a type to a superclass or interface are examples of weakening.

An API can change in the following way without breaking its consumer:

- It can *weaken* its input (require *less* from the caller); and
- It can *strengthen* its output (guarantee *more* to the caller).
* It can *weaken* its input (require *less* from the caller); and
* It can *strengthen* its output (guarantee *more* to the caller).

### Struct types

Structs (interfaces consisting completely of `readonly` properties) are
treated as bags of data. Their API compatibility will be evaluated depending
on whether they appear in input or output position of operations.

- Structs are *weakened* if all types of all of its properties are weakened.
* Structs are *weakened* if all types of all of its properties are weakened.
Normally removing properties would also be considered weakening, but
because that may cause references to the fields in existing code bases to
become undefined (which is not allowed in most programming languages) we
disallow removing properties.
- Structs are *strengthened* if all types of all of its properties are
* Structs are *strengthened* if all types of all of its properties are
strengthened, or if fields are added.

__jsii-diff__ will check the evolution of structs against their position
Expand Down
14 changes: 12 additions & 2 deletions packages/jsii-diff/bin/jsii-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import * as yargs from 'yargs';
import { compareAssemblies } from '../lib';
import {
classifyDiagnostics,
treatAsError,
formatDiagnostic,
hasErrors,
ErrorClass,
ERROR_CLASSES,
} from '../lib/diagnostics';
import {
DownloadFailure,
Expand Down Expand Up @@ -42,6 +45,13 @@ async function main(): Promise<number> {
type: 'boolean',
default: false,
desc: 'Error on experimental API changes',
deprecate: 'Use `--error-on` instead',
})
.option('error-on', {
type: 'string',
default: 'prod',
choices: ERROR_CLASSES,
desc: 'Which type of API changes should be treated as an error',
})
.option('ignore-file', {
alias: 'i',
Expand Down Expand Up @@ -119,15 +129,15 @@ async function main(): Promise<number> {
if (mismatches.count > 0) {
const diags = classifyDiagnostics(
mismatches,
argv['experimental-errors'],
treatAsError(argv['error-on'] as ErrorClass, argv['experimental-errors']),
await loadFilter(argv['ignore-file']),
);

process.stderr.write(
`Original assembly: ${original.name}@${original.version}\n`,
);
process.stderr.write(
`Updated assembly: ${updated.name}@${updated.version}\n`,
`Updated assembly: ${updated.name}@${updated.version}\n`,
);
process.stderr.write('API elements with incompatible changes:\n');
for (const diag of diags) {
Expand Down
57 changes: 48 additions & 9 deletions packages/jsii-diff/lib/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,57 @@ export function hasErrors(diags: Diagnostic[]) {
return diags.some((diag) => diag.level === DiagLevel.Error);
}

export function onlyErrors(diags: Diagnostic[]) {
return diags.filter((diag) => diag.level === DiagLevel.Error);
}

export function onlyWarnings(diags: Diagnostic[]) {
return diags.filter((diag) => diag.level === DiagLevel.Warning);
}

export const ERROR_CLASSES = ['prod', 'non-experimental', 'all'] as const;

export type ErrorClass = (typeof ERROR_CLASSES)[number];

export const ERROR_CLASSES_TO_STABILITIES: Record<ErrorClass, Stability[]> = {
prod: [Stability.Stable, Stability.Deprecated],
'non-experimental': [
Stability.Stable,
Stability.Deprecated,
Stability.External,
],
all: [
Stability.Stable,
Stability.Experimental,
Stability.External,
Stability.Deprecated,
],
};

export function treatAsError(
errorClass: ErrorClass,
deprecatedExperimentalErrors = false,
): Set<Stability> {
const shouldError = new Set<Stability>();

for (const stability of ERROR_CLASSES_TO_STABILITIES[errorClass]) {
shouldError.add(stability);
}

if (deprecatedExperimentalErrors) {
shouldError.add(Stability.Experimental);
}

return shouldError;
}

/**
* Classify API mismatches into a set of warnings and errors
*/
export function classifyDiagnostics(
mismatches: Mismatches,
experimentalErrors: boolean,
skipFilter: Set<string>,
shouldError: Set<Stability>,
skipFilter: Set<string> = new Set(),
): Diagnostic[] {
const ret = mismatches.mismatches.map((mis) => ({
level: level(mis),
Expand All @@ -56,12 +100,7 @@ export function classifyDiagnostics(
if (skipFilter.has(mis.violationKey)) {
return DiagLevel.Skipped;
}
if (
mis.stability === Stability.Stable ||
(mis.stability === Stability.Experimental && experimentalErrors)
) {
return DiagLevel.Error;
}
return DiagLevel.Warning;

return shouldError.has(mis.stability) ? DiagLevel.Error : DiagLevel.Warning;
}
}
Loading

0 comments on commit ade54ad

Please sign in to comment.