Skip to content

Commit 5bbe067

Browse files
authored
feat: re-use pyright config (#77)
In addition, added a few smaller features related to this as described in the CHANGELOG.md entry that was created.
1 parent d902e78 commit 5bbe067

File tree

27 files changed

+718
-159
lines changed

27 files changed

+718
-159
lines changed

.github/workflows/scip-snapshot.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: scip-snapshots
22

3-
env:
4-
NODE_VERSION: '16.7.0'
5-
63
on:
74
push:
85
branches:
@@ -16,15 +13,20 @@ jobs:
1613
runs-on: ubuntu-latest
1714
steps:
1815
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v2
16+
- name: Install asdf.
17+
uses: asdf-vm/actions/setup@v2.1.0
18+
- name: Cache asdf and asdf-managed tools.
19+
uses: actions/cache@v3.3.1
20+
id: asdf-cache
2021
with:
21-
node-version: ${{ env.NODE_VERSION }}
22-
registry-url: 'https://registry.npmjs.org'
23-
22+
path: ${{ env.ASDF_DIR }}
23+
key: asdf-${{ runner.os}}-${{ hashFiles('**/.tool-versions') }}
24+
- name: Install asdf tools (if not cached).
25+
if: steps.asdf-cache.outputs.cache-hit != 'true'
26+
uses: asdf-vm/actions/install@v2.1.0
2427
- name: Get npm cache directory
2528
id: npm-cache
26-
run: |
27-
echo "::set-output name=dir::$(npm config get cache)"
29+
run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT
2830
- uses: actions/cache@v2
2931
with:
3032
path: ${{ steps.npm-cache.outputs.dir }}
@@ -33,9 +35,6 @@ jobs:
3335
${{ runner.os }}-node-
3436
3537
- run: npm install
36-
3738
- run: cd ./packages/pyright-scip/ && npm install && npm run build
38-
3939
- run: python --version
40-
4140
- run: cd ./packages/pyright-scip/ && npm run check-snapshots

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
python 3.10.11
2+
nodejs 18.16.0

README.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,87 @@ $ npm install -g @sourcegraph/scip-python
1313

1414
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.
1515

16+
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.
17+
18+
1619
## Usage
1720

1821
```
1922
$ npm install @sourcegraph/scip-python
2023
2124
$ # NOTE: make sure to activate your virtual environment before running
22-
$ scip-python index . --project-name $MY_PROJECT
25+
$ scip-python index . --project-name=$MY_PROJECT
2326
2427
$ # Make sure to point towards the sourcegraph instance you're interested in uploading to.
2528
$ # more information at https://github.com/sourcegraph/src-cli
2629
$ src code-intel upload
2730
```
2831

32+
### target-only
33+
34+
To run scip-python over only a particular directory, you can use the `--target-only` flag. Example:
35+
36+
```
37+
$ scip-python index . --project-name=$MY_PROJECT --target-only=src/subdir
38+
```
39+
40+
### project-namespace
41+
42+
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.
43+
44+
```
45+
$ scip-python index . --project-name=$MY_PROJECT --project-namespace=implicit.namespace
46+
```
47+
48+
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`.
49+
50+
## Environment
51+
52+
The environment file format is a JSON list of `PythonPackage`s. The `PythonPackage` has the following form:
53+
54+
```json
55+
{
56+
"name": "PyYAML",
57+
"version": "6.0",
58+
"files": [
59+
"PyYAML-6.0.dist-info/INSTALLER",
60+
...
61+
"yaml/__init__.py",
62+
"yaml/composer.py",
63+
"yaml/tokens.py",
64+
...
65+
]
66+
},
67+
```
68+
69+
Where:
70+
- `name`:
71+
- The name of the package. Often times this is the same as the module, but is not always the case.
72+
- For example, `PyYAML` is the name of the package, but the module is `yaml` (i.e. `import yaml`).
73+
- `version`:
74+
- The vesion of the package. This is used to generate stable references to external packages.
75+
- `files`:
76+
- A list of all the files that are a member of this package.
77+
- Some packages declare multiple modules, so these should all be included.
78+
79+
The environment file should be a list of these packages:
80+
81+
```json
82+
[
83+
{ "name": "PyYAML", "version": "6.0", "files": [...] },
84+
{ "name": "pytorch", "version": "3.0", "files": [..] },
85+
...
86+
]
87+
```
88+
89+
To use the environment file, you should call scip-python like so:
90+
91+
```
92+
$ scip-python index --project-name=$MY_PROJECT --environment=path/to/env.json
93+
```
94+
95+
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.
96+
2997
## Sourcegraph Example Configuration
3098

3199
Using the usage example above may be quite simple to add a CI pipeline (perhaps using the `sourcegraph/scip-python:autoindex`) image

packages/pyright-scip/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Release v0.4
2+
3+
- remove: `--include` and `--exclude`. Instead use `pyproject.toml` and pyright configuration.
4+
- add: `--target-only` to only emit and parse information related to some subdirectory of your project. Should still be run from root of project.
5+
- 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.
6+
- Now respects pyright config by default (and discovers applicable pyright configuration).
7+
- Updated pyright internal library
8+
- Attempt to capture possible failures in pyright library so some indexing can still be completed.

packages/pyright-scip/package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/pyright-scip/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"clean": "shx rm -rf ./dist ./out README.md LICENSE.txt",
99
"prepack": "npm run clean && shx cp ../../README.md . && shx cp ../../LICENSE.txt . && npm run build",
1010
"check-snapshots": "npm run update-snapshots -- --check",
11-
"update-snapshots": "node ./index.js snapshot-dir snapshots --environment snapshots/testEnv.json --no-progress-bar",
11+
"update-snapshots": "node ./index.js snapshot-dir snapshots --environment snapshots/testEnv.json --quiet",
1212
"test": "jest --forceExit --detectOpenHandles",
1313
"webpack": "webpack --mode development --progress",
1414
"watch": "webpack --mode development --progress --watch"
@@ -42,6 +42,7 @@
4242
"webpack-cli": "^4.9.1"
4343
},
4444
"dependencies": {
45+
"@iarna/toml": "2.2.5",
4546
"commander": "^9.2.0",
4647
"diff": "^5.0.0",
4748
"glob": "^7.2.0",

packages/pyright-scip/snapshots/output/aliased_import/actual.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# > ```
1212

1313
print(A.SOME_CONSTANT)
14-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
14+
#^^^^ reference python-stdlib 3.11 builtins/print().
1515
#external documentation ```python
1616
# > (function) def print(
1717
# > *values: object,

packages/pyright-scip/snapshots/output/builtin_imports/builtin_imports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
# > ```
3939

4040
print(re, Callable, Optional)
41-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
41+
#^^^^ reference python-stdlib 3.11 builtins/print().
4242
#external documentation ```python
4343
# > (function) def print(
4444
# > *values: object,

packages/pyright-scip/snapshots/output/class_nohint/class_nohint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def something(self):
5353
# > ```
5454
# ^^^^ definition snapshot-util 0.1 class_nohint/Example#something().(self)
5555
print(self.x)
56-
# ^^^^^ reference python-stdlib 3.11 builtins/__init__:print().
56+
# ^^^^^ reference python-stdlib 3.11 builtins/print().
5757
# external documentation ```python
5858
# > (function) def print(
5959
# > *values: object,
@@ -66,7 +66,7 @@ def something(self):
6666
# ^^^^ reference snapshot-util 0.1 class_nohint/Example#something().(self)
6767
# ^ reference snapshot-util 0.1 class_nohint/Example#x.
6868
print(self.y)
69-
# ^^^^^ reference python-stdlib 3.11 builtins/__init__:print().
69+
# ^^^^^ reference python-stdlib 3.11 builtins/print().
7070
# ^^^^ reference snapshot-util 0.1 class_nohint/Example#something().(self)
7171
# ^ reference snapshot-util 0.1 class_nohint/Example#y.
7272

packages/pyright-scip/snapshots/output/comprehensions/comp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def something(x):
7575
# ^^^ definition snapshot-util 0.1 comp/var.
7676
# ^^^^ reference snapshot-util 0.1 comp/asdf.
7777
print(var)
78-
# ^^^^^ reference python-stdlib 3.11 builtins/__init__:print().
78+
# ^^^^^ reference python-stdlib 3.11 builtins/print().
7979
# external documentation ```python
8080
# > (function) def print(
8181
# > *values: object,

packages/pyright-scip/snapshots/output/dunder_vars/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# > __name__: str
99
# > ```
1010
print("main")
11-
# ^^^^^ reference python-stdlib 3.11 builtins/__init__:print().
11+
# ^^^^^ reference python-stdlib 3.11 builtins/print().
1212
# external documentation ```python
1313
# > (function) def print(
1414
# > *values: object,

packages/pyright-scip/snapshots/output/f_string/fstring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# > ```
99

1010
print(f"var: hello {var}")
11-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
11+
#^^^^ reference python-stdlib 3.11 builtins/print().
1212
#external documentation ```python
1313
# > (function) def print(
1414
# > *values: object,

packages/pyright-scip/snapshots/output/file_from_module_import/abc/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# ^^^^^^^^^^^ reference snapshot-util 0.1 `xyz.nested_file`/__init__:
77

88
print(nested_file.X)
9-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
9+
#^^^^ reference python-stdlib 3.11 builtins/print().
1010
#external documentation ```python
1111
# > (function) def print(
1212
# > *values: object,

packages/pyright-scip/snapshots/output/file_from_module_import/file_from_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# ^^^^^^^^^^^ reference snapshot-util 0.1 `xyz.nested_file`/__init__:
77

88
print(nested_file.X)
9-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
9+
#^^^^ reference python-stdlib 3.11 builtins/print().
1010
#external documentation ```python
1111
# > (function) def print(
1212
# > *values: object,

packages/pyright-scip/snapshots/output/nested_items/src/importer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# ^^^^^^^^^^^^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar.baz.mod`/AnotherNestedMuchWow#
1111

1212
print(SuchNestedMuchWow().class_item)
13-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
13+
#^^^^ reference python-stdlib 3.11 builtins/print().
1414
#external documentation ```python
1515
# > (function) def print(
1616
# > *values: object,
@@ -23,11 +23,11 @@
2323
# ^^^^^^^^^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar.baz.mod`/SuchNestedMuchWow#
2424
# ^^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar.baz.mod`/SuchNestedMuchWow#class_item.
2525
print(AnotherNestedMuchWow().other_item)
26-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
26+
#^^^^ reference python-stdlib 3.11 builtins/print().
2727
# ^^^^^^^^^^^^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar.baz.mod`/AnotherNestedMuchWow#
2828
# ^^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar.baz.mod`/AnotherNestedMuchWow#other_item.
2929
print(InitClass().init_item)
30-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
30+
#^^^^ reference python-stdlib 3.11 builtins/print().
3131
# ^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar`/InitClass#
3232
# ^^^^^^^^^ reference snapshot-util 0.1 `src.foo.bar`/InitClass#init_item.
3333

packages/pyright-scip/snapshots/output/nested_items/src/long_importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# ^^^^^^^^^^^^^^^ reference snapshot-util 0.1 `foo.bar.baz.mod`/__init__:
66

77
print(foo.bar.baz.mod.SuchNestedMuchWow)
8-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
8+
#^^^^ reference python-stdlib 3.11 builtins/print().
99
#external documentation ```python
1010
# > (function) def print(
1111
# > *values: object,

packages/pyright-scip/snapshots/output/request_goofiness/goofy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# ^^^^^^^^ reference requests 2.0.0 requests/__init__:
66

77
print(requests.get("https://sourcegraph.com"))
8-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
8+
#^^^^ reference python-stdlib 3.11 builtins/print().
99
#external documentation ```python
1010
# > (function) def print(
1111
# > *values: object,

packages/pyright-scip/snapshots/output/unique/builtin_import_refs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# > ```
3333

3434
print(Any)
35-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
35+
#^^^^ reference python-stdlib 3.11 builtins/print().
3636
#external documentation ```python
3737
# > (function) def print(
3838
# > *values: object,

packages/pyright-scip/snapshots/output/unique/property_access.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def nested():
8686
# ^ definition local 0
8787
# ^^ reference snapshot-util 0.1 property_access/usage().(xs)
8888
print(x.prop_ref)
89-
# ^^^^^ reference python-stdlib 3.11 builtins/__init__:print().
89+
# ^^^^^ reference python-stdlib 3.11 builtins/print().
9090
# external documentation ```python
9191
# > (function) def print(
9292
# > *values: object,

packages/pyright-scip/snapshots/output/unresolved_import/unresolved.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# documentation (module): this_is_not_real [unable to re...
77

88
print(this_is_not_real.x)
9-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
9+
#^^^^ reference python-stdlib 3.11 builtins/print().
1010
#external documentation ```python
1111
# > (function) def print(
1212
# > *values: object,
@@ -18,7 +18,7 @@
1818
# > ```
1919
# ^^^^^^^^^^^^^^^^ reference local 0
2020
print(this_is_not_real.x)
21-
#^^^^ reference python-stdlib 3.11 builtins/__init__:print().
21+
#^^^^ reference python-stdlib 3.11 builtins/print().
2222
# ^^^^^^^^^^^^^^^^ reference local 0
2323

2424

packages/pyright-scip/src/MainCommand.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ checkIndexParser([], {
2525
});
2626

2727
checkIndexParser(['--cwd', 'qux'], { cwd: 'qux' });
28-
checkIndexParser(['--no-progress-bar'], { quiet: false });
28+
checkIndexParser(['--quiet'], { quiet: true });
2929
checkIndexParser(['--show-progress-rate-limit', '120'], { showProgressRateLimit: 120 });
3030
checkIndexParser(['--show-progress-rate-limit', '0.5'], { showProgressRateLimit: 0.5 });
31+
checkIndexParser(['--target-only', 'foo'], { targetOnly: 'foo' });
32+
checkIndexParser(['--project-namespace', 'LSP'], { projectNamespace: 'LSP' });

0 commit comments

Comments
 (0)