|
1 | | -# Python (beta) |
| 1 | +# Code intelligence for Python (beta) |
2 | 2 |
|
3 | 3 |  |
4 | 4 |
|
5 | | -This extension adds Python code intelligence to Sourcegraph using a [Python language server](https://github.com/Microsoft/python-language-server) (the [@sourcegraph fork](https://github.com/sourcegraph/python-language-server/tree/wip2)). |
| 5 | +This extension provides Python code intelligence on Sourcegraph. Ensure this extension is enabled and then try it on some examples: |
6 | 6 |
|
7 | | -[**🗃️ Source code**](https://github.com/sourcegraph/lang-python) |
8 | | - |
9 | | -[**➕ View in extension registry**](https://sourcegraph.com/extensions/sourcegraph/python) |
10 | | - |
11 | | -## Features |
| 7 | +- Tensorflow: [tensorflow_ranking/examples/tf_ranking_libsvm.py](https://sourcegraph.com/github.com/tensorflow/ranking@931e4e18d68612d0b29dc3c81994acdd4b6ab743/-/blob/tensorflow_ranking/examples/tf_ranking_libsvm.py#L294:27&tab=references) |
| 8 | +- Flask: [flask/views.py](https://sourcegraph.com/github.com/pallets/flask/-/blob/flask/views.py) |
| 9 | +- Zulip: [corporate/lib/stripe.py](https://sourcegraph.com/github.com/zulip/zulip/-/blob/corporate/lib/stripe.py) |
| 10 | +- Trivial sample: [pkg0/m0.py](http://sourcegraph.com/github.com/sgtest/python-sample-0/-/blob/pkg0/m0.py) |
12 | 11 |
|
13 | | -For Python code viewed on [Sourcegraph](https://sourcegraph.com) and when using the [Sourcegraph browser extension](https://docs.sourcegraph.com/integration/browser_extension): |
| 12 | + |
14 | 13 |
|
15 | | -- Hovers with documentation and inferred type signatures |
16 | | -- Go to definition |
17 | | -- Find references |
| 14 | +## Usage with private Sourcegraph instances |
18 | 15 |
|
19 | | -## Usage on your own Sourcegraph instance |
| 16 | +This extension is configured to talk to a language server over WebSockets. If you are running a |
| 17 | +private Sourcegraph instance, you should run your own language server. The server is available as a |
| 18 | +Docker image `sourcegraph/lang-python` from Docker Hub. |
20 | 19 |
|
21 | | -Run the language server Docker container: |
| 20 | +### Using Docker |
22 | 21 |
|
23 | | -``` |
24 | | -docker run --rm -p 4288:4288 sourcegraph/lang-python:insiders |
25 | | -``` |
| 22 | +1. Run the Python language server Docker container: |
26 | 23 |
|
27 | | -Add these to your Sourcegraph settings: |
| 24 | + ```sh |
| 25 | + docker run --rm -p 4288:4288 sourcegraph/lang-python:insiders |
| 26 | + ``` |
28 | 27 |
|
29 | | -``` |
30 | | - "python.languageServer.url": "ws://localhost:4288", |
31 | | - "python.sourcegraph.url": "http://host.docker.internal:7080", |
32 | | -``` |
| 28 | +1. Enable this extension on your Sourcegraph https://sourcegraph.example.com/extensions/sourcegraph/lang-python |
33 | 29 |
|
34 | | -If you're running on Linux, change `python.sourcegraph.url` to the IP given by: |
35 | 30 |
|
36 | | -```bash |
37 | | -ip addr show docker0 | grep -Po 'inet \K[\d.]+' |
38 | | -``` |
| 31 | +1. Add these to your Sourcegraph settings: |
39 | 32 |
|
40 | | -## Usage on Sourcegraph.com |
| 33 | + ```json |
| 34 | + "python.languageServer.url": "ws://localhost:4288", |
| 35 | + "python.sourcegraph.url": "http://host.docker.internal:7080", |
| 36 | + ``` |
41 | 37 |
|
42 | | -This extension is enabled for all users by default on Sourcegraph.com and when using the [Sourcegraph browser extension](https://docs.sourcegraph.com/integration/browser_extension) on public code. |
| 38 | + If you're running on Linux, change `python.sourcegraph.url` to the IP given by: |
43 | 39 |
|
44 | | -To use it, just visit a Python file and hover over tokens. Examples: |
| 40 | + ```bash |
| 41 | + ip addr show docker0 | grep -Po 'inet \K[\d.]+' |
| 42 | + ``` |
45 | 43 |
|
46 | | -- Tensorflow: [tensorflow_ranking/examples/tf_ranking_libsvm.py](https://sourcegraph.com/github.com/tensorflow/ranking@931e4e18d68612d0b29dc3c81994acdd4b6ab743/-/blob/tensorflow_ranking/examples/tf_ranking_libsvm.py#L294:27&tab=references) |
47 | | -- Flask: [flask/views.py](https://sourcegraph.com/github.com/pallets/flask/-/blob/flask/views.py) |
48 | | -- Zulip: [corporate/lib/stripe.py](https://sourcegraph.com/github.com/zulip/zulip/-/blob/corporate/lib/stripe.py) |
49 | | -- Trivial sample: [pkg0/m0.py](http://sourcegraph.com/github.com/sgtest/python-sample-0/-/blob/pkg0/m0.py) |
| 44 | +### Authentication proxies and firewalls |
50 | 45 |
|
51 | | - |
| 46 | +Some customers deploy Sourcegraph behind an authentication proxy or firewall. If you do this, we |
| 47 | +recommend deploying the language server behind the proxy so that it can issue requests directly to |
| 48 | +Sourcegraph without going through the proxy. (Otherwise, you will need to configure the language |
| 49 | +server to authenticate through your proxy.) Make sure you set `python.sourcegraphUrl` to the URL |
| 50 | +that the language server should use to reach Sourcegraph, which is likely different from the URL |
| 51 | +that end users use. |
52 | 52 |
|
53 | 53 | ## Known issues |
54 | 54 |
|
|
0 commit comments