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

chore(deps): Update attrs requirement from ~=21.2 to >=21.2,<23.0 in /packages/@jsii/python-runtime #3692

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ jobs:
name: Run benchmark suite
runs-on: ubuntu-latest
permissions:
contents: write
contents: read
pull-requests: write
needs: build
steps:
# Check out the code
Expand Down Expand Up @@ -395,7 +396,7 @@ jobs:
tool: 'customSmallerIsBetter'
output-file-path: ${{ runner.temp }}/bench-output.json
comment-always: true
github-token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
fail-on-alert: true
- name: Upload Benchmark Results
if: github.event_name == 'push'
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/python-runtime/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"jsii._embedded.jsii": ["*.js", "*.js.map"],
},
install_requires=[
"attrs~=21.2",
"attrs>=21.2,<23.0",
"cattrs>=1.8,<22.2",
"publication>=0.0.3", # This is used by all generated code.
"typeguard~=2.13.3", # This is used by all generated code.
Expand Down
6 changes: 3 additions & 3 deletions packages/jsii-rosetta/bin/jsii-rosetta.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@jsii/check-node/run';

import * as fs from 'fs-extra';
import { promises as fs } from 'fs';
import * as path from 'path';
import * as yargs from 'yargs';

Expand Down Expand Up @@ -408,7 +408,7 @@ function main() {
const packageJsonPath = (await fs.stat(args.PACKAGE)).isDirectory()
? path.join(args.PACKAGE, 'package.json')
: args.PACKAGE;
const packageJson = await fs.readJson(packageJsonPath);
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8'));
if (packageJson.jsii == null) {
console.error(
`The package in ${args.PACKAGE} does not have a jsii configuration! You can set it up using jsii-config.`,
Expand All @@ -425,7 +425,7 @@ function main() {
const mdRosetta = (mdJsii.rosetta = mdJsii.rosetta ?? {});
mdRosetta.strict = true;

return fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
return fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
}),
)
.demandCommand()
Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-rosetta/lib/commands/infuse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as spec from '@jsii/spec';
import * as fs from 'fs-extra';
import * as fs from 'fs';
import * as path from 'path';

import {
Expand Down
7 changes: 5 additions & 2 deletions packages/jsii-rosetta/lib/commands/transliterate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Assembly, Docs, SPEC_FILE_NAME, Type, TypeKind, loadAssemblyFromPath } from '@jsii/spec';
import { writeJson } from 'fs-extra';
import { promises as fs } from 'fs';
import { resolve } from 'path';

import { TargetLanguage } from '../languages';
Expand Down Expand Up @@ -117,7 +117,10 @@ export async function transliterateAssembly(
transliterateType(type, rosetta, language);
}
// eslint-disable-next-line no-await-in-loop
await writeJson(resolve(options?.outdir ?? location, `${SPEC_FILE_NAME}.${language}`), result, { spaces: 2 });
await fs.writeFile(
resolve(options?.outdir ?? location, `${SPEC_FILE_NAME}.${language}`),
JSON.stringify(result, null, 2),
);
const then = new Date().getTime();
debug(`Done transliterating ${result.name}@${result.version} to ${language} after ${then - now} milliseconds`);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/jsii-rosetta/lib/find-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as fs from 'fs-extra';
import { promises as fs } from 'fs';
import * as path from 'path';

import { pathExists } from './util';

/**
* Find the directory that contains a given dependency, identified by its 'package.json', from a starting search directory
*
Expand Down Expand Up @@ -34,7 +36,7 @@ export async function findDependencyDirectory(dependencyName: string, searchStar
export async function findPackageJsonUp(packageName: string, directory: string) {
return findUp(directory, async (dir) => {
const pjFile = path.join(dir, 'package.json');
return (await fs.pathExists(pjFile)) && (await fs.readJson(pjFile)).name === packageName;
return (await pathExists(pjFile)) && JSON.parse(await fs.readFile(pjFile, 'utf-8')).name === packageName;
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/jsii-rosetta/lib/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from 'fs-extra';
import * as fs from 'fs';
import * as path from 'path';
import { createSourceFile, ScriptKind, ScriptTarget, SyntaxKind } from 'typescript';

Expand Down
11 changes: 6 additions & 5 deletions packages/jsii-rosetta/lib/jsii/assemblies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
writeAssembly,
} from '@jsii/spec';
import * as crypto from 'crypto';
import * as fs from 'fs-extra';
import { promises as fsPromises } from 'fs';
import * as fs from 'fs';
import * as path from 'path';

import { findDependencyDirectory, isBuiltinModule } from '../find-utils';
Expand Down Expand Up @@ -78,7 +79,7 @@ export function loadAssemblies(
const pjLocation = path.join(directory, 'package.json');

const assembly = loadAssemblyFromFile(location, validateAssemblies);
const packageJson = fs.pathExistsSync(pjLocation) ? fs.readJSONSync(pjLocation, { encoding: 'utf-8' }) : undefined;
const packageJson = fs.existsSync(pjLocation) ? JSON.parse(fs.readFileSync(pjLocation, 'utf-8')) : undefined;

return { assembly, directory, packageJson };
}
Expand Down Expand Up @@ -297,7 +298,7 @@ export function findTypeLookupAssembly(startingDirectory: string): TypeLookupAss

function loadLookupAssembly(directory: string): TypeLookupAssembly | undefined {
try {
const packageJson = fs.readJSONSync(path.join(directory, 'package.json'), { encoding: 'utf-8' });
const packageJson = JSON.parse(fs.readFileSync(path.join(directory, 'package.json'), 'utf-8'));
const assembly: spec.Assembly = loadAssemblyFromPath(directory);
const symbolIdMap = mkDict([
...Object.values(assembly.types ?? {}).map((type) => [type.symbolId ?? '', type.fqn] as const),
Expand Down Expand Up @@ -367,7 +368,7 @@ async function withDependencies(asm: LoadedAssembly, snippet: TypeScriptSnippet)

compilationDependencies[asm.assembly.name] = {
type: 'concrete',
resolvedDirectory: await fs.realpath(asm.directory),
resolvedDirectory: await fsPromises.realpath(asm.directory),
};

Object.assign(
Expand All @@ -387,7 +388,7 @@ async function withDependencies(asm: LoadedAssembly, snippet: TypeScriptSnippet)
name,
{
type: 'concrete',
resolvedDirectory: await fs.realpath(await findDependencyDirectory(name, asm.directory)),
resolvedDirectory: await fsPromises.realpath(await findDependencyDirectory(name, asm.directory)),
},
] as const,
),
Expand Down
5 changes: 2 additions & 3 deletions packages/jsii-rosetta/lib/rosetta-reader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as spec from '@jsii/spec';
import * as fs from 'fs-extra';
import * as path from 'path';

import { allTypeScriptSnippets } from './jsii/assemblies';
Expand All @@ -19,7 +18,7 @@ import {
import { snippetKey } from './tablets/key';
import { DEFAULT_TABLET_NAME, LanguageTablet, Translation } from './tablets/tablets';
import { Translator } from './translate';
import { commentToken, printDiagnostics } from './util';
import { commentToken, pathExists, printDiagnostics } from './util';

export enum UnknownSnippetMode {
/**
Expand Down Expand Up @@ -150,7 +149,7 @@ export class RosettaTabletReader {
*/
public async addAssembly(assembly: spec.Assembly, assemblyDir: string) {
const defaultTablet = path.join(assemblyDir, DEFAULT_TABLET_NAME);
if (await fs.pathExists(defaultTablet)) {
if (await pathExists(defaultTablet)) {
try {
await this.loadTabletFromFile(defaultTablet);
return;
Expand Down
4 changes: 2 additions & 2 deletions packages/jsii-rosetta/lib/rosetta-translator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as spec from '@jsii/spec';
import * as fs from 'fs-extra';
import { promises as fs } from 'fs';

import { TypeFingerprinter } from './jsii/fingerprinting';
import { TARGET_LANGUAGES } from './languages';
Expand Down Expand Up @@ -190,7 +190,7 @@ export class RosettaTranslator {
} finally {
process.chdir(origDir);
if (cleanCompilationDir) {
await fs.remove(compilationDirectory);
await fs.rm(compilationDirectory, { force: true, recursive: true });
}
}

Expand Down
31 changes: 17 additions & 14 deletions packages/jsii-rosetta/lib/snippet-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as cp from 'child_process';
import * as fastGlob from 'fast-glob';
import * as fs from 'fs-extra';
import { promises as fsPromises } from 'fs';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as semver from 'semver';
Expand All @@ -9,7 +10,7 @@ import { intersect } from 'semver-intersect';
import { findDependencyDirectory, findUp } from './find-utils';
import * as logging from './logging';
import { TypeScriptSnippet, CompilationDependency } from './snippet';
import { mkDict, formatList } from './util';
import { mkDict, formatList, pathExists } from './util';

/**
* Collect the dependencies of a bunch of snippets together in one declaration
Expand Down Expand Up @@ -51,7 +52,9 @@ function resolveConflict(
}

if (a.type === 'concrete' && b.type === 'symbolic') {
const concreteVersion: string = fs.readJsonSync(path.join(a.resolvedDirectory, 'package.json')).version;
const concreteVersion: string = JSON.parse(
fs.readFileSync(path.join(a.resolvedDirectory, 'package.json'), 'utf-8'),
).version;

if (!semver.satisfies(concreteVersion, b.versionRange)) {
throw new Error(
Expand Down Expand Up @@ -108,7 +111,7 @@ export async function prepareDependencyDirectory(deps: Record<string, Compilatio
.map((x) => x.resolvedDirectory);
const monorepoPackages = await scanMonoRepos(concreteDirs);

const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'rosetta'));
const tmpDir = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'rosetta'));
logging.info(`Preparing dependency closure at ${tmpDir}`);

// Resolved symbolic packages against monorepo
Expand Down Expand Up @@ -148,10 +151,10 @@ export async function prepareDependencyDirectory(deps: Record<string, Compilatio
await Promise.all(
Object.entries(linkedInstalls).map(async ([name, source]) => {
const target = path.join(modDir, name);
if (!(await fs.pathExists(target))) {
if (!(await pathExists(target))) {
// Package could be namespaced, so ensure the namespace dir exists
await fs.mkdirp(path.dirname(target));
await fs.symlink(source, target, 'dir');
await fsPromises.mkdir(path.dirname(target), { recursive: true });
await fsPromises.symlink(source, target, 'dir');
}
}),
);
Expand Down Expand Up @@ -182,8 +185,8 @@ async function scanMonoRepos(startingDirs: readonly string[]): Promise<Record<st
await Promise.all(
packageDirectories.map(async (directory) => {
const pjLocation = path.join(directory, 'package.json');
return (await fs.pathExists(pjLocation))
? [[(await fs.readJson(pjLocation)).name as string, directory] as const]
return (await pathExists(pjLocation))
? [[JSON.parse(await fsPromises.readFile(pjLocation, 'utf-8')).name as string, directory] as const]
: [];
}),
)
Expand All @@ -198,9 +201,9 @@ async function findMonoRepoGlobs(startingDir: string): Promise<Set<string>> {
const ret = new Set<string>();

// Lerna monorepo
const lernaJsonDir = await findUp(startingDir, async (dir) => fs.pathExists(path.join(dir, 'lerna.json')));
const lernaJsonDir = await findUp(startingDir, async (dir) => pathExists(path.join(dir, 'lerna.json')));
if (lernaJsonDir) {
const lernaJson = await fs.readJson(path.join(lernaJsonDir, 'lerna.json'));
const lernaJson = JSON.parse(await fsPromises.readFile(path.join(lernaJsonDir, 'lerna.json'), 'utf-8'));
for (const glob of lernaJson?.packages ?? []) {
ret.add(path.join(lernaJsonDir, glob));
}
Expand All @@ -210,11 +213,11 @@ async function findMonoRepoGlobs(startingDir: string): Promise<Set<string>> {
const yarnWsDir = await findUp(
startingDir,
async (dir) =>
(await fs.pathExists(path.join(dir, 'package.json'))) &&
(await fs.readJson(path.join(dir, 'package.json')))?.workspaces !== undefined,
(await pathExists(path.join(dir, 'package.json'))) &&
JSON.parse(await fsPromises.readFile(path.join(dir, 'package.json'), 'utf-8'))?.workspaces !== undefined,
);
if (yarnWsDir) {
const yarnWs = await fs.readJson(path.join(yarnWsDir, 'package.json'));
const yarnWs = JSON.parse(await fsPromises.readFile(path.join(yarnWsDir, 'package.json'), 'utf-8'));
for (const glob of yarnWs.workspaces?.packages ?? []) {
ret.add(path.join(yarnWsDir, glob));
}
Expand Down
6 changes: 3 additions & 3 deletions packages/jsii-rosetta/lib/tablets/tablets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from 'fs-extra';
import { existsSync, promises as fs } from 'fs';
import * as path from 'path';
import * as zlib from 'zlib';

Expand Down Expand Up @@ -44,7 +44,7 @@ export class LanguageTablet {
*/
public static async fromOptionalFile(filename: string) {
const ret = new LanguageTablet();
if (fs.existsSync(filename)) {
if (existsSync(filename)) {
try {
await ret.load(filename);
} catch (e: any) {
Expand Down Expand Up @@ -179,7 +179,7 @@ export class LanguageTablet {
* the schema will be gzipped before writing to the file.
*/
public async save(filename: string, compress = false) {
await fs.mkdirp(path.dirname(filename));
await fs.mkdir(path.dirname(filename), { recursive: true });

let schema = Buffer.from(JSON.stringify(this.toSchema(), null, 2));
if (compress) {
Expand Down
16 changes: 16 additions & 0 deletions packages/jsii-rosetta/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { promises as fs } from 'fs';
import * as ts from 'typescript';

import { RosettaDiagnostic } from './translate';
Expand Down Expand Up @@ -227,3 +228,18 @@ export function commentToken(language: string) {
return '//';
}
}

export async function pathExists(path: string): Promise<boolean> {
try {
await fs.stat(path);
return true;
} catch (err: any) {
if (err.code === 'ENOENT') {
return false;
}
if (!err.stack) {
Error.captureStackTrace(err);
}
throw err;
}
}
2 changes: 0 additions & 2 deletions packages/jsii-rosetta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
},
"devDependencies": {
"@types/commonmark": "^0.27.5",
"@types/fs-extra": "^9.0.13",
"@types/mock-fs": "^4.13.1",
"@types/workerpool": "^6.1.0",
"@types/semver": "^7.3.10",
Expand All @@ -29,7 +28,6 @@
"@jsii/check-node": "0.0.0",
"@jsii/spec": "0.0.0",
"commonmark": "^0.30.0",
"fs-extra": "^10.1.0",
"typescript": "~3.9.10",
"sort-json": "^2.0.1",
"@xmldom/xmldom": "^0.8.2",
Expand Down
18 changes: 11 additions & 7 deletions packages/jsii-rosetta/test/commands/extract.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SPEC_FILE_NAME_COMPRESSED } from '@jsii/spec';
import * as fs from 'fs-extra';
import * as fs from 'fs';
import { compileJsiiForTest } from 'jsii';
import * as path from 'path';

Expand All @@ -16,6 +16,7 @@ import * as extract from '../../lib/commands/extract';
import { loadAssemblies } from '../../lib/jsii/assemblies';
import { TARGET_LANGUAGES } from '../../lib/languages';
import * as logging from '../../lib/logging';
import { pathExists } from '../../lib/util';
import { TestJsiiModule, DUMMY_JSII_CONFIG, testSnippetLocation } from '../testutil';

jest.setTimeout(30_000);
Expand Down Expand Up @@ -159,7 +160,7 @@ describe('with cache file', () => {
});

async function givenThatDefaultTabletDoesNotExist() {
await fs.unlink(path.join(assembly.moduleDirectory, DEFAULT_TABLET_NAME));
await fs.promises.unlink(path.join(assembly.moduleDirectory, DEFAULT_TABLET_NAME));
}

describe('translation does not happen ', () => {
Expand Down Expand Up @@ -240,8 +241,8 @@ describe('with cache file', () => {
});

// THEN
expect(await fs.pathExists(path.join(assembly.moduleDirectory, 'dummy.tabl.json'))).toBeTruthy();
expect(await fs.pathExists(path.join(assembly.moduleDirectory, '.jsii.tabl.json'))).toBeTruthy();
expect(await pathExists(path.join(assembly.moduleDirectory, 'dummy.tabl.json'))).toBeTruthy();
expect(await pathExists(path.join(assembly.moduleDirectory, '.jsii.tabl.json'))).toBeTruthy();
});

describe('when the cache output tablet has unrelated snippets', () => {
Expand Down Expand Up @@ -644,9 +645,12 @@ test('can use additional dependencies from monorepo', async () => {
),
);
// GIVEN - a lerna.json that would find that package
await fs.writeJson(path.join(asm.workspaceDirectory, 'lerna.json'), {
packages: ['node_modules/*'],
});
await fs.promises.writeFile(
path.join(asm.workspaceDirectory, 'lerna.json'),
JSON.stringify({
packages: ['node_modules/*'],
}),
);

// WHEN
await extract.extractSnippets([asm.moduleDirectory], defaultExtractOptions);
Expand Down
Loading