From 220023c87b31b4a2352ff9a4816182c7db9f1006 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 1 May 2023 13:35:08 -0400 Subject: [PATCH 1/9] fix: add --target-only --- README.md | 52 +- packages/pyright-scip/package-lock.json | 105 +++++ packages/pyright-scip/package.json | 5 +- packages/pyright-scip/src/MainCommand.test.ts | 3 +- packages/pyright-scip/src/MainCommand.ts | 8 +- packages/pyright-scip/src/config.ts | 444 ++++++++++++++++++ packages/pyright-scip/src/indexer.ts | 41 +- packages/pyright-scip/src/lib.ts | 2 +- packages/pyright-scip/src/treeVisitor.ts | 2 + 9 files changed, 629 insertions(+), 33 deletions(-) create mode 100644 packages/pyright-scip/src/config.ts diff --git a/README.md b/README.md index c8265158d..8ba874b5c 100644 --- a/README.md +++ b/README.md @@ -13,19 +13,69 @@ $ npm install -g @sourcegraph/scip-python scip-python requires Node v16 or newer. See the [Dockerfile](https://github.com/sourcegraph/scip-python/blob/scip/Dockerfile.autoindex) for an exact SHA that is tested. +scip-python uses `pip` to attempt to determine the versions and names of the packages available in your environment. If you do not use pip to install the packages, you can instead use the `--environment` flag to supply a list of packages to use as the environment. This will skip any calls out to pip to determine the state of your env. See [Environment](##-environment) for more information. + + ## Usage ``` $ npm install @sourcegraph/scip-python $ # NOTE: make sure to activate your virtual environment before running -$ scip-python index . --project-name $MY_PROJECT +$ scip-python index . --project-name=$MY_PROJECT $ # Make sure to point towards the sourcegraph instance you're interested in uploading to. $ # more information at https://github.com/sourcegraph/src-cli $ src code-intel upload ``` +To run scip-python over only a particular directory, you can use the `--target-only` flag. Example: + +``` +$ scip-python index . --project-name=$MY_PROJECT --target-only=src/subdir +``` + +## Environment + +The environment file format is a JSON list of `PythonPackage`s. The `PythonPackage` has the following form: + +```json +{ + "name": "PyYAML", + "version": "6.0", + "files": [ + "PyYAML-6.0.dist-info/INSTALLER", + ... + "yaml/__init__.py", + "yaml/composer.py", + "yaml/tokens.py", + ... + ] +}, +``` + +Where: +- `name`: + - The name of the package. Often times this is the same as the module, but is not always the case. + - For example, `PyYAML` is the name of the package, but the module is `yaml` (i.e. `import yaml`). +- `version`: + - The vesion of the package. This is used to generate stable references to external packages. +- `files`: + - A list of all the files that are a member of this package. + - Some packages declare multiple modules, so these should all be included. + +The environment file should be a list of these packages: + +```json +[ + { "name": "PyYAML", "version": "6.0", "files": [...] }, + { "name": "pytorch", "version": "3.0", "files": [..] }, + ... +] +``` + +If you're just using pip, this should not be required. We should calculate this from the pip environment. If you experience any bugs, please report them. The goal is that we support standard pip installation without additional configuration. If there is other python tooling that can generate this information, you can file an issue and we'll see if we can support it as well. + ## Sourcegraph Example Configuration Using the usage example above may be quite simple to add a CI pipeline (perhaps using the `sourcegraph/scip-python:autoindex`) image diff --git a/packages/pyright-scip/package-lock.json b/packages/pyright-scip/package-lock.json index d493ae617..a435e9905 100644 --- a/packages/pyright-scip/package-lock.json +++ b/packages/pyright-scip/package-lock.json @@ -9,6 +9,8 @@ "version": "0.3.3", "license": "MIT", "dependencies": { + "@iarna/toml": "2.2.5", + "command-line-args": "^5.2.1", "commander": "^9.2.0", "diff": "^5.0.0", "glob": "^7.2.0", @@ -23,6 +25,7 @@ "@sourcegraph/eslint-config": "0.26.0", "@sourcegraph/prettierrc": "3.0.3", "@sourcegraph/tsconfig": "4.0.1", + "@types/command-line-args": "^5.2.0", "@types/diff": "^5.0.2", "@types/glob": "^7.2.0", "@types/google-protobuf": "^3.15.5", @@ -775,6 +778,11 @@ "dev": true, "peer": true }, + "node_modules/@iarna/toml": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz", + "integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==" + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -1575,6 +1583,12 @@ "@babel/types": "^7.3.0" } }, + "node_modules/@types/command-line-args": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@types/command-line-args/-/command-line-args-5.2.0.tgz", + "integrity": "sha512-UuKzKpJJ/Ief6ufIaIzr3A/0XnluX7RvFgwkV89Yzvm77wCh1kFaFmqN8XEnGcN62EuHdedQjEMb8mYxFLGPyA==", + "dev": true + }, "node_modules/@types/diff": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/@types/diff/-/diff-5.0.2.tgz", @@ -2341,6 +2355,14 @@ "node": ">=6.0" } }, + "node_modules/array-back": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz", + "integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==", + "engines": { + "node": ">=6" + } + }, "node_modules/array-includes": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.4.tgz", @@ -2961,6 +2983,20 @@ "node": ">= 0.8" } }, + "node_modules/command-line-args": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.1.tgz", + "integrity": "sha512-H4UfQhZyakIjC74I9d34fGYDwk3XpSr17QhEd0Q3I9Xq1CETHo4Hcuo87WyWHpAF1aSLjLRf5lD9ZGX2qStUvg==", + "dependencies": { + "array-back": "^3.1.0", + "find-replace": "^3.0.0", + "lodash.camelcase": "^4.3.0", + "typical": "^4.0.0" + }, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/commander": { "version": "9.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-9.2.0.tgz", @@ -4400,6 +4436,17 @@ "node": ">=8" } }, + "node_modules/find-replace": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz", + "integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==", + "dependencies": { + "array-back": "^3.0.1" + }, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/find-up": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", @@ -6954,6 +7001,11 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, + "node_modules/lodash.camelcase": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", + "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==" + }, "node_modules/lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", @@ -9208,6 +9260,14 @@ "node": ">=4.2.0" } }, + "node_modules/typical": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz", + "integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==", + "engines": { + "node": ">=8" + } + }, "node_modules/unbox-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", @@ -10339,6 +10399,11 @@ "dev": true, "peer": true }, + "@iarna/toml": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz", + "integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==" + }, "@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -11028,6 +11093,12 @@ "@babel/types": "^7.3.0" } }, + "@types/command-line-args": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@types/command-line-args/-/command-line-args-5.2.0.tgz", + "integrity": "sha512-UuKzKpJJ/Ief6ufIaIzr3A/0XnluX7RvFgwkV89Yzvm77wCh1kFaFmqN8XEnGcN62EuHdedQjEMb8mYxFLGPyA==", + "dev": true + }, "@types/diff": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/@types/diff/-/diff-5.0.2.tgz", @@ -11640,6 +11711,11 @@ "@babel/runtime-corejs3": "^7.10.2" } }, + "array-back": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz", + "integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==" + }, "array-includes": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.4.tgz", @@ -12096,6 +12172,17 @@ "delayed-stream": "~1.0.0" } }, + "command-line-args": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.1.tgz", + "integrity": "sha512-H4UfQhZyakIjC74I9d34fGYDwk3XpSr17QhEd0Q3I9Xq1CETHo4Hcuo87WyWHpAF1aSLjLRf5lD9ZGX2qStUvg==", + "requires": { + "array-back": "^3.1.0", + "find-replace": "^3.0.0", + "lodash.camelcase": "^4.3.0", + "typical": "^4.0.0" + } + }, "commander": { "version": "9.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-9.2.0.tgz", @@ -13189,6 +13276,14 @@ "to-regex-range": "^5.0.1" } }, + "find-replace": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz", + "integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==", + "requires": { + "array-back": "^3.0.1" + } + }, "find-up": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", @@ -15163,6 +15258,11 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, + "lodash.camelcase": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", + "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==" + }, "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", @@ -16810,6 +16910,11 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==" }, + "typical": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz", + "integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==" + }, "unbox-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", diff --git a/packages/pyright-scip/package.json b/packages/pyright-scip/package.json index 43a6fd6ad..248b5bed4 100644 --- a/packages/pyright-scip/package.json +++ b/packages/pyright-scip/package.json @@ -8,7 +8,7 @@ "clean": "shx rm -rf ./dist ./out README.md LICENSE.txt", "prepack": "npm run clean && shx cp ../../README.md . && shx cp ../../LICENSE.txt . && npm run build", "check-snapshots": "npm run update-snapshots -- --check", - "update-snapshots": "node ./index.js snapshot-dir snapshots --environment snapshots/testEnv.json --no-progress-bar", + "update-snapshots": "node ./index.js snapshot-dir snapshots --environment snapshots/testEnv.json --quiet", "test": "jest --forceExit --detectOpenHandles", "webpack": "webpack --mode development --progress", "watch": "webpack --mode development --progress --watch" @@ -24,6 +24,7 @@ "@sourcegraph/eslint-config": "0.26.0", "@sourcegraph/prettierrc": "3.0.3", "@sourcegraph/tsconfig": "4.0.1", + "@types/command-line-args": "^5.2.0", "@types/diff": "^5.0.2", "@types/glob": "^7.2.0", "@types/google-protobuf": "^3.15.5", @@ -42,6 +43,8 @@ "webpack-cli": "^4.9.1" }, "dependencies": { + "@iarna/toml": "2.2.5", + "command-line-args": "^5.2.1", "commander": "^9.2.0", "diff": "^5.0.0", "glob": "^7.2.0", diff --git a/packages/pyright-scip/src/MainCommand.test.ts b/packages/pyright-scip/src/MainCommand.test.ts index 9ae0d5b04..bec8bc2db 100644 --- a/packages/pyright-scip/src/MainCommand.test.ts +++ b/packages/pyright-scip/src/MainCommand.test.ts @@ -25,6 +25,7 @@ checkIndexParser([], { }); checkIndexParser(['--cwd', 'qux'], { cwd: 'qux' }); -checkIndexParser(['--no-progress-bar'], { quiet: false }); +checkIndexParser(['--quiet'], { quiet: true }); checkIndexParser(['--show-progress-rate-limit', '120'], { showProgressRateLimit: 120 }); checkIndexParser(['--show-progress-rate-limit', '0.5'], { showProgressRateLimit: 0.5 }); +checkIndexParser(['--target-only', 'foo'], { targetOnly: 'foo' }); diff --git a/packages/pyright-scip/src/MainCommand.ts b/packages/pyright-scip/src/MainCommand.ts index bba3122eb..0b108d621 100644 --- a/packages/pyright-scip/src/MainCommand.ts +++ b/packages/pyright-scip/src/MainCommand.ts @@ -8,10 +8,9 @@ export interface IndexOptions { snapshotDir: string; environment?: string; dev: boolean; - include: string; - exclude: string; output: string; cwd: string; + targetOnly?: string; // Progress reporting configuration quiet: boolean; @@ -56,9 +55,9 @@ export function mainCommand( .requiredOption('--project-name ', 'the name of the current project, pypi name if applicable') .option('--project-version ', 'the version of the current project, defaults to git revision') .option('--cwd ', 'working directory for executing scip-python', process.cwd()) + .option('--target-only ', 'limit analysis to the following path') .option('--output ', 'path to the output file', DEFAULT_OUTPUT_FILE) .option('--snapshot-dir ', 'the directory to output a snapshot of the SCIP dump') - .option('--no-progress-bar', '(deprecated, use "--quiet")') .option('--quiet', 'run without logging and status information', false) .option( '--show-progress-rate-limit ', @@ -66,8 +65,6 @@ export function mainCommand( parseOptionalNum ) .option('--environment ', 'the environment json file (experimental)') - .option('--include ', 'comma-separated list of patterns to include (experimental)') - .option('--exclude ', 'comma-separated list of patterns to exclude (experimental)') .option('--dev', 'run in developer mode (experimental)', false) .action((parsedOptions) => { indexAction(parsedOptions as IndexOptions); @@ -83,7 +80,6 @@ export function mainCommand( .option('--output ', 'path to the output file', DEFAULT_OUTPUT_FILE) .option('--environment ', 'the environment json file (experimental)') .option('--no-index', 'skip indexing (use existing index.scip)') - .option('--no-progress-bar', '(deprecated, use "--quiet")') .option('--quiet', 'run without logging and status information', false) .option( '--show-progress-rate-limit ', diff --git a/packages/pyright-scip/src/config.ts b/packages/pyright-scip/src/config.ts new file mode 100644 index 000000000..40a9b8bad --- /dev/null +++ b/packages/pyright-scip/src/config.ts @@ -0,0 +1,444 @@ +import * as TOML from '@iarna/toml'; +import * as JSONC from 'jsonc-parser'; +import { findPythonSearchPaths, getTypeShedFallbackPath } from 'pyright-internal/analyzer/pythonPathUtils'; + +import { CommandLineOptions } from 'pyright-internal/common/commandLineOptions'; +import { ConfigOptions } from 'pyright-internal/common/configOptions'; +import { FullAccessHost } from 'pyright-internal/common/fullAccessHost'; +import { Host } from 'pyright-internal/common/host'; +import { defaultStubsDirectory } from 'pyright-internal/common/pathConsts'; +import { + forEachAncestorDirectory, + combinePaths, + getDirectoryPath, + normalizePath, + isDirectory, + getFileSpec, +} from 'pyright-internal/common/pathUtils'; +import { createFromRealFileSystem } from 'pyright-internal/common/realFileSystem'; +import { PyrightFileSystem } from 'pyright-internal/pyrightFileSystem'; +import { ScipConfig } from './lib'; + +const configFileNames = ['scip-pyrightconfig.json', 'pyrightconfig.json']; +const pyprojectTomlName = 'pyproject.toml'; + +export class ScipPyrightConfig { + fs: PyrightFileSystem; + _configFilePath: string | undefined; + _configOptions: ConfigOptions; + + _console: Console = console; + _typeCheckingMode = 'basic'; + + constructor(scipConfig: ScipConfig, fs: PyrightFileSystem) { + this.fs = fs; + + this._configOptions = new ConfigOptions(scipConfig.projectRoot); + this._configOptions.checkOnlyOpenFiles = false; + this._configOptions.indexing = true; + this._configOptions.useLibraryCodeForTypes = true; + } + + getConfigOptions(): ConfigOptions { + const host = new FullAccessHost(this.fs); + const options = new CommandLineOptions(process.cwd(), false); + + let config = this._getConfigOptions(host, options); + config.checkOnlyOpenFiles = false; + config.indexing = true; + config.useLibraryCodeForTypes = true; + config.typeshedPath = this._configOptions.typeshedPath || getTypeShedFallbackPath(this.fs); + + return config; + } + + // EVERYTHING BELOW HERE IS COPIED FROM: + // - packages/pyright-internal/src/analyzer/service.ts + // + // These are not exposed and too coupled to the analysis service, + // it doesn't make sense to try and connect them at this time. + private _getConfigOptions(host: Host, commandLineOptions: CommandLineOptions): ConfigOptions { + let projectRoot = commandLineOptions.executionRoot; + let configFilePath: string | undefined; + let pyprojectFilePath: string | undefined; + + if (commandLineOptions.configFilePath) { + // If the config file path was specified, determine whether it's + // a directory (in which case the default config file name is assumed) + // or a file. + configFilePath = combinePaths( + commandLineOptions.executionRoot, + normalizePath(commandLineOptions.configFilePath) + ); + if (!this.fs.existsSync(configFilePath)) { + this._console.info(`Configuration file not found at ${configFilePath}.`); + configFilePath = commandLineOptions.executionRoot; + } else { + if (configFilePath.toLowerCase().endsWith('.json')) { + projectRoot = getDirectoryPath(configFilePath); + } else { + projectRoot = configFilePath; + configFilePath = this._findConfigFile(configFilePath); + if (!configFilePath) { + this._console.info(`Configuration file not found at ${projectRoot}.`); + } + } + } + } else if (projectRoot) { + // In a project-based IDE like VS Code, we should assume that the + // project root directory contains the config file. + configFilePath = this._findConfigFile(projectRoot); + + // If pyright is being executed from the command line, the working + // directory may be deep within a project, and we need to walk up the + // directory hierarchy to find the project root. + if (!configFilePath && !commandLineOptions.fromVsCodeExtension) { + configFilePath = this._findConfigFileHereOrUp(projectRoot); + } + + if (configFilePath) { + projectRoot = getDirectoryPath(configFilePath); + } else { + this._console.log(`No configuration file found.`); + configFilePath = undefined; + } + } + + if (!configFilePath) { + // See if we can find a pyproject.toml file in this directory. + pyprojectFilePath = this._findPyprojectTomlFile(projectRoot); + + if (!pyprojectFilePath && !commandLineOptions.fromVsCodeExtension) { + pyprojectFilePath = this._findPyprojectTomlFileHereOrUp(projectRoot); + } + + if (pyprojectFilePath) { + projectRoot = getDirectoryPath(pyprojectFilePath); + this._console.log(`pyproject.toml file found at ${projectRoot}.`); + } else { + this._console.log(`No pyproject.toml file found.`); + } + } + + const configOptions = new ConfigOptions(projectRoot, this._typeCheckingMode); + const defaultExcludes = ['**/node_modules', '**/__pycache__', '**/.*']; + + if (commandLineOptions.pythonPath) { + configOptions.pythonPath = commandLineOptions.pythonPath; + } + + // The pythonPlatform and pythonVersion from the command-line can be overridden + // by the config file, so initialize them upfront. + configOptions.defaultPythonPlatform = commandLineOptions.pythonPlatform; + configOptions.defaultPythonVersion = commandLineOptions.pythonVersion; + configOptions.ensureDefaultExtraPaths( + this.fs, + commandLineOptions.autoSearchPaths || false, + commandLineOptions.extraPaths + ); + + if (commandLineOptions.fileSpecs.length > 0) { + commandLineOptions.fileSpecs.forEach((fileSpec) => { + configOptions.include.push(getFileSpec(this.fs, projectRoot, fileSpec)); + }); + } + + if (commandLineOptions.excludeFileSpecs.length > 0) { + commandLineOptions.excludeFileSpecs.forEach((fileSpec) => { + configOptions.exclude.push(getFileSpec(this.fs, projectRoot, fileSpec)); + }); + } + + if (commandLineOptions.ignoreFileSpecs.length > 0) { + commandLineOptions.ignoreFileSpecs.forEach((fileSpec) => { + configOptions.ignore.push(getFileSpec(this.fs, projectRoot, fileSpec)); + }); + } + + if (!configFilePath && commandLineOptions.executionRoot) { + if (commandLineOptions.fileSpecs.length === 0) { + // If no config file was found and there are no explicit include + // paths specified, assume the caller wants to include all source + // files under the execution root path. + configOptions.include.push(getFileSpec(this.fs, commandLineOptions.executionRoot, '.')); + } + + if (commandLineOptions.excludeFileSpecs.length === 0) { + // Add a few common excludes to avoid long scan times. + defaultExcludes.forEach((exclude) => { + configOptions.exclude.push(getFileSpec(this.fs, commandLineOptions.executionRoot, exclude)); + }); + } + } + + this._configFilePath = configFilePath || pyprojectFilePath; + + // If we found a config file, parse it to compute the effective options. + let configJsonObj: object | undefined; + if (configFilePath) { + this._console.info(`Loading configuration file at ${configFilePath}`); + configJsonObj = this._parseJsonConfigFile(configFilePath); + } else if (pyprojectFilePath) { + this._console.info(`Loading pyproject.toml file at ${pyprojectFilePath}`); + configJsonObj = this._parsePyprojectTomlFile(pyprojectFilePath); + } + + if (configJsonObj) { + configOptions.initializeFromJson( + configJsonObj, + this._typeCheckingMode, + this._console, + this.fs, + host, + commandLineOptions.diagnosticSeverityOverrides, + commandLineOptions.fileSpecs.length > 0 + ); + + const configFileDir = getDirectoryPath(this._configFilePath!); + + // If no include paths were provided, assume that all files within + // the project should be included. + if (configOptions.include.length === 0) { + this._console.info(`No include entries specified; assuming ${configFileDir}`); + configOptions.include.push(getFileSpec(this.fs, configFileDir, '.')); + } + + // If there was no explicit set of excludes, add a few common ones to avoid long scan times. + if (configOptions.exclude.length === 0) { + defaultExcludes.forEach((exclude) => { + this._console.info(`Auto-excluding ${exclude}`); + configOptions.exclude.push(getFileSpec(this.fs, configFileDir, exclude)); + }); + + if (configOptions.autoExcludeVenv === undefined) { + configOptions.autoExcludeVenv = true; + } + } + } else { + configOptions.autoExcludeVenv = true; + configOptions.applyDiagnosticOverrides(commandLineOptions.diagnosticSeverityOverrides); + } + + // Override the analyzeUnannotatedFunctions setting based on the command-line setting. + if (commandLineOptions.analyzeUnannotatedFunctions !== undefined) { + configOptions.diagnosticRuleSet.analyzeUnannotatedFunctions = + commandLineOptions.analyzeUnannotatedFunctions; + } + + const reportDuplicateSetting = (settingName: string, configValue: number | string | boolean) => { + const settingSource = commandLineOptions.fromVsCodeExtension + ? 'the client settings' + : 'a command-line option'; + this._console.warn( + `The ${settingName} has been specified in both the config file and ` + + `${settingSource}. The value in the config file (${configValue}) ` + + `will take precedence` + ); + }; + + // Apply the command-line options if the corresponding + // item wasn't already set in the config file. Report any + // duplicates. + if (commandLineOptions.venvPath) { + if (!configOptions.venvPath) { + configOptions.venvPath = commandLineOptions.venvPath; + } else { + reportDuplicateSetting('venvPath', configOptions.venvPath); + } + } + + if (commandLineOptions.typeshedPath) { + if (!configOptions.typeshedPath) { + configOptions.typeshedPath = commandLineOptions.typeshedPath; + } else { + reportDuplicateSetting('typeshedPath', configOptions.typeshedPath); + } + } + + configOptions.verboseOutput = commandLineOptions.verboseOutput ?? configOptions.verboseOutput; + configOptions.checkOnlyOpenFiles = !!commandLineOptions.checkOnlyOpenFiles; + configOptions.autoImportCompletions = !!commandLineOptions.autoImportCompletions; + configOptions.indexing = !!commandLineOptions.indexing; + configOptions.taskListTokens = commandLineOptions.taskListTokens; + configOptions.logTypeEvaluationTime = !!commandLineOptions.logTypeEvaluationTime; + configOptions.typeEvaluationTimeThreshold = commandLineOptions.typeEvaluationTimeThreshold; + + // If useLibraryCodeForTypes was not specified in the config, allow the settings + // or command line to override it. + if (configOptions.useLibraryCodeForTypes === undefined) { + configOptions.useLibraryCodeForTypes = !!commandLineOptions.useLibraryCodeForTypes; + } else if (commandLineOptions.useLibraryCodeForTypes !== undefined) { + reportDuplicateSetting('useLibraryCodeForTypes', configOptions.useLibraryCodeForTypes); + } + + if (commandLineOptions.stubPath) { + if (!configOptions.stubPath) { + configOptions.stubPath = commandLineOptions.stubPath; + } else { + reportDuplicateSetting('stubPath', configOptions.stubPath); + } + } + + if (configOptions.stubPath) { + // If there was a stub path specified, validate it. + if (!this.fs.existsSync(configOptions.stubPath) || !isDirectory(this.fs, configOptions.stubPath)) { + this._console.warn(`stubPath ${configOptions.stubPath} is not a valid directory.`); + } + } else { + // If no stub path was specified, use a default path. + configOptions.stubPath = normalizePath(combinePaths(configOptions.projectRoot, defaultStubsDirectory)); + } + + // Do some sanity checks on the specified settings and report missing + // or inconsistent information. + if (configOptions.venvPath) { + if (!this.fs.existsSync(configOptions.venvPath) || !isDirectory(this.fs, configOptions.venvPath)) { + this._console.error(`venvPath ${configOptions.venvPath} is not a valid directory.`); + } + + // venvPath without venv means it won't do anything while resolveImport. + // so first, try to set venv from existing configOption if it is null. if both are null, + // then, resolveImport won't consider venv + configOptions.venv = configOptions.venv ?? this._configOptions.venv; + if (configOptions.venv) { + const fullVenvPath = combinePaths(configOptions.venvPath, configOptions.venv); + + if (!this.fs.existsSync(fullVenvPath) || !isDirectory(this.fs, fullVenvPath)) { + this._console.error( + `venv ${configOptions.venv} subdirectory not found in venv path ${configOptions.venvPath}.` + ); + } else { + const importFailureInfo: string[] = []; + if (findPythonSearchPaths(this.fs, configOptions, host, importFailureInfo) === undefined) { + this._console.error( + `site-packages directory cannot be located for venvPath ` + + `${configOptions.venvPath} and venv ${configOptions.venv}.` + ); + + if (configOptions.verboseOutput) { + importFailureInfo.forEach((diag) => { + this._console.error(` ${diag}`); + }); + } + } + } + } + } + + // Is there a reference to a venv? If so, there needs to be a valid venvPath. + if (configOptions.venv) { + if (!configOptions.venvPath) { + this._console.warn(`venvPath not specified, so venv settings will be ignored.`); + } + } + + if (configOptions.typeshedPath) { + if (!this.fs.existsSync(configOptions.typeshedPath) || !isDirectory(this.fs, configOptions.typeshedPath)) { + this._console.error(`typeshedPath ${configOptions.typeshedPath} is not a valid directory.`); + } + } + + return configOptions; + } + + private _findConfigFile(searchPath: string): string | undefined { + for (const name of configFileNames) { + const fileName = combinePaths(searchPath, name); + if (this.fs.existsSync(fileName)) { + return fileName; + } + } + return undefined; + } + + private _findConfigFileHereOrUp(searchPath: string): string | undefined { + return forEachAncestorDirectory(searchPath, (ancestor) => this._findConfigFile(ancestor)); + } + + private _findPyprojectTomlFile(searchPath: string) { + const fileName = combinePaths(searchPath, pyprojectTomlName); + if (this.fs.existsSync(fileName)) { + return fileName; + } + return undefined; + } + + private _findPyprojectTomlFileHereOrUp(searchPath: string): string | undefined { + return forEachAncestorDirectory(searchPath, (ancestor) => this._findPyprojectTomlFile(ancestor)); + } + + private _parseJsonConfigFile(configPath: string): object | undefined { + return this._attemptParseFile(configPath, (fileContents) => { + const errors: JSONC.ParseError[] = []; + const result = JSONC.parse(fileContents, errors, { allowTrailingComma: true }); + if (errors.length > 0) { + throw new Error('Errors parsing JSON file'); + } + + return result; + }); + } + + private _attemptParseFile( + filePath: string, + parseCallback: (contents: string, attempt: number) => object | undefined + ): object | undefined { + let fileContents = ''; + let parseAttemptCount = 0; + + while (true) { + // Attempt to read the file contents. + try { + fileContents = this.fs.readFileSync(filePath, 'utf8'); + } catch { + this._console.error(`Config file "${filePath}" could not be read.`); + return undefined; + } + + // Attempt to parse the file. + let parseFailed = false; + try { + return parseCallback(fileContents, parseAttemptCount + 1); + } catch (e: any) { + parseFailed = true; + } + + if (!parseFailed) { + break; + } + + // If we attempt to read the file immediately after it was saved, it + // may have been partially written when we read it, resulting in parse + // errors. We'll give it a little more time and try again. + if (parseAttemptCount++ >= 5) { + this._console.error(`Config file "${filePath}" could not be parsed. Verify that format is correct.`); + return undefined; + } + } + + return undefined; + } + + private _parsePyprojectTomlFile(pyprojectPath: string): object | undefined { + return this._attemptParseFile(pyprojectPath, (fileContents, attemptCount) => { + try { + // First, try and load tool.scip section + const configObj = TOML.parse(fileContents); + if (configObj && configObj.tool && (configObj.tool as TOML.JsonMap).scip) { + return (configObj.tool as TOML.JsonMap).scip as object; + } + + // Fall back to tool.pyright section + if (configObj && configObj.tool && (configObj.tool as TOML.JsonMap).pyright) { + return (configObj.tool as TOML.JsonMap).pyright as object; + } + } catch (e: any) { + this._console.error(`Pyproject file parse attempt ${attemptCount} error: ${JSON.stringify(e)}`); + throw e; + } + + this._console.error(`Pyproject file "${pyprojectPath}" is missing "[tool.pyright]" section.`); + return undefined; + }); + } +} diff --git a/packages/pyright-scip/src/indexer.ts b/packages/pyright-scip/src/indexer.ts index e6c664c5e..e734d3f62 100644 --- a/packages/pyright-scip/src/indexer.ts +++ b/packages/pyright-scip/src/indexer.ts @@ -5,21 +5,19 @@ import { Program } from 'pyright-internal/analyzer/program'; import { ImportResolver } from 'pyright-internal/analyzer/importResolver'; import { createFromRealFileSystem } from 'pyright-internal/common/realFileSystem'; import { ConfigOptions } from 'pyright-internal/common/configOptions'; -import { IndexResults } from 'pyright-internal/languageService/documentSymbolProvider'; import { TreeVisitor } from './treeVisitor'; import { FullAccessHost } from 'pyright-internal/common/fullAccessHost'; import * as url from 'url'; import { ScipConfig } from './lib'; import { SourceFile } from 'pyright-internal/analyzer/sourceFile'; import { Counter } from './lsif-typescript/Counter'; -import { getTypeShedFallbackPath } from 'pyright-internal/analyzer/pythonPathUtils'; import { PyrightFileSystem } from 'pyright-internal/pyrightFileSystem'; import getEnvironment from './virtualenv/environment'; import { version } from 'package.json'; -import { getFileSpec } from 'pyright-internal/common/pathUtils'; import { FileMatcher } from './FileMatcher'; import { sendStatus, StatusUpdater, withStatus } from './status'; import { scip } from './scip'; +import { ScipPyrightConfig } from './config'; export class Indexer { program: Program; @@ -39,30 +37,27 @@ export class Indexer { // have the same methods of configuring, you might just want to change the include/exclude) // // private _getConfigOptions(host: Host, commandLineOptions: CommandLineOptions): ConfigOptions { - this.pyrightConfig = new ConfigOptions(scipConfig.projectRoot); - this.pyrightConfig.checkOnlyOpenFiles = false; - this.pyrightConfig.indexing = true; - this.pyrightConfig.useLibraryCodeForTypes = true; - - const fs = new PyrightFileSystem(createFromRealFileSystem()); - this.pyrightConfig.typeshedPath = getTypeShedFallbackPath(fs); - - if (this.scipConfig.include) { - this.pyrightConfig.include = this.scipConfig.include - .split(',') - .map((pathspec) => getFileSpec(fs, process.cwd(), pathspec)); - } else { - this.pyrightConfig.include = [getFileSpec(fs, process.cwd(), '.')]; - } + let fs = new PyrightFileSystem(createFromRealFileSystem()); - if (this.scipConfig.exclude) { - this.pyrightConfig.exclude = this.scipConfig.exclude - .split(',') - .map((pathspec) => getFileSpec(fs, process.cwd(), pathspec)); - } + let config = new ScipPyrightConfig(scipConfig, fs); + this.pyrightConfig = config.getConfigOptions(); const matcher = new FileMatcher(this.pyrightConfig, fs); + this.projectFiles = new Set(matcher.matchFiles(this.pyrightConfig.include, this.pyrightConfig.exclude)); + if (scipConfig.targetOnly) { + const target = path.resolve(scipConfig.targetOnly); + const targetFiles: Set = new Set(); + for (const file of this.projectFiles) { + if (file.startsWith(target)) { + targetFiles.add(file); + } + } + + this.projectFiles = targetFiles; + } + + console.log('Total Project Files', this.projectFiles.size); const host = new FullAccessHost(fs); this.importResolver = new ImportResolver(fs, this.pyrightConfig, host); diff --git a/packages/pyright-scip/src/lib.ts b/packages/pyright-scip/src/lib.ts index 5a1f7c70b..36f0c5814 100644 --- a/packages/pyright-scip/src/lib.ts +++ b/packages/pyright-scip/src/lib.ts @@ -10,7 +10,7 @@ import { IndexOptions } from './MainCommand'; export interface ScipConfig extends IndexOptions { /** - * The directory where to generate the dump.lsif-typed file. + * The directory where to generate the index.scip file. * * All `Document.relative_path` fields will be relative paths to this directory. */ diff --git a/packages/pyright-scip/src/treeVisitor.ts b/packages/pyright-scip/src/treeVisitor.ts index 2b61f042b..eee4937d6 100644 --- a/packages/pyright-scip/src/treeVisitor.ts +++ b/packages/pyright-scip/src/treeVisitor.ts @@ -193,6 +193,8 @@ export class TreeVisitor extends ParseTreeWalker { log.info('=> Working file:', config.sourceFile.getFilePath(), '<=='); + // TODO: This should happen earlier, a bit weird to throw an error this deep + // in the traversal if (!this.config.scipConfig.projectName) { throw 'Must have project name'; } From 02e8695b84a286149251560d85acbeff564f5d28 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 1 May 2023 13:42:07 -0400 Subject: [PATCH 2/9] fixup: remove command-line-args --- packages/pyright-scip/package-lock.json | 94 ------------------------- packages/pyright-scip/package.json | 2 - 2 files changed, 96 deletions(-) diff --git a/packages/pyright-scip/package-lock.json b/packages/pyright-scip/package-lock.json index a435e9905..c85c45142 100644 --- a/packages/pyright-scip/package-lock.json +++ b/packages/pyright-scip/package-lock.json @@ -10,7 +10,6 @@ "license": "MIT", "dependencies": { "@iarna/toml": "2.2.5", - "command-line-args": "^5.2.1", "commander": "^9.2.0", "diff": "^5.0.0", "glob": "^7.2.0", @@ -25,7 +24,6 @@ "@sourcegraph/eslint-config": "0.26.0", "@sourcegraph/prettierrc": "3.0.3", "@sourcegraph/tsconfig": "4.0.1", - "@types/command-line-args": "^5.2.0", "@types/diff": "^5.0.2", "@types/glob": "^7.2.0", "@types/google-protobuf": "^3.15.5", @@ -1583,12 +1581,6 @@ "@babel/types": "^7.3.0" } }, - "node_modules/@types/command-line-args": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@types/command-line-args/-/command-line-args-5.2.0.tgz", - "integrity": "sha512-UuKzKpJJ/Ief6ufIaIzr3A/0XnluX7RvFgwkV89Yzvm77wCh1kFaFmqN8XEnGcN62EuHdedQjEMb8mYxFLGPyA==", - "dev": true - }, "node_modules/@types/diff": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/@types/diff/-/diff-5.0.2.tgz", @@ -2355,14 +2347,6 @@ "node": ">=6.0" } }, - "node_modules/array-back": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz", - "integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==", - "engines": { - "node": ">=6" - } - }, "node_modules/array-includes": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.4.tgz", @@ -2983,20 +2967,6 @@ "node": ">= 0.8" } }, - "node_modules/command-line-args": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.1.tgz", - "integrity": "sha512-H4UfQhZyakIjC74I9d34fGYDwk3XpSr17QhEd0Q3I9Xq1CETHo4Hcuo87WyWHpAF1aSLjLRf5lD9ZGX2qStUvg==", - "dependencies": { - "array-back": "^3.1.0", - "find-replace": "^3.0.0", - "lodash.camelcase": "^4.3.0", - "typical": "^4.0.0" - }, - "engines": { - "node": ">=4.0.0" - } - }, "node_modules/commander": { "version": "9.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-9.2.0.tgz", @@ -4436,17 +4406,6 @@ "node": ">=8" } }, - "node_modules/find-replace": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz", - "integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==", - "dependencies": { - "array-back": "^3.0.1" - }, - "engines": { - "node": ">=4.0.0" - } - }, "node_modules/find-up": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", @@ -7001,11 +6960,6 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, - "node_modules/lodash.camelcase": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", - "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==" - }, "node_modules/lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", @@ -9260,14 +9214,6 @@ "node": ">=4.2.0" } }, - "node_modules/typical": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz", - "integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==", - "engines": { - "node": ">=8" - } - }, "node_modules/unbox-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", @@ -11093,12 +11039,6 @@ "@babel/types": "^7.3.0" } }, - "@types/command-line-args": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@types/command-line-args/-/command-line-args-5.2.0.tgz", - "integrity": "sha512-UuKzKpJJ/Ief6ufIaIzr3A/0XnluX7RvFgwkV89Yzvm77wCh1kFaFmqN8XEnGcN62EuHdedQjEMb8mYxFLGPyA==", - "dev": true - }, "@types/diff": { "version": "5.0.2", "resolved": "https://registry.npmjs.org/@types/diff/-/diff-5.0.2.tgz", @@ -11711,11 +11651,6 @@ "@babel/runtime-corejs3": "^7.10.2" } }, - "array-back": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz", - "integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==" - }, "array-includes": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.4.tgz", @@ -12172,17 +12107,6 @@ "delayed-stream": "~1.0.0" } }, - "command-line-args": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.1.tgz", - "integrity": "sha512-H4UfQhZyakIjC74I9d34fGYDwk3XpSr17QhEd0Q3I9Xq1CETHo4Hcuo87WyWHpAF1aSLjLRf5lD9ZGX2qStUvg==", - "requires": { - "array-back": "^3.1.0", - "find-replace": "^3.0.0", - "lodash.camelcase": "^4.3.0", - "typical": "^4.0.0" - } - }, "commander": { "version": "9.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-9.2.0.tgz", @@ -13276,14 +13200,6 @@ "to-regex-range": "^5.0.1" } }, - "find-replace": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz", - "integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==", - "requires": { - "array-back": "^3.0.1" - } - }, "find-up": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", @@ -15258,11 +15174,6 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, - "lodash.camelcase": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", - "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==" - }, "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", @@ -16910,11 +16821,6 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.3.tgz", "integrity": "sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==" }, - "typical": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz", - "integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==" - }, "unbox-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", diff --git a/packages/pyright-scip/package.json b/packages/pyright-scip/package.json index 248b5bed4..3c56221a6 100644 --- a/packages/pyright-scip/package.json +++ b/packages/pyright-scip/package.json @@ -24,7 +24,6 @@ "@sourcegraph/eslint-config": "0.26.0", "@sourcegraph/prettierrc": "3.0.3", "@sourcegraph/tsconfig": "4.0.1", - "@types/command-line-args": "^5.2.0", "@types/diff": "^5.0.2", "@types/glob": "^7.2.0", "@types/google-protobuf": "^3.15.5", @@ -44,7 +43,6 @@ }, "dependencies": { "@iarna/toml": "2.2.5", - "command-line-args": "^5.2.1", "commander": "^9.2.0", "diff": "^5.0.0", "glob": "^7.2.0", From 6ea64bfb62020fd11da12e8aa838e3c5b3f2f07a Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 1 May 2023 15:27:02 -0400 Subject: [PATCH 3/9] fixup: docs --- .../snapshots/output/builtin_imports/builtin_imports.py | 2 +- .../pyright-scip/snapshots/output/unique/builtin_import_refs.py | 2 +- .../pyright-scip/snapshots/output/unique/property_access.py | 2 +- .../pyright-scip/snapshots/output/unique/vars_inside_scopes.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py b/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py index 7b939e11d..c6fdc9745 100644 --- a/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py +++ b/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py @@ -16,7 +16,7 @@ # > * Imports and exports, all public names... # > * Internal helper functions: these shou... # > * \_SpecialForm and its instances (spec... -# > Any, NoReturn, ClassVar, Union, Optional... +# > Any, NoReturn, Never, ClassVar, Union, O... # > * Classes whose instances can be type a... # > ForwardRef, TypeVar and ParamSpec # > * The core of internal generics API: \_... diff --git a/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py b/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py index 1c7e7282f..ba54ef7f0 100644 --- a/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py +++ b/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py @@ -14,7 +14,7 @@ # > * Imports and exports, all public names... # > * Internal helper functions: these shou... # > * \_SpecialForm and its instances (spec... -# > Any, NoReturn, ClassVar, Union, Optional... +# > Any, NoReturn, Never, ClassVar, Union, O... # > * Classes whose instances can be type a... # > ForwardRef, TypeVar and ParamSpec # > * The core of internal generics API: \_... diff --git a/packages/pyright-scip/snapshots/output/unique/property_access.py b/packages/pyright-scip/snapshots/output/unique/property_access.py index 87ac02a54..a06460a25 100644 --- a/packages/pyright-scip/snapshots/output/unique/property_access.py +++ b/packages/pyright-scip/snapshots/output/unique/property_access.py @@ -14,7 +14,7 @@ # > * Imports and exports, all public names... # > * Internal helper functions: these shou... # > * \_SpecialForm and its instances (spec... -# > Any, NoReturn, ClassVar, Union, Optional... +# > Any, NoReturn, Never, ClassVar, Union, O... # > * Classes whose instances can be type a... # > ForwardRef, TypeVar and ParamSpec # > * The core of internal generics API: \_... diff --git a/packages/pyright-scip/snapshots/output/unique/vars_inside_scopes.py b/packages/pyright-scip/snapshots/output/unique/vars_inside_scopes.py index f750116c0..0cfa27df7 100644 --- a/packages/pyright-scip/snapshots/output/unique/vars_inside_scopes.py +++ b/packages/pyright-scip/snapshots/output/unique/vars_inside_scopes.py @@ -14,7 +14,7 @@ # > * Imports and exports, all public names... # > * Internal helper functions: these shou... # > * \_SpecialForm and its instances (spec... -# > Any, NoReturn, ClassVar, Union, Optional... +# > Any, NoReturn, Never, ClassVar, Union, O... # > * Classes whose instances can be type a... # > ForwardRef, TypeVar and ParamSpec # > * The core of internal generics API: \_... From 514b49a06008341f17471fccd05179721214303e Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Mon, 1 May 2023 16:31:46 -0400 Subject: [PATCH 4/9] fix: unify symbol generation and add namespace --- README.md | 18 +++ .../snapshots/output/aliased_import/actual.py | 2 +- .../output/builtin_imports/builtin_imports.py | 2 +- .../output/class_nohint/class_nohint.py | 4 +- .../snapshots/output/comprehensions/comp.py | 2 +- .../snapshots/output/dunder_vars/__main__.py | 2 +- .../snapshots/output/f_string/fstring.py | 2 +- .../file_from_module_import/abc/file.py | 2 +- .../file_from_module.py | 2 +- .../output/nested_items/src/importer.py | 6 +- .../output/nested_items/src/long_importer.py | 2 +- .../output/request_goofiness/goofy.py | 2 +- .../output/unique/builtin_import_refs.py | 2 +- .../output/unique/property_access.py | 2 +- .../output/unresolved_import/unresolved.py | 4 +- packages/pyright-scip/src/MainCommand.test.ts | 1 + packages/pyright-scip/src/MainCommand.ts | 2 + packages/pyright-scip/src/config.ts | 3 +- packages/pyright-scip/src/indexer.ts | 21 ++- packages/pyright-scip/src/symbols.ts | 61 +++++++-- packages/pyright-scip/src/treeVisitor.ts | 122 ++++++------------ 21 files changed, 148 insertions(+), 116 deletions(-) diff --git a/README.md b/README.md index 8ba874b5c..e802a95ec 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,24 @@ $ # more information at https://github.com/sourcegraph/src-cli $ src code-intel upload ``` +### target-only + To run scip-python over only a particular directory, you can use the `--target-only` flag. Example: ``` $ scip-python index . --project-name=$MY_PROJECT --target-only=src/subdir ``` +### project-namespace + +Additionally, if your project is loaded with some prefix, you can use the `--project-namespace` to put a namespace before all the generated symbols for this project. + +``` +$ scip-python index . --project-name=$MY_PROJECT --project-namespace=implicit.namespace +``` + +Now all symbols will have `implicit.namespace` prepended to their symbol, so that you can use it for cross repository navigation, even if the directory structure in your current project does not explicitly show `implicit/namespace/myproject/__init__.py`. + ## Environment The environment file format is a JSON list of `PythonPackage`s. The `PythonPackage` has the following form: @@ -74,6 +86,12 @@ The environment file should be a list of these packages: ] ``` +To use the environment file, you should call scip-python like so: + +``` +$ scip-python index --project-name=$MY_PROJECT --environment=path/to/env.json +``` + If you're just using pip, this should not be required. We should calculate this from the pip environment. If you experience any bugs, please report them. The goal is that we support standard pip installation without additional configuration. If there is other python tooling that can generate this information, you can file an issue and we'll see if we can support it as well. ## Sourcegraph Example Configuration diff --git a/packages/pyright-scip/snapshots/output/aliased_import/actual.py b/packages/pyright-scip/snapshots/output/aliased_import/actual.py index 8e1121700..a6253ac5f 100644 --- a/packages/pyright-scip/snapshots/output/aliased_import/actual.py +++ b/packages/pyright-scip/snapshots/output/aliased_import/actual.py @@ -11,7 +11,7 @@ # > ``` print(A.SOME_CONSTANT) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). #external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py b/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py index c6fdc9745..ec267116f 100644 --- a/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py +++ b/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py @@ -38,7 +38,7 @@ # > ``` print(re, Callable, Optional) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). #external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/class_nohint/class_nohint.py b/packages/pyright-scip/snapshots/output/class_nohint/class_nohint.py index 545b17d76..7cec6c45e 100644 --- a/packages/pyright-scip/snapshots/output/class_nohint/class_nohint.py +++ b/packages/pyright-scip/snapshots/output/class_nohint/class_nohint.py @@ -53,7 +53,7 @@ def something(self): # > ``` # ^^^^ definition snapshot-util 0.1 class_nohint/Example#something().(self) print(self.x) -# ^^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +# ^^^^^ reference python-stdlib 3.11 builtins/print(). # external documentation ```python # > (function) def print( # > *values: object, @@ -66,7 +66,7 @@ def something(self): # ^^^^ reference snapshot-util 0.1 class_nohint/Example#something().(self) # ^ reference snapshot-util 0.1 class_nohint/Example#x. print(self.y) -# ^^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +# ^^^^^ reference python-stdlib 3.11 builtins/print(). # ^^^^ reference snapshot-util 0.1 class_nohint/Example#something().(self) # ^ reference snapshot-util 0.1 class_nohint/Example#y. diff --git a/packages/pyright-scip/snapshots/output/comprehensions/comp.py b/packages/pyright-scip/snapshots/output/comprehensions/comp.py index 8c696fde0..ab89f8f67 100644 --- a/packages/pyright-scip/snapshots/output/comprehensions/comp.py +++ b/packages/pyright-scip/snapshots/output/comprehensions/comp.py @@ -75,7 +75,7 @@ def something(x): # ^^^ definition snapshot-util 0.1 comp/var. # ^^^^ reference snapshot-util 0.1 comp/asdf. print(var) -# ^^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +# ^^^^^ reference python-stdlib 3.11 builtins/print(). # external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/dunder_vars/__main__.py b/packages/pyright-scip/snapshots/output/dunder_vars/__main__.py index ee44e14a6..ffcdc2677 100644 --- a/packages/pyright-scip/snapshots/output/dunder_vars/__main__.py +++ b/packages/pyright-scip/snapshots/output/dunder_vars/__main__.py @@ -8,7 +8,7 @@ # > __name__: str # > ``` print("main") -# ^^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +# ^^^^^ reference python-stdlib 3.11 builtins/print(). # external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/f_string/fstring.py b/packages/pyright-scip/snapshots/output/f_string/fstring.py index c4d954cc5..a40594ee7 100644 --- a/packages/pyright-scip/snapshots/output/f_string/fstring.py +++ b/packages/pyright-scip/snapshots/output/f_string/fstring.py @@ -8,7 +8,7 @@ # > ``` print(f"var: hello {var}") -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). #external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/file_from_module_import/abc/file.py b/packages/pyright-scip/snapshots/output/file_from_module_import/abc/file.py index bb8df66dd..4da5f0c4d 100644 --- a/packages/pyright-scip/snapshots/output/file_from_module_import/abc/file.py +++ b/packages/pyright-scip/snapshots/output/file_from_module_import/abc/file.py @@ -6,7 +6,7 @@ # ^^^^^^^^^^^ reference snapshot-util 0.1 `xyz.nested_file`/__init__: print(nested_file.X) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). #external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/file_from_module_import/file_from_module.py b/packages/pyright-scip/snapshots/output/file_from_module_import/file_from_module.py index 9fbeee51a..f9e22416b 100644 --- a/packages/pyright-scip/snapshots/output/file_from_module_import/file_from_module.py +++ b/packages/pyright-scip/snapshots/output/file_from_module_import/file_from_module.py @@ -6,7 +6,7 @@ # ^^^^^^^^^^^ reference snapshot-util 0.1 `xyz.nested_file`/__init__: print(nested_file.X) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). #external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/nested_items/src/importer.py b/packages/pyright-scip/snapshots/output/nested_items/src/importer.py index f22d6d5b9..cd90cbb8b 100644 --- a/packages/pyright-scip/snapshots/output/nested_items/src/importer.py +++ b/packages/pyright-scip/snapshots/output/nested_items/src/importer.py @@ -10,7 +10,7 @@ # ^^^^^^^^^^^^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar.baz.mod`/AnotherNestedMuchWow# print(SuchNestedMuchWow().class_item) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). #external documentation ```python # > (function) def print( # > *values: object, @@ -23,11 +23,11 @@ # ^^^^^^^^^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar.baz.mod`/SuchNestedMuchWow# # ^^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar.baz.mod`/SuchNestedMuchWow#class_item. print(AnotherNestedMuchWow().other_item) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). # ^^^^^^^^^^^^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar.baz.mod`/AnotherNestedMuchWow# # ^^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar.baz.mod`/AnotherNestedMuchWow#other_item. print(InitClass().init_item) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). # ^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar`/InitClass# # ^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar`/InitClass#init_item. diff --git a/packages/pyright-scip/snapshots/output/nested_items/src/long_importer.py b/packages/pyright-scip/snapshots/output/nested_items/src/long_importer.py index 7a487298e..bc76513e4 100644 --- a/packages/pyright-scip/snapshots/output/nested_items/src/long_importer.py +++ b/packages/pyright-scip/snapshots/output/nested_items/src/long_importer.py @@ -5,7 +5,7 @@ # ^^^^^^^^^^^^^^^ reference snapshot-util 0.1 `foo.bar.baz.mod`/__init__: print(foo.bar.baz.mod.SuchNestedMuchWow) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). #external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/request_goofiness/goofy.py b/packages/pyright-scip/snapshots/output/request_goofiness/goofy.py index 01c76b5c4..2306e980e 100644 --- a/packages/pyright-scip/snapshots/output/request_goofiness/goofy.py +++ b/packages/pyright-scip/snapshots/output/request_goofiness/goofy.py @@ -5,7 +5,7 @@ # ^^^^^^^^ reference requests 2.0.0 requests/__init__: print(requests.get("https://sourcegraph.com")) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). #external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py b/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py index ba54ef7f0..9ef5c684c 100644 --- a/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py +++ b/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py @@ -32,7 +32,7 @@ # > ``` print(Any) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). #external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/unique/property_access.py b/packages/pyright-scip/snapshots/output/unique/property_access.py index a06460a25..4f384d6c3 100644 --- a/packages/pyright-scip/snapshots/output/unique/property_access.py +++ b/packages/pyright-scip/snapshots/output/unique/property_access.py @@ -86,7 +86,7 @@ def nested(): # ^ definition local 0 # ^^ reference snapshot-util 0.1 property_access/usage().(xs) print(x.prop_ref) -# ^^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +# ^^^^^ reference python-stdlib 3.11 builtins/print(). # external documentation ```python # > (function) def print( # > *values: object, diff --git a/packages/pyright-scip/snapshots/output/unresolved_import/unresolved.py b/packages/pyright-scip/snapshots/output/unresolved_import/unresolved.py index c47b33fcb..602259f89 100644 --- a/packages/pyright-scip/snapshots/output/unresolved_import/unresolved.py +++ b/packages/pyright-scip/snapshots/output/unresolved_import/unresolved.py @@ -6,7 +6,7 @@ # documentation (module): this_is_not_real [unable to re... print(this_is_not_real.x) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). #external documentation ```python # > (function) def print( # > *values: object, @@ -18,7 +18,7 @@ # > ``` # ^^^^^^^^^^^^^^^^ reference local 0 print(this_is_not_real.x) -#^^^^ reference python-stdlib 3.11 builtins/__init__:print(). +#^^^^ reference python-stdlib 3.11 builtins/print(). # ^^^^^^^^^^^^^^^^ reference local 0 diff --git a/packages/pyright-scip/src/MainCommand.test.ts b/packages/pyright-scip/src/MainCommand.test.ts index bec8bc2db..5d43310a1 100644 --- a/packages/pyright-scip/src/MainCommand.test.ts +++ b/packages/pyright-scip/src/MainCommand.test.ts @@ -29,3 +29,4 @@ checkIndexParser(['--quiet'], { quiet: true }); checkIndexParser(['--show-progress-rate-limit', '120'], { showProgressRateLimit: 120 }); checkIndexParser(['--show-progress-rate-limit', '0.5'], { showProgressRateLimit: 0.5 }); checkIndexParser(['--target-only', 'foo'], { targetOnly: 'foo' }); +checkIndexParser(['--project-namespace', 'LSP'], { projectNamespace: 'LSP' }); diff --git a/packages/pyright-scip/src/MainCommand.ts b/packages/pyright-scip/src/MainCommand.ts index 0b108d621..97734017f 100644 --- a/packages/pyright-scip/src/MainCommand.ts +++ b/packages/pyright-scip/src/MainCommand.ts @@ -5,6 +5,7 @@ export interface IndexOptions { project: string; projectName: string; projectVersion: string; + projectNamespace?: string; snapshotDir: string; environment?: string; dev: boolean; @@ -54,6 +55,7 @@ export function mainCommand( .command('index') .requiredOption('--project-name ', 'the name of the current project, pypi name if applicable') .option('--project-version ', 'the version of the current project, defaults to git revision') + .option('--project-namespace ', 'A prefix to prepend to all module definitions in the current index') .option('--cwd ', 'working directory for executing scip-python', process.cwd()) .option('--target-only ', 'limit analysis to the following path') .option('--output ', 'path to the output file', DEFAULT_OUTPUT_FILE) diff --git a/packages/pyright-scip/src/config.ts b/packages/pyright-scip/src/config.ts index 40a9b8bad..9d21c96c6 100644 --- a/packages/pyright-scip/src/config.ts +++ b/packages/pyright-scip/src/config.ts @@ -15,7 +15,6 @@ import { isDirectory, getFileSpec, } from 'pyright-internal/common/pathUtils'; -import { createFromRealFileSystem } from 'pyright-internal/common/realFileSystem'; import { PyrightFileSystem } from 'pyright-internal/pyrightFileSystem'; import { ScipConfig } from './lib'; @@ -41,6 +40,8 @@ export class ScipPyrightConfig { getConfigOptions(): ConfigOptions { const host = new FullAccessHost(this.fs); + + // TODO: This probably should be ScipConfig.workspaceroot or similar? const options = new CommandLineOptions(process.cwd(), false); let config = this._getConfigOptions(host, options); diff --git a/packages/pyright-scip/src/indexer.ts b/packages/pyright-scip/src/indexer.ts index e734d3f62..3f632c914 100644 --- a/packages/pyright-scip/src/indexer.ts +++ b/packages/pyright-scip/src/indexer.ts @@ -18,6 +18,7 @@ import { FileMatcher } from './FileMatcher'; import { sendStatus, StatusUpdater, withStatus } from './status'; import { scip } from './scip'; import { ScipPyrightConfig } from './config'; +import { setProjectNamespace } from './symbols'; export class Indexer { program: Program; @@ -46,10 +47,10 @@ export class Indexer { this.projectFiles = new Set(matcher.matchFiles(this.pyrightConfig.include, this.pyrightConfig.exclude)); if (scipConfig.targetOnly) { - const target = path.resolve(scipConfig.targetOnly); + scipConfig.targetOnly = path.resolve(scipConfig.targetOnly); const targetFiles: Set = new Set(); for (const file of this.projectFiles) { - if (file.startsWith(target)) { + if (file.startsWith(scipConfig.targetOnly)) { targetFiles.add(file); } } @@ -64,6 +65,10 @@ export class Indexer { this.program = new Program(this.importResolver, this.pyrightConfig); this.program.setTrackedFiles([...this.projectFiles]); + + if (scipConfig.projectNamespace) { + setProjectNamespace(scipConfig.projectName, this.scipConfig.projectNamespace!); + } } public index(): void { @@ -92,7 +97,7 @@ export class Indexer { this.scipConfig.writeIndex( new scip.Index({ metadata: new scip.Metadata({ - project_root: url.pathToFileURL(this.scipConfig.workspaceRoot).toString(), + project_root: url.pathToFileURL(this.getProjectRoot()).toString(), text_document_encoding: scip.TextEncoding.UTF8, tool_info: new scip.ToolInfo({ name: 'scip-python', @@ -143,7 +148,7 @@ export class Indexer { const filepath = sourceFile.getFilePath(); let doc = new scip.Document({ - relative_path: path.relative(this.scipConfig.workspaceRoot, filepath), + relative_path: path.relative(this.getProjectRoot(), filepath), }); const parseResults = sourceFile.getParseResults(); @@ -191,4 +196,12 @@ export class Indexer { sendStatus(`Sucessfully wrote SCIP index to ${this.scipConfig.output}`); } + + private getProjectRoot(): string { + if (this.scipConfig.targetOnly && this.scipConfig.targetOnly !== '') { + return this.scipConfig.targetOnly; + } else { + return this.scipConfig.workspaceRoot; + } + } } diff --git a/packages/pyright-scip/src/symbols.ts b/packages/pyright-scip/src/symbols.ts index b3a827cbb..a3b3d5b15 100644 --- a/packages/pyright-scip/src/symbols.ts +++ b/packages/pyright-scip/src/symbols.ts @@ -1,34 +1,79 @@ import { ParseNode } from 'pyright-internal/parser/parseNodes'; import { Counter } from './lsif-typescript/Counter'; -import { metaDescriptor, packageDescriptor, typeDescriptor } from './lsif-typescript/Descriptor'; +import { + metaDescriptor, + methodDescriptor, + packageDescriptor, + parameterDescriptor, + termDescriptor, + typeDescriptor, +} from './lsif-typescript/Descriptor'; import { ScipSymbol } from './ScipSymbol'; import PythonPackage from './virtualenv/PythonPackage'; -export function pythonModule(pythonPackage: PythonPackage, moduleName: string): ScipSymbol { - return ScipSymbol.global( - ScipSymbol.global(ScipSymbol.package(pythonPackage.name, pythonPackage.version), packageDescriptor(moduleName)), - metaDescriptor('__init__') - ); +let namespaces: Map = new Map(); + +export function setProjectNamespace(packageName: string, projectName: string): void { + namespaces.set(packageName, projectName); } export function makePackage(pythonPackage: PythonPackage): ScipSymbol { return ScipSymbol.package(pythonPackage.name, pythonPackage.version); } -export function makeModule(moduleName: string, pythonPackage: PythonPackage): ScipSymbol { +export function makeModule(pythonPackage: PythonPackage, moduleName: string): ScipSymbol { + let ns = namespaces.get(pythonPackage.name); + if (ns) { + moduleName = ns + '.' + moduleName; + } + + return ScipSymbol.global(makePackage(pythonPackage), packageDescriptor(moduleName)); +} + +export function makeModuleInit(pythonPackage: PythonPackage, moduleName: string): ScipSymbol { + let ns = namespaces.get(pythonPackage.name); + if (ns) { + moduleName = ns + '.' + moduleName; + } + return ScipSymbol.global( ScipSymbol.global(makePackage(pythonPackage), packageDescriptor(moduleName)), metaDescriptor('__init__') ); } -export function makeClass(pythonPackage: PythonPackage, moduleName: string, name: string) { +export function makeClass(pythonPackage: PythonPackage, moduleName: string, name: string): ScipSymbol { + let ns = namespaces.get(pythonPackage.name); + if (ns) { + moduleName = ns + '.' + moduleName; + } + return ScipSymbol.global( ScipSymbol.global(makePackage(pythonPackage), packageDescriptor(moduleName)), typeDescriptor(name) ); } +export function makeParameter(sym: ScipSymbol, name: string): ScipSymbol { + return ScipSymbol.global(sym, parameterDescriptor(name)); +} + +export function makeMeta(sym: ScipSymbol, meta: string): ScipSymbol { + return ScipSymbol.global(sym, metaDescriptor(meta)); +} + +export function makeMethod(parent: ScipSymbol, name: string): ScipSymbol { + return ScipSymbol.global(parent, methodDescriptor(name)); +} + +export function makeType(parent: ScipSymbol, name: string): ScipSymbol { + return ScipSymbol.global(parent, typeDescriptor(name)); +} + +export function makeTerm(parent: ScipSymbol, name: string): ScipSymbol { + return ScipSymbol.global(parent, termDescriptor(name)); +} + export function make(_node: ParseNode, counter: Counter): ScipSymbol { return ScipSymbol.local(counter.next()); } diff --git a/packages/pyright-scip/src/treeVisitor.ts b/packages/pyright-scip/src/treeVisitor.ts index eee4937d6..42fcd79e7 100644 --- a/packages/pyright-scip/src/treeVisitor.ts +++ b/packages/pyright-scip/src/treeVisitor.ts @@ -26,14 +26,6 @@ import { import * as ModifiedTypeUtils from './ModifiedTypeUtils'; import { scip } from './scip'; import * as Symbols from './symbols'; -import { - metaDescriptor, - methodDescriptor, - packageDescriptor, - parameterDescriptor, - termDescriptor, - typeDescriptor, -} from './lsif-typescript/Descriptor'; import { ScipSymbol } from './ScipSymbol'; import { Position } from './lsif-typescript/Position'; import { Range } from './lsif-typescript/Range'; @@ -61,7 +53,6 @@ import { Event } from 'vscode-languageserver'; import { HoverResults } from 'pyright-internal/languageService/hoverProvider'; import { convertDocStringToMarkdown } from 'pyright-internal/analyzer/docStringConversion'; import { assert } from 'pyright-internal/common/debug'; -import { createTracePrinter } from 'pyright-internal/analyzer/tracePrinter'; import { getClassFieldsRecursive } from 'pyright-internal/analyzer/typeUtils'; // Useful functions for later, but haven't gotten far enough yet to use them. @@ -83,8 +74,8 @@ function softAssert(expression: any, message: string, ...exprs: any) { return expression; } +// const _printer = createTracePrinter([process.cwd()]); const _msgs = new Set(); -const _printer = createTracePrinter([process.cwd()]); const _transform = function (exprs: any[]): any[] { const result: any[] = []; for (let i = 0; i < exprs.length; i++) { @@ -237,7 +228,7 @@ export class TreeVisitor extends ParseTreeWalker { const pythonPackage = this.getPackageInfo(node, fileInfo.moduleName); if (pythonPackage) { if (softAssert(pythonPackage === this.projectPackage, 'expected pythonPackage to be this.projectPackage')) { - const symbol = Symbols.makeModule(fileInfo.moduleName, pythonPackage); + const symbol = Symbols.makeModuleInit(pythonPackage, fileInfo.moduleName); this.document.occurrences.push( new scip.Occurrence({ @@ -524,13 +515,13 @@ export class TreeVisitor extends ParseTreeWalker { importInfo.resolvedPaths[0] && path.resolve(importInfo.resolvedPaths[0]).startsWith(this.cwd) ) { - const symbol = Symbols.makeModule(moduleName, this.projectPackage); + const symbol = Symbols.makeModuleInit(this.projectPackage, moduleName); this.pushNewOccurrence(node.module, symbol); } else { const pythonPackage = this.moduleNameNodeToPythonPackage(node.module); if (pythonPackage) { - const symbol = Symbols.makeModule(moduleName, pythonPackage); + const symbol = Symbols.makeModuleInit(pythonPackage, moduleName); this.pushNewOccurrence(node.module, symbol); } else { // For python packages & modules that we cannot resolve, @@ -584,8 +575,6 @@ export class TreeVisitor extends ParseTreeWalker { } private emitDeclaration(node: NameNode, decl: Declaration): boolean { - log.debug(' emitDeclaration:'); - log.debug(' decl:', () => _printer.print(decl)); const parent = node.parent!; if (!decl.node) { @@ -603,7 +592,6 @@ export class TreeVisitor extends ParseTreeWalker { } const isDefinition = decl.node.id === parent.id; - log.debug(' node:', ParseTreeUtils.printParseNodeType(decl.node.nodeType), isDefinition); const builtinType = this.evaluator.getBuiltInType(node, node.value); if (this.isStdlib(decl, builtinType)) { @@ -632,7 +620,7 @@ export class TreeVisitor extends ParseTreeWalker { assert(declNode != node.parent, 'Must not be the definition'); assert(pythonPackage, 'Must have a python package: ' + moduleName); - return Symbols.makeModule(moduleName, pythonPackage); + return Symbols.makeModuleInit(pythonPackage, moduleName); }); // TODO: We could maybe cache this to not always be asking for these names & decls @@ -871,8 +859,6 @@ export class TreeVisitor extends ParseTreeWalker { } override visitName(node: NameNode): boolean { - log.debug('\nVisiting Name:', node.value); - if (!node.parent) { throw `No parent for named node: ${node.token.value}`; } @@ -881,10 +867,8 @@ export class TreeVisitor extends ParseTreeWalker { return true; } - const parent = node.parent; const decls = this.evaluator.getDeclarationsForNameNode(node) || []; - log.debug(' ParentParsenodeType:', ParseTreeUtils.printParseNodeType, parent.nodeType); if (decls.length === 0) { return this.emitNameWithoutDeclaration(node); } @@ -1026,14 +1010,9 @@ export class TreeVisitor extends ParseTreeWalker { return symbol; } case TypeCategory.Module: { - const symbol = ScipSymbol.global( - ScipSymbol.package(builtinType.moduleName, this.stdlibPackage.version), - metaDescriptor('__init__') - ); - + const symbol = Symbols.makeModuleInit(this.stdlibPackage, builtinType.moduleName); this.pushNewOccurrence(node, symbol); - // const pythonPackage = this.getPackageInfo(node, builtinType.moduleName)!; this.emitExternalSymbolInformation(node, symbol, []); return symbol; } @@ -1071,12 +1050,9 @@ export class TreeVisitor extends ParseTreeWalker { case ParseNodeType.Module: { moduleName = getFileInfo(node).moduleName; if (moduleName === 'builtins') { - return Symbols.makeModule('builtins', this.stdlibPackage); + return Symbols.makeModule(this.stdlibPackage, 'builtins'); } else { - return ScipSymbol.global( - ScipSymbol.package(pythonPackage.name, pythonPackage.version), - packageDescriptor(moduleName) - ); + return Symbols.makeModule(pythonPackage, moduleName); } } case ParseNodeType.ModuleName: { @@ -1097,12 +1073,9 @@ export class TreeVisitor extends ParseTreeWalker { pythonPackage = this.stdlibPackage; } - return ScipSymbol.global( - ScipSymbol.global( - ScipSymbol.package(pythonPackage.name, pythonPackage.version), - packageDescriptor(node.nameParts.map((namePart) => namePart.value).join('.')) - ), - metaDescriptor('__init__') + return Symbols.makeModuleInit( + pythonPackage, + node.nameParts.map((namePart) => namePart.value).join('.') ); } case ParseNodeType.MemberAccess: { @@ -1115,27 +1088,18 @@ export class TreeVisitor extends ParseTreeWalker { return ScipSymbol.local(this.counter.next()); } - return ScipSymbol.global(this.getScipSymbol(node.parent!), parameterDescriptor(node.name.value)); + return Symbols.makeParameter(this.getScipSymbol(node.parent!), node.name.value); } case ParseNodeType.Class: { - return ScipSymbol.global( - this.getScipSymbol(node.parent!), - typeDescriptor((node as ClassNode).name.value) - ); + return Symbols.makeType(this.getScipSymbol(node.parent!), (node as ClassNode).name.value); } case ParseNodeType.Function: { let cls = ParseTreeUtils.getEnclosingClass(node, false); if (cls) { - return ScipSymbol.global( - this.getScipSymbol(cls), - methodDescriptor((node as FunctionNode).name!.value) - ); + return Symbols.makeMethod(this.getScipSymbol(cls), (node as FunctionNode).name!.value); } - return ScipSymbol.global( - this.getScipSymbol(node.parent!), - methodDescriptor((node as FunctionNode).name!.value) - ); + return Symbols.makeMethod(this.getScipSymbol(node.parent!), (node as FunctionNode).name!.value); } case ParseNodeType.Suite: { if (node.parent) { @@ -1144,7 +1108,7 @@ export class TreeVisitor extends ParseTreeWalker { // TODO: Not sure what to do about this... // I don't know if we ever need to include this at all. - return ScipSymbol.global(this.getScipSymbol(node.parent!), metaDescriptor('#')); + return Symbols.makeMeta(this.getScipSymbol(node.parent!), '#'); } case ParseNodeType.Name: { const parent = node.parent; @@ -1162,15 +1126,12 @@ export class TreeVisitor extends ParseTreeWalker { return this.getSymbolOnce(node, () => { const pythonPackage = this.getPackageInfo(node, bound.details.moduleName)!; - let symbol = ScipSymbol.global( - ScipSymbol.global( - ScipSymbol.global( - ScipSymbol.package(pythonPackage.name, pythonPackage.version), - packageDescriptor(bound.details.moduleName) - ), - typeDescriptor(bound.details.name) + let symbol = Symbols.makeTerm( + Symbols.makeType( + Symbols.makeModule(pythonPackage, bound.details.moduleName), + bound.details.name ), - termDescriptor(node.value) + node.value ); // TODO: We might not want to do this if it's not the definition? @@ -1201,17 +1162,14 @@ export class TreeVisitor extends ParseTreeWalker { } } - return ScipSymbol.global( - this.getScipSymbol(enclosingSuite || parent), - termDescriptor((node as NameNode).value) - ); + return Symbols.makeTerm(this.getScipSymbol(enclosingSuite || parent), (node as NameNode).value); } case ParseNodeType.TypeAnnotation: { switch (node.valueExpression.nodeType) { case ParseNodeType.Name: { - return ScipSymbol.global( + return Symbols.makeTerm( this.getScipSymbol(ParseTreeUtils.getEnclosingSuite(node) || node.parent!), - termDescriptor(node.valueExpression.value) + node.valueExpression.value ); } default: { @@ -1221,10 +1179,10 @@ export class TreeVisitor extends ParseTreeWalker { } } case ParseNodeType.FunctionAnnotation: { - return ScipSymbol.global( + return Symbols.makeTerm( this.getScipSymbol(node.parent!), // Descriptor.term((node as TypeAnnotationNode).typeAnnotation) - termDescriptor('FuncAnnotation') + 'FuncAnnotation' ); } case ParseNodeType.Decorator: { @@ -1246,7 +1204,7 @@ export class TreeVisitor extends ParseTreeWalker { return this.getScipSymbol(node.parent!); } case ParseNodeType.ImportAs: { - return Symbols.pythonModule(pythonPackage, moduleName); + return Symbols.makeModuleInit(pythonPackage, moduleName); } case ParseNodeType.ImportFrom: { const importPackage = this.moduleNameNodeToPythonPackage(node.module); @@ -1285,9 +1243,9 @@ export class TreeVisitor extends ParseTreeWalker { const pythonPackage = this.moduleNameNodeToPythonPackage(parent.module) || this.projectPackage; - return Symbols.makeModule( - [...parent.module.nameParts, node.name].map((part) => part.value).join('.'), - pythonPackage + return Symbols.makeModuleInit( + pythonPackage, + [...parent.module.nameParts, node.name].map((part) => part.value).join('.') ); } } @@ -1346,6 +1304,9 @@ export class TreeVisitor extends ParseTreeWalker { // Take a `Type` from pyright and turn that into an LSIF symbol. private typeToSymbol(node: NameNode, declNode: ParseNode, typeObj: Type): ScipSymbol { if (Types.isFunction(typeObj)) { + // TODO: Possibly worth checking for parent declarations. + // I'm not sure if that will actually work though for types. + const decl = typeObj.details.declaration; if (!decl) { // throw 'Unhandled missing declaration for type: function'; @@ -1371,18 +1332,12 @@ export class TreeVisitor extends ParseTreeWalker { classType.details.name ); - return ScipSymbol.global(symbol, methodDescriptor(node.value)); + return Symbols.makeMethod(symbol, node.value); } - // return ScipSymbol.global(this.makeScipSymbol( + return ScipSymbol.local(this.counter.next()); } else { - return ScipSymbol.global( - ScipSymbol.global( - ScipSymbol.package(pythonPackage?.name, pythonPackage?.version), - packageDescriptor(typeObj.details.moduleName) - ), - methodDescriptor(node.value) - ); + return Symbols.makeMethod(Symbols.makeModule(pythonPackage, typeObj.details.moduleName), node.value); } } else if (Types.isClass(typeObj)) { const pythonPackage = this.getPackageInfo(node, typeObj.details.moduleName)!; @@ -1395,10 +1350,7 @@ export class TreeVisitor extends ParseTreeWalker { throw 'typevar'; } else if (Types.isModule(typeObj)) { const pythonPackage = this.getPackageInfo(node, typeObj.moduleName)!; - return ScipSymbol.global( - ScipSymbol.package(typeObj.moduleName, pythonPackage.version), - metaDescriptor('__init__') - ); + return Symbols.makeModuleInit(pythonPackage, typeObj.moduleName); } else if (Types.isOverloadedFunction(typeObj)) { if (!typeObj.overloads) { softAssert(false, "Didn't think it would be possible to have overloaded w/ no overloads"); From 35d7f798fbf0e9e1cb0e3d007bd85fd2339c1478 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Wed, 3 May 2023 12:15:02 -0400 Subject: [PATCH 5/9] update ci and do not crash --- .github/workflows/scip-snapshot.yml | 9 +-------- .tool-versions | 2 ++ .../output/builtin_imports/builtin_imports.py | 2 +- .../output/unique/builtin_import_refs.py | 2 +- .../output/unique/property_access.py | 2 +- .../output/unique/vars_inside_scopes.py | 2 +- packages/pyright-scip/src/indexer.ts | 20 ++++++++++++++++++- 7 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 .tool-versions diff --git a/.github/workflows/scip-snapshot.yml b/.github/workflows/scip-snapshot.yml index aeab70e6d..f1dfb97bb 100644 --- a/.github/workflows/scip-snapshot.yml +++ b/.github/workflows/scip-snapshot.yml @@ -1,8 +1,5 @@ name: scip-snapshots -env: - NODE_VERSION: '16.7.0' - on: push: branches: @@ -16,11 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 - with: - node-version: ${{ env.NODE_VERSION }} - registry-url: 'https://registry.npmjs.org' - + - uses: asdf-vm/actions/install@v2 - name: Get npm cache directory id: npm-cache run: | diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 000000000..cdb9f849c --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +python 3.10.11 +nodejs 18.16.0 diff --git a/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py b/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py index ec267116f..e14550560 100644 --- a/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py +++ b/packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py @@ -16,7 +16,7 @@ # > * Imports and exports, all public names... # > * Internal helper functions: these shou... # > * \_SpecialForm and its instances (spec... -# > Any, NoReturn, Never, ClassVar, Union, O... +# > Any, NoReturn, ClassVar, Union, Optional... # > * Classes whose instances can be type a... # > ForwardRef, TypeVar and ParamSpec # > * The core of internal generics API: \_... diff --git a/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py b/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py index 9ef5c684c..39a77a9e2 100644 --- a/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py +++ b/packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py @@ -14,7 +14,7 @@ # > * Imports and exports, all public names... # > * Internal helper functions: these shou... # > * \_SpecialForm and its instances (spec... -# > Any, NoReturn, Never, ClassVar, Union, O... +# > Any, NoReturn, ClassVar, Union, Optional... # > * Classes whose instances can be type a... # > ForwardRef, TypeVar and ParamSpec # > * The core of internal generics API: \_... diff --git a/packages/pyright-scip/snapshots/output/unique/property_access.py b/packages/pyright-scip/snapshots/output/unique/property_access.py index 4f384d6c3..1db148992 100644 --- a/packages/pyright-scip/snapshots/output/unique/property_access.py +++ b/packages/pyright-scip/snapshots/output/unique/property_access.py @@ -14,7 +14,7 @@ # > * Imports and exports, all public names... # > * Internal helper functions: these shou... # > * \_SpecialForm and its instances (spec... -# > Any, NoReturn, Never, ClassVar, Union, O... +# > Any, NoReturn, ClassVar, Union, Optional... # > * Classes whose instances can be type a... # > ForwardRef, TypeVar and ParamSpec # > * The core of internal generics API: \_... diff --git a/packages/pyright-scip/snapshots/output/unique/vars_inside_scopes.py b/packages/pyright-scip/snapshots/output/unique/vars_inside_scopes.py index 0cfa27df7..f750116c0 100644 --- a/packages/pyright-scip/snapshots/output/unique/vars_inside_scopes.py +++ b/packages/pyright-scip/snapshots/output/unique/vars_inside_scopes.py @@ -14,7 +14,7 @@ # > * Imports and exports, all public names... # > * Internal helper functions: these shou... # > * \_SpecialForm and its instances (spec... -# > Any, NoReturn, Never, ClassVar, Union, O... +# > Any, NoReturn, ClassVar, Union, Optional... # > * Classes whose instances can be type a... # > ForwardRef, TypeVar and ParamSpec # > * The core of internal generics API: \_... diff --git a/packages/pyright-scip/src/indexer.ts b/packages/pyright-scip/src/indexer.ts index 3f632c914..5266d293a 100644 --- a/packages/pyright-scip/src/indexer.ts +++ b/packages/pyright-scip/src/indexer.ts @@ -77,8 +77,26 @@ export class Indexer { onCancellationRequested: Event.None, }; + let failedAnalysis = 0; + let safe_analyze = () => { + try { + return this.program.analyze({ openFilesTimeInMs: 10000, noOpenFilesTimeInMs: 10000 }); + } catch (e) { + // Allow 100 failed attempts before we give up analysis. + // This shouldn't happen often because it means there's a bug in pyright that + // completely stops execution. You'll at least get some output even if it is failing. + sendStatus(` Analysis partially failed with (${failedAnalysis}/100): ${e}`); + if (failedAnalysis++ < 100) { + return true; + } else { + sendStatus(` Cancelling analysis, but continuing to write index. Please file an issue`); + return false; + } + } + }; + const analyzer_fn = (progress: StatusUpdater) => { - while (this.program.analyze({ openFilesTimeInMs: 10000, noOpenFilesTimeInMs: 10000 })) { + while (safe_analyze()) { const filesCompleted = this.program.getFileCount() - this.program.getFilesToAnalyzeCount(); const filesTotal = this.program.getFileCount(); progress.message(`${filesCompleted} / ${filesTotal}`); From 5754f9c34e243a0cb0973e5283336e14669a6e59 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Wed, 3 May 2023 12:24:29 -0400 Subject: [PATCH 6/9] fixpu: docs --- .github/workflows/scip-snapshot.yml | 4 ---- packages/pyright-scip/CHANGELOG.md | 8 ++++++++ 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 packages/pyright-scip/CHANGELOG.md diff --git a/.github/workflows/scip-snapshot.yml b/.github/workflows/scip-snapshot.yml index f1dfb97bb..6da6d1af1 100644 --- a/.github/workflows/scip-snapshot.yml +++ b/.github/workflows/scip-snapshot.yml @@ -14,10 +14,6 @@ jobs: steps: - uses: actions/checkout@v2 - uses: asdf-vm/actions/install@v2 - - name: Get npm cache directory - id: npm-cache - run: | - echo "::set-output name=dir::$(npm config get cache)" - uses: actions/cache@v2 with: path: ${{ steps.npm-cache.outputs.dir }} diff --git a/packages/pyright-scip/CHANGELOG.md b/packages/pyright-scip/CHANGELOG.md new file mode 100644 index 000000000..c52bf569f --- /dev/null +++ b/packages/pyright-scip/CHANGELOG.md @@ -0,0 +1,8 @@ +# Release v0.4 + +- remove: `--include` and `--exclude`. Instead use `pyproject.toml` and pyright configuration. +- add: `--target-only` to only emit and parse information related to some subdirectory of your project. Should still be run from root of project. +- add: `--project-namespace` to prefix any definitions in your current project. This can be useful when your package gets installed in some non-standard way and there doesn't have the appropriate prefix that other python packages would import from. +- Now respects pyright config by default (and discovers applicable pyright configuration). +- Updated pyright internal library +- Attempt to capture possible failures in pyright library so some indexing can still be completed. From 1c46a2837d2ed14953a897c77a43d3844169121d Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Wed, 3 May 2023 12:32:38 -0400 Subject: [PATCH 7/9] attempt to cache asdf --- .github/workflows/scip-snapshot.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/scip-snapshot.yml b/.github/workflows/scip-snapshot.yml index 6da6d1af1..39141d82f 100644 --- a/.github/workflows/scip-snapshot.yml +++ b/.github/workflows/scip-snapshot.yml @@ -13,7 +13,21 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: asdf-vm/actions/install@v2 + - name: Install asdf. + uses: asdf-vm/actions/setup@v2.1.0 + - name: Cache asdf and asdf-managed tools. + uses: actions/cache@v3.3.1 + id: asdf-cache + with: + path: ${{ env.ASDF_DIR }} + key: asdf-${{ runner.os}}-${{ hashFiles('**/.tool-versions') }} + - name: Install asdf tools (if not cached). + if: steps.asdf-cache.outputs.cache-hit != 'true' + uses: asdf-vm/actions/install@v2.1.0 + - name: Get npm cache directory + id: npm-cache + run: | + echo "::set-output name=dir::$(npm config get cache)" - uses: actions/cache@v2 with: path: ${{ steps.npm-cache.outputs.dir }} From 437bf544f3c5a98901fb4262d3100fb42a44cec2 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Wed, 3 May 2023 12:38:07 -0400 Subject: [PATCH 8/9] try new gh style --- .github/workflows/scip-snapshot.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/scip-snapshot.yml b/.github/workflows/scip-snapshot.yml index 39141d82f..d7ef429f8 100644 --- a/.github/workflows/scip-snapshot.yml +++ b/.github/workflows/scip-snapshot.yml @@ -26,8 +26,7 @@ jobs: uses: asdf-vm/actions/install@v2.1.0 - name: Get npm cache directory id: npm-cache - run: | - echo "::set-output name=dir::$(npm config get cache)" + run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT - uses: actions/cache@v2 with: path: ${{ steps.npm-cache.outputs.dir }} From 0f34d21604e9aa1254dee4a662b969a3283fd0b0 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Wed, 3 May 2023 12:48:34 -0400 Subject: [PATCH 9/9] format --- .github/workflows/scip-snapshot.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/scip-snapshot.yml b/.github/workflows/scip-snapshot.yml index d7ef429f8..7bc4e1f26 100644 --- a/.github/workflows/scip-snapshot.yml +++ b/.github/workflows/scip-snapshot.yml @@ -35,9 +35,6 @@ jobs: ${{ runner.os }}-node- - run: npm install - - run: cd ./packages/pyright-scip/ && npm install && npm run build - - run: python --version - - run: cd ./packages/pyright-scip/ && npm run check-snapshots