Skip to content

Commit

Permalink
docs: fix code examples for setting-up-ide and `interpreter-compati…
Browse files Browse the repository at this point in the history
…bility` docs (Cherry-pick of #19624) (#19638)

## Setting Up IDE Doc Issue

Currently, in the `docs/markdown/Using Pants/setting-up-an-ide.md` page,
the project instructs users to run

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

However, for some reason, the command `pants roots --roots-sep=' '` is
not working for the `' '` character. This PR makes a small fix to this
issue changing the `' '` character to the default `'\n'` by removing the
`--roots-sep=` argument and changing how the `ROOTS` environment
variable is split.

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

Alternatively, if we want to maintain the `roots-sep` argument, so users
know it exists, we can change it from `' '` to a non whitespace
character, such as `';'` and that also seems to work.

## Interpreter Compatibility Doc Issue

Another small issue is in
`docs/markdown/Python/python/python-interpreter-compatibility.md` in the
example:

```python
python_sources(
    name="lib",
    overrides={
        "py2.py": {"interpreter_constraints": ["==2.7.*"]},
        # You can use a tuple for multiple files:
        ("common.py", "f.py"): {"interpreter_constraints": ["==2.7.*"]},
)
```

This example is missing an `}`. This PR also addresses this small issue.

Co-authored-by: Mikael Souza <mikael.souza.cc@gmail.com>
  • Loading branch information
WorkerPants and mikaelsouza committed Aug 22, 2023
1 parent 0771f07 commit ab29267
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Expand Up @@ -55,6 +55,7 @@ python_sources(
"py2.py": {"interpreter_constraints": ["==2.7.*"]},
# You can use a tuple for multiple files:
("common.py", "f.py"): {"interpreter_constraints": ["==2.7.*"]},
}
)
```

Expand Down
4 changes: 2 additions & 2 deletions docs/markdown/Using Pants/setting-up-an-ide.md
Expand Up @@ -24,8 +24,8 @@ In VSCode, the Python extension will look for a file named `.env` in the current
For Python, to generate the `.env` file containing all the source roots, you can use something like this:

```shell
$ ROOTS=$(pants roots --roots-sep=' ')
$ python3 -c "print('PYTHONPATH=\"./' + ':./'.join(\"${ROOTS}\".split()) + ':\$PYTHONPATH\"')" > .env
$ ROOTS=$(pants roots)
$ python3 -c "print('PYTHONPATH=\"./' + ':./'.join('''${ROOTS}'''.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 ab29267

Please sign in to comment.