8000 feat: re-use pyright config by tjdevries · Pull Request #77 · sourcegraph/scip-python · GitHub
[go: up one dir, main page]

Skip to content

feat: re-use pyright config #77

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

Merged
merged 9 commits into from
May 3, 2023
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
23 changes: 11 additions & 12 deletions .github/workflows/scip-snapshot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: scip-snapshots

env:
NODE_VERSION: '16.7.0'

on:
push:
branches:
Expand All @@ -16,15 +13,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@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:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'

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)"
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
- uses: actions/cache@v2
with:
path: ${{ steps.npm-cache.outputs.dir }}
Expand All @@ -33,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
< 8000 div class="file-info flex-auto min-width-0 mb-md-0 mb-2"> 2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python 3.10.11
nodejs 18.16.0
70 changes: 69 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,87 @@ $ 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
```

### 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:

```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": [..] },
...
]
```

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

Using the usage example above may be quite simple to add a CI pipeline (perhaps using the `sourcegraph/scip-python:autoindex`) image
Expand Down
8 changes: 8 additions & 0 deletions packages/pyright-scip/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 11 additions & 0 deletions packages/pyright-scip/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/pyright-scip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -42,6 +42,7 @@
"webpack-cli": "^4.9.1"
},
"dependencies": {
"@iarna/toml": "2.2.5",
"commander": "^9.2.0",
"diff": "^5.0.0",
"glob": "^7.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-scip/snapshots/output/f_string/fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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


4 changes: 3 additions & 1 deletion packages/pyright-scip/src/MainCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ 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' });
checkIndexParser(['--project-namespace', 'LSP'], { projectNamespace: 'LSP' });
Loading
0