Skip to content

Commit

Permalink
Avoid quotes in suggested .env file for IDEs (Cherry-pick of #20144) (#…
Browse files Browse the repository at this point in the history
…20146)

This fixes #20127 by avoiding double quotes in the `.env` file generated
by the code snippet in the IDE set-up docs.

Double quotes aren't supported by the `scie-pants` `.env` loader, and a
line containing them was previously silently ignored (plus all lines
after), but with scie-pants 0.11.0, will be an error. See
pantsbuild/scie-pants#307 and
pantsbuild/scie-pants#319.

The new suggestion has _no_ quotes at all, because there's no other way
to have a line that includes a substitution. To handle source roots with
spaces in their paths, this has to also manually escape them. Supporting
double quotes is effectively a new feature of `scie-pants` launcher (via
scie jump a-scie/jump#166 via `dotenvy`
allan2/dotenvy#11), but for now we can at
least stop suggesting incorrect things.

For instance, with source roots `a b/c` and `def`, this generates:

```
PYTHONPATH=./a\ b/c:./def:$PYTHONPATH
```

Co-authored-by: Huon Wilson <huon@exoflare.io>
  • Loading branch information
WorkerPants and huonw committed Nov 3, 2023
1 parent a6a73c8 commit 5ffae27
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/markdown/Using Pants/setting-up-an-ide.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ For Python, to generate the `.env` file containing all the source roots, you can

```shell
$ ROOTS=$(pants roots)
$ python3 -c "print('PYTHONPATH=\"./' + ':./'.join('''${ROOTS}'''.split('\n')) + ':\$PYTHONPATH\"')" > .env
$ python3 -c "print('PYTHONPATH=./' + ':./'.join('''${ROOTS}'''.replace(' ', '\\ ').split('\n')) + ':\$PYTHONPATH')" > .env
```

See [Use of the PYTHONPATH variable](https://code.visualstudio.com/docs/python/environments#_use-of-the-pythonpath-variable) to learn more about using the `PYTHONPATH` variable in VSCode.
Expand Down

0 comments on commit 5ffae27

Please sign in to comment.