Skip to content

Commit 358e535

Browse files
authored
Dev/update_readme (#222)
* document short command * document editor integration for VSCode * used GH Copilot to review and revise
1 parent 49c7dce commit 358e535

File tree

1 file changed

+55
-5
lines changed

1 file changed

+55
-5
lines changed

README.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ As a tool, `ni-python-styleguide` is installed like any other script:
2525
pip install ni-python-styleguide
2626
```
2727

28+
The script name `nps` is a short-name for `ni-python-styleguide`, and may be used in place of `ni-python-styleguide` in any CLI command.
29+
2830
### Linting
2931

3032
To lint, just run the `lint` subcommand (from within the project root, or lower):
@@ -34,7 +36,7 @@ ni-python-styleguide lint
3436
# or
3537
ni-python-styleguide lint ./dir/
3638
# or
37-
ni-python-styleguide lint module.py
39+
nps lint module.py
3840
```
3941

4042
The rules enforced are all rules documented in the written convention, which are marked as enforced.
@@ -46,10 +48,9 @@ However there are some situations you might need to configure the tool.
4648

4749
### Fix
4850

49-
`ni-python-styleguide` has a subcommand `fix` which will run [black](https://pypi.org/project/black/) and [isort](https://pycqa.github.io/isort/).
51+
`ni-python-styleguide` has a subcommand `fix` which will run [black](https://pypi.org/project/black/) and [isort](https://pycqa.github.io/isort/) to apply basic formatting fixes.
5052

51-
Additionally, you can run `fix` with the `--aggressive` option and it will add acknowledgements (# noqa) for the remaining linting errors
52-
it cannot fix, in addition to running black and isort.
53+
When using the `--aggressive` option with `fix`, it will first run `black` and `isort` to fix what it can then add acknowledgements (`# noqa`) for any remaining linting errors that cannot be automatically fixed.
5354

5455
#### When using `setup.py`
5556

@@ -63,7 +64,7 @@ application-import-names = "<app_name>"
6364

6465
### Formatting
6566

66-
`ni-python-styleguide` has a subcommand `format` which will run [black](https://pypi.org/project/black/) and [isort](https://pycqa.github.io/isort/).
67+
`ni-python-styleguide` has a subcommand `format` which will run [black](https://pypi.org/project/black/) and [isort](https://pycqa.github.io/isort/) with the correct settings to match the linting expectations.
6768

6869
If you wish to be able to invoke black directly, you'll want to set the following to get `black` formatting as the styleguide expects.
6970

@@ -105,3 +106,52 @@ nmap <F8> <Plug>(ale_fix) " Fix on F8
105106
```
106107

107108
Change all of these to your taste.
109+
110+
#### VSCode
111+
112+
113+
One can configure VSCode either in the [User 'settings.json' file](https://code.visualstudio.com/docs/configure/settings#_settings-json-file), or in a local [`.vscode/settings.json`](https://code.visualstudio.com/docs/configure/settings#_workspace-settingsjson-location).
114+
115+
116+
1. Install the [Python extension by Microsoft](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
117+
118+
1. Because ni-python-styleguide is a wrapper around `flake8`, you can add the following configuration
119+
to make it uses ni-python-styleguide's rules.
120+
121+
If using Poetry:
122+
```json
123+
"flake8.path": [
124+
"poetry",
125+
"run",
126+
"ni-python-styleguide",
127+
"lint"
128+
],
129+
```
130+
If ni-python-styleguide is directly installed
131+
```json
132+
"flake8.path": [
133+
"ni-python-styleguide",
134+
"lint"
135+
],
136+
```
137+
138+
(alternatively, tell `flake8` to use the ni-python-styleguide config)
139+
```json
140+
"flake8.args": [
141+
"--config=.venv\\lib\\site-packages\\ni_python_styleguide\\config.ini"
142+
],
143+
```
144+
145+
1. Telling the formatter to use ni-python-styleguide's settings
146+
147+
(telling VS Code to use `black` and telling `black` to use `ni-python-styleguide`'s settings file)
148+
```json
149+
"[python]": {
150+
"editor.formatOnType": true,
151+
"editor.defaultFormatter": "ms-python.black-formatter"
152+
},
153+
"black-formatter.args": [
154+
"--config=.venv\\lib\\site-packages\\ni_python_styleguide\\config.toml"
155+
],
156+
```
157+

0 commit comments

Comments
 (0)