Skip to content

Commit 0a9a7b7

Browse files
authored
Check formatting of Python code in AzDO pipelines (#9743)
* Check formatting of Python code in AzDO pipelines * Buy one double quote get one free 💥 * Update contributing guide * Install black as part of CI * Undo small change * Install pip and black when formatting Python code * Install pip in initialization step (for all steps) * Remove pip install condition * New Python files since my formatting pass LOL
1 parent a6da8d3 commit 0a9a7b7

File tree

9 files changed

+27
-9
lines changed

9 files changed

+27
-9
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ npm ci
3838
python3 -m venv .venv
3939
# Activate the virtual environment as appropriate for your shell, For example ...
4040
source .venv/bin/activate
41+
# The Python code in the extension is formatted using Black.
42+
python3 -m pip install black
4143
# Install Python dependencies using `python3`.
4244
# If you want to use a different interpreter then specify it in the
4345
# CI_PYTHON_PATH environment variable.

build/ci/templates/jobs/build_compile.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@ jobs:
3636
workingDirectory: $(Build.SourcesDirectory)
3737

3838
- bash: npx prettier "src/**/*.ts*" --check
39-
displayName: "Code Format"
39+
displayName: "Code Format (TypeScript)"
4040
workingDirectory: $(Build.SourcesDirectory)
4141

4242
- bash: npx prettier "build/**/*.js" --check
43-
displayName: "Code Format"
43+
displayName: "Code Format (JavaScript)"
4444
workingDirectory: $(Build.SourcesDirectory)
45+
46+
- bash: |
47+
python -m pip install -U black
48+
python -m black . --check
49+
displayName: "Code Format (Python)"
50+
workingDirectory: $(Build.SourcesDirectory)/pythonFiles

build/ci/templates/steps/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ steps:
1919
compile: 'false'
2020

2121
- bash: |
22-
python -m pip install -U pip
2322
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt
2423
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python/old_ptvsd --no-cache-dir --implementation py --no-deps --upgrade 'ptvsd==4.3.2'
2524
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python/new_ptvsd/no_wheels --no-cache-dir --implementation py --no-deps --upgrade --pre ptvsd

build/ci/templates/steps/initialization.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ steps:
120120
displayName: 'Start Display Server (xvfb) to launch VS Code)'
121121
condition: and(succeeded(), eq(variables['Agent.Os'], 'Linux'))
122122
123+
- bash: python -m pip install -U pip
124+
displayName: 'Install pip'
125+
123126
# # Show all versions installed/available on PATH if in verbose mode.
124127
# # Example command line (windows pwsh):
125128
# # > Write-Host Node ver: $(& node -v) NPM Ver: $(& npm -v) Python ver: $(& python --version)"

build/ci/templates/test_phases.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ steps:
9393
# > python -m pip install --upgrade -r build/test-requirements.txt
9494
# > python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt
9595
- bash: |
96-
python -m pip install -U pip
9796
python -m pip install --upgrade -r build/test-requirements.txt
9897
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt
9998
python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python/old_ptvsd --no-cache-dir --implementation py --no-deps --upgrade 'ptvsd==4.3.2'
@@ -119,7 +118,6 @@ steps:
119118
# > python -m pip install --upgrade -r build/functional-test-requirements.txt
120119
# > python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt
121120
- bash: |
122-
python -m pip install -U pip
123121
python -m pip install numpy
124122
python -m pip install --upgrade -r ./build/functional-test-requirements.txt
125123
displayName: 'pip install functional requirements'
@@ -142,7 +140,6 @@ steps:
142140
# > python -m pip install --upgrade -r build/ipython-test-requirements.txt
143141
# > python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade -r requirements.txt
144142
- bash: |
145-
python -m pip install -U pip
146143
python -m pip install numpy
147144
python -m pip install --upgrade -r ./build/ipython-test-requirements.txt
148145
displayName: 'pip install ipython requirements'

news/3 Code Health/2012.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Use [prettier](https://prettier.io/) as the formatter for `TypeScript` code within the extension.
1+
Use [prettier](https://prettier.io/) as the `TypeScript` formatter and [Black](https://github.com/psf/black) as the `Python` formatter within the extension.

pythonFiles/printEnvVariablesToFile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
# Last argument is the target file into which we'll write the env variables as json.
1010
json_file = sys.argv[-1]
1111

12-
with open(json_file, 'w') as outfile:
12+
with open(json_file, "w") as outfile:
1313
json.dump(dict(os.environ), outfile)

pythonFiles/pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tool.black]
2+
exclude = '''
3+
4+
(
5+
/(
6+
.data
7+
| .vscode
8+
| lib
9+
)/
10+
)
11+
'''

pythonFiles/shell_exec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
fp.flush()
3838
try:
3939
# ALso log the error for use from the other side.
40-
with open(lock_file + '.error', 'w') as fpError:
40+
with open(lock_file + ".error", "w") as fpError:
4141
fpError.write(traceback.format_exc())
4242
except Exception:
4343
pass

0 commit comments

Comments
 (0)