From 9e578058af0f75d265ff0a467188f66dc05d89ed Mon Sep 17 00:00:00 2001 From: staticf0x Date: Sat, 21 Oct 2023 12:41:05 +0200 Subject: [PATCH 1/5] Add contributing guide to setup dev environment --- CONTRIBUTING.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..cecaa5ae --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,67 @@ +# Setup the environment + +1. Clone the repo: `git clone git@github.com:python-lsp/python-lsp-server.git` +2. Create the virtual environment: `python3 -m virtualenv .venv` +3. Activate: `source .venv/bin/activate` + +Create a helper script to run the server without the need to `pip3 install` it +on every change and name it `run` or similar: + +```py +#!/home/user/projects/python-lsp-server/.venv/bin/python +import sys + +from pylsp.__main__ import main + +sys.exit(main()) +``` + +## Configure your editor + +In Sublime Text 4, open LSP-pylsp settings and change the path to the `pylsp` command: + +```json +{ + "command": ["/home/user/projects/python-lsp-server/run", "-vvv", "--log-file", "pylsp.log"] +} +``` + +Option `-v` increases verbosity and `--log-file` will write all log messages +into a file, which can be used for debugging. + +Running command `LSP: Troubleshoot server` you should now see the configured command, +if not, then the configuration doesn't work as expected. + +To enabled plugins like `ruff`, you also need to point your editor to the correct +`PYTHONPATH`: + +```json +{ + "command": ["/home/user/projects/python-lsp-server/run", "-vvv", "--log-file", "pylsp.log"], + "env": { + "PYTHONPATH": "/home/user/projects/python-lsp-server/.venv/lib/python3.11/site-packages", + }, +} +``` + +## Trying out if it works + +Go to file `pylsp/python_lsp.py`, function `start_io_lang_server`, +and on the first line of the function, add some logging: + +```py +log.info("It works!") +``` + +Save the file, restart the LSP server and you should see the log line: + +``` +2023-10-12 16:46:38,320 CEST - INFO - pylsp._utils - It works! +``` + +Now the project is setup in a way you can quickly iterate change you want to add. + +# Running tests + +1. Install dependencies: `pip3 install .[test]` +2. Run `pytest`: `pytest -v` From a605db2efae3f22d6f0992167b470036986c234d Mon Sep 17 00:00:00 2001 From: Riley <44530786+staticf0x@users.noreply.github.com> Date: Fri, 27 Oct 2023 17:20:17 +0200 Subject: [PATCH 2/5] Update CONTRIBUTING.md Co-authored-by: Pavel Kulyov --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cecaa5ae..c2094267 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ # Setup the environment 1. Clone the repo: `git clone git@github.com:python-lsp/python-lsp-server.git` -2. Create the virtual environment: `python3 -m virtualenv .venv` +2. Create the virtual environment: `python3 -m venv .venv` 3. Activate: `source .venv/bin/activate` Create a helper script to run the server without the need to `pip3 install` it From b9cbb89cc32ee787425c787c7481d2845222bed5 Mon Sep 17 00:00:00 2001 From: staticf0x Date: Fri, 27 Oct 2023 17:40:19 +0200 Subject: [PATCH 3/5] Edits from review --- CONTRIBUTING.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c2094267..6abb952f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,18 +3,8 @@ 1. Clone the repo: `git clone git@github.com:python-lsp/python-lsp-server.git` 2. Create the virtual environment: `python3 -m venv .venv` 3. Activate: `source .venv/bin/activate` - -Create a helper script to run the server without the need to `pip3 install` it -on every change and name it `run` or similar: - -```py -#!/home/user/projects/python-lsp-server/.venv/bin/python -import sys - -from pylsp.__main__ import main - -sys.exit(main()) -``` +4. Install an editable installation: `pip3 install -e .` + - This will ensure you'll see your edits immediately without reinstalling the project ## Configure your editor @@ -63,5 +53,15 @@ Now the project is setup in a way you can quickly iterate change you want to add # Running tests -1. Install dependencies: `pip3 install .[test]` -2. Run `pytest`: `pytest -v` +1. Install runtime dependencies: `pip3 install .[all]` +2. Install test dependencies: `pip3 install .[test]` +3. Run `pytest`: `pytest -v` + +## Useful pytest options + +- To run a specific test file, use `pytest test/test_utils.py` +- To run a specific test function within a test file, + use `pytest test/test_utils.py::test_debounce` +- To run tests matching a certain expression, use `pytest -k format` +- To increase verbosity of pytest, use `pytest -v` or `pytest -vv` +- To enter a debugger on failed tests, use `pytest --pdb` From 295d2ffece7b5dcf8a289b5112e536fbdc02d04c Mon Sep 17 00:00:00 2001 From: staticf0x Date: Thu, 25 Jan 2024 14:38:49 +0100 Subject: [PATCH 4/5] Remove editor configuration --- CONTRIBUTING.md | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6abb952f..cb34f3b1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,34 +5,7 @@ 3. Activate: `source .venv/bin/activate` 4. Install an editable installation: `pip3 install -e .` - This will ensure you'll see your edits immediately without reinstalling the project - -## Configure your editor - -In Sublime Text 4, open LSP-pylsp settings and change the path to the `pylsp` command: - -```json -{ - "command": ["/home/user/projects/python-lsp-server/run", "-vvv", "--log-file", "pylsp.log"] -} -``` - -Option `-v` increases verbosity and `--log-file` will write all log messages -into a file, which can be used for debugging. - -Running command `LSP: Troubleshoot server` you should now see the configured command, -if not, then the configuration doesn't work as expected. - -To enabled plugins like `ruff`, you also need to point your editor to the correct -`PYTHONPATH`: - -```json -{ - "command": ["/home/user/projects/python-lsp-server/run", "-vvv", "--log-file", "pylsp.log"], - "env": { - "PYTHONPATH": "/home/user/projects/python-lsp-server/.venv/lib/python3.11/site-packages", - }, -} -``` +5. Configure your editor to point the pylsp executable to the one in `.venv` ## Trying out if it works From a19fadc83f22f8cda18fb2e780bc374d12d88dde Mon Sep 17 00:00:00 2001 From: Riley <44530786+staticf0x@users.noreply.github.com> Date: Sun, 24 Mar 2024 20:16:43 +0100 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Carlos Cordoba --- CONTRIBUTING.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cb34f3b1..5a24957b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,9 @@ # Setup the environment 1. Clone the repo: `git clone git@github.com:python-lsp/python-lsp-server.git` -2. Create the virtual environment: `python3 -m venv .venv` +2. Create the virtual environment: `python -m venv .venv` 3. Activate: `source .venv/bin/activate` -4. Install an editable installation: `pip3 install -e .` +4. Install an editable installation: `pip install -e .` - This will ensure you'll see your edits immediately without reinstalling the project 5. Configure your editor to point the pylsp executable to the one in `.venv` @@ -26,8 +26,8 @@ Now the project is setup in a way you can quickly iterate change you want to add # Running tests -1. Install runtime dependencies: `pip3 install .[all]` -2. Install test dependencies: `pip3 install .[test]` +1. Install runtime dependencies: `pip install .[all]` +2. Install test dependencies: `pip install .[test]` 3. Run `pytest`: `pytest -v` ## Useful pytest options