Skip to content

Commit ae2a693

Browse files
committed
Black is working now
1 parent e2d572f commit ae2a693

File tree

8 files changed

+98
-9
lines changed

8 files changed

+98
-9
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
autopep8
22
yapf
3+
black
34
pylint
45
pep8
56
prospector

src/client/common/configSettings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,12 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
213213
this.formatting = this.formatting ? this.formatting : {
214214
autopep8Args: [], autopep8Path: 'autopep8',
215215
provider: 'autopep8',
216-
yapfArgs: [], yapfPath: 'yapf'
216+
yapfArgs: [], yapfPath: 'yapf',
217+
blackArgs: [], blackPath: 'black'
217218
};
218219
this.formatting.autopep8Path = getAbsolutePath(systemVariables.resolveAny(this.formatting.autopep8Path), workspaceRoot);
219220
this.formatting.yapfPath = getAbsolutePath(systemVariables.resolveAny(this.formatting.yapfPath), workspaceRoot);
221+
this.formatting.blackPath = getAbsolutePath(systemVariables.resolveAny(this.formatting.blackPath), workspaceRoot);
220222

221223
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion
222224
const autoCompleteSettings = systemVariables.resolveAny(pythonSettings.get<IAutoCompeteSettings>('autoComplete'))!;

src/client/common/installer/productInstaller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class FormatterInstaller extends BaseInstaller {
128128
const productName = ProductNames.get(product)!;
129129

130130
const installThis = `Install ${productName}`;
131+
// TODO(Josh): Wat
131132
const alternateFormatter = product === Product.autopep8 ? 'yapf' : 'autopep8';
132133
const useOtherFormatter = `Use '${alternateFormatter}' formatter`;
133134
const item = await this.appShell.showErrorMessage(`Formatter ${productName} is not installed.`, installThis, useOtherFormatter);
@@ -231,6 +232,7 @@ export class ProductInstaller implements IInstaller {
231232
this.ProductTypes.set(Product.unittest, ProductType.TestFramework);
232233
this.ProductTypes.set(Product.autopep8, ProductType.Formatter);
233234
this.ProductTypes.set(Product.yapf, ProductType.Formatter);
235+
this.ProductTypes.set(Product.black, ProductType.Formatter);
234236
this.ProductTypes.set(Product.rope, ProductType.RefactoringLibrary);
235237
}
236238

src/client/common/installer/productNames.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ ProductNames.set(Product.pydocstyle, 'pydocstyle');
1616
ProductNames.set(Product.pylint, 'pylint');
1717
ProductNames.set(Product.pytest, 'pytest');
1818
ProductNames.set(Product.yapf, 'yapf');
19+
ProductNames.set(Product.black, 'black');
1920
ProductNames.set(Product.rope, 'rope');

src/client/formatters/baseFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export abstract class BaseFormatter {
5959
const executionInfo = this.helper.getExecutionInfo(this.product, args, document.uri);
6060
executionInfo.args.push(tempFile);
6161
const pythonToolsExecutionService = this.serviceContainer.get<IPythonToolExecutionService>(IPythonToolExecutionService);
62-
const promise = pythonToolsExecutionService.exec(executionInfo, { cwd, throwOnStdErr: true, token }, document.uri)
62+
const promise = pythonToolsExecutionService.exec(executionInfo, { cwd, throwOnStdErr: false, token }, document.uri)
6363
.then(output => output.stdout)
6464
.then(data => {
6565
if (this.checkCancellation(document.fileName, tempFile, token)) {

src/client/formatters/blackFormatter.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ export class BlackFormatter extends BaseFormatter {
2222
const hasCustomArgs = Array.isArray(settings.formatting.blackArgs) && settings.formatting.blackArgs.length > 0;
2323
const formatSelection = false; // range ? !range.isEmpty : false;
2424

25-
const args = [];
25+
const args = ['--diff'];
2626
// if (formatSelection) {
27+
// black does not support partial formatting, throw an error?
2728
// // tslint:disable-next-line:no-non-null-assertion
2829
// args.push(...['--lines', `${range!.start.line + 1}-${range!.end.line + 1}`]);
2930
// }
3031
// Yapf starts looking for config file starting from the file path.
31-
const fallbarFolder = this.getWorkspaceUri(document).fsPath;
32-
const cwd = this.getDocumentPath(document, fallbarFolder);
32+
const fallbackFolder = this.getWorkspaceUri(document).fsPath;
33+
const cwd = this.getDocumentPath(document, fallbackFolder);
3334
const promise = super.provideDocumentFormattingEdits(document, options, token, args, cwd);
34-
sendTelemetryWhenDone(FORMAT, promise, stopWatch, { tool: 'black', hasCustomArgs, formatSelection });
35+
//sendTelemetryWhenDone(FORMAT, promise, stopWatch, { tool: 'black', hasCustomArgs, formatSelection });
3536
return promise;
3637
}
3738
}

src/client/formatters/helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class FormatterHelper implements IFormatterHelper {
1616
switch (formatter) {
1717
case Product.autopep8: return 'autopep8';
1818
case Product.yapf: return 'yapf';
19+
case Product.black: return 'black';
1920
default: {
2021
throw new Error(`Unrecognized Formatter '${formatter}'`);
2122
}

yarn.lock

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ binary-extensions@^1.0.0:
470470
version "1.11.0"
471471
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.11.0.tgz#46aa1751fb6a2f93ee5e689bb1087d4b14c6c205"
472472

473+
"binary@>= 0.3.0 < 1":
474+
version "0.3.0"
475+
resolved "https://registry.yarnpkg.com/binary/-/binary-0.3.0.tgz#9f60553bc5ce8c3386f3b553cff47462adecaa79"
476+
dependencies:
477+
buffers "~0.1.1"
478+
chainsaw "~0.1.0"
479+
473480
block-stream@*:
474481
version "0.0.9"
475482
resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a"
@@ -550,6 +557,10 @@ buffer-equal@^1.0.0:
550557
version "1.0.0"
551558
resolved "https://registry.yarnpkg.com/buffer-equal/-/buffer-equal-1.0.0.tgz#59616b498304d556abd466966b22eeda3eca5fbe"
552559

560+
buffers@~0.1.1:
561+
version "0.1.1"
562+
resolved "https://registry.yarnpkg.com/buffers/-/buffers-0.1.1.tgz#b24579c3bed4d6d396aeee6d9a8ae7f5482ab7bb"
563+
553564
builtin-modules@^1.0.0, builtin-modules@^1.1.1:
554565
version "1.1.1"
555566
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"
@@ -619,6 +630,12 @@ chai@^4.1.2:
619630
pathval "^1.0.0"
620631
type-detect "^4.0.0"
621632

633+
chainsaw@~0.1.0:
634+
version "0.1.0"
635+
resolved "https://registry.yarnpkg.com/chainsaw/-/chainsaw-0.1.0.tgz#5eab50b28afe58074d0d58291388828b5e5fbc98"
636+
dependencies:
637+
traverse ">=0.3.0 <0.4"
638+
622639
chalk@^0.5.0:
623640
version "0.5.1"
624641
resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.5.1.tgz#663b3a648b68b55d04690d49167aa837858f2174"
@@ -1472,6 +1489,15 @@ fstream-ignore@^1.0.5:
14721489
inherits "2"
14731490
minimatch "^3.0.0"
14741491

1492+
"fstream@>= 0.1.30 < 1":
1493+
version "0.1.31"
1494+
resolved "https://registry.yarnpkg.com/fstream/-/fstream-0.1.31.tgz#7337f058fbbbbefa8c9f561a28cab0849202c988"
1495+
dependencies:
1496+
graceful-fs "~3.0.2"
1497+
inherits "~2.0.0"
1498+
mkdirp "0.5"
1499+
rimraf "2"
1500+
14751501
fstream@^1.0.0, fstream@^1.0.10, fstream@^1.0.2:
14761502
version "1.0.11"
14771503
resolved "https://registry.yarnpkg.com/fstream/-/fstream-1.0.11.tgz#5c1fb1f117477114f0632a0eb4b71b3cb0fd3171"
@@ -1695,7 +1721,7 @@ [email protected], graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, gr
16951721
version "4.1.11"
16961722
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
16971723

1698-
graceful-fs@^3.0.0:
1724+
graceful-fs@^3.0.0, graceful-fs@~3.0.2:
16991725
version "3.0.11"
17001726
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-3.0.11.tgz#7613c778a1afea62f25c630a086d7f3acbbdd818"
17011727
dependencies:
@@ -2915,6 +2941,13 @@ map-visit@^1.0.0:
29152941
dependencies:
29162942
object-visit "^1.0.0"
29172943

2944+
"match-stream@>= 0.0.2 < 1":
2945+
version "0.0.2"
2946+
resolved "https://registry.yarnpkg.com/match-stream/-/match-stream-0.0.2.tgz#99eb050093b34dffade421b9ac0b410a9cfa17cf"
2947+
dependencies:
2948+
buffers "~0.1.1"
2949+
readable-stream "~1.0.0"
2950+
29182951
29192952
version "1.3.4"
29202953
resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.4.tgz#e9bdbde94a20a5ac18b04340fc5764d5b09d901d"
@@ -3052,7 +3085,7 @@ mixin-deep@^1.2.0:
30523085
for-in "^1.0.2"
30533086
is-extendable "^1.0.1"
30543087

3055-
[email protected], [email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
3088+
[email protected], [email protected].1, [email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
30563089
version "0.5.1"
30573090
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
30583091
dependencies:
@@ -3367,6 +3400,10 @@ osenv@^0.1.4:
33673400
os-homedir "^1.0.0"
33683401
os-tmpdir "^1.0.0"
33693402

3403+
"over@>= 0.0.5 < 1":
3404+
version "0.0.5"
3405+
resolved "https://registry.yarnpkg.com/over/-/over-0.0.5.tgz#f29852e70fd7e25f360e013a8ec44c82aedb5708"
3406+
33703407
p-map@^1.1.1:
33713408
version "1.2.0"
33723409
resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.2.0.tgz#e4e94f311eabbc8633a1e79908165fca26241b6b"
@@ -3547,6 +3584,15 @@ pseudomap@^1.0.1, pseudomap@^1.0.2:
35473584
version "1.0.2"
35483585
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
35493586

3587+
"pullstream@>= 0.4.1 < 1":
3588+
version "0.4.1"
3589+
resolved "https://registry.yarnpkg.com/pullstream/-/pullstream-0.4.1.tgz#d6fb3bf5aed697e831150eb1002c25a3f8ae1314"
3590+
dependencies:
3591+
over ">= 0.0.5 < 1"
3592+
readable-stream "~1.0.31"
3593+
setimmediate ">= 1.0.2 < 2"
3594+
slice-stream ">= 1.0.0 < 2"
3595+
35503596
pump@^2.0.0:
35513597
version "2.0.1"
35523598
resolved "https://registry.yarnpkg.com/pump/-/pump-2.0.1.tgz#12399add6e4cf7526d973cbc8b5ce2e2908b3909"
@@ -3625,7 +3671,7 @@ read-pkg@^1.0.0:
36253671
normalize-package-data "^2.3.2"
36263672
path-type "^1.0.0"
36273673

3628-
"readable-stream@>=1.0.33-1 <1.1.0-0", readable-stream@~1.0.17:
3674+
"readable-stream@>=1.0.33-1 <1.1.0-0", readable-stream@~1.0.0, readable-stream@~1.0.17, readable-stream@~1.0.31:
36293675
version "1.0.34"
36303676
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c"
36313677
dependencies:
@@ -3763,6 +3809,12 @@ replace-ext@^1.0.0:
37633809
version "1.0.0"
37643810
resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-1.0.0.tgz#de63128373fcbf7c3ccfa4de5a480c45a67958eb"
37653811

3812+
request-progress@^3.0.0:
3813+
version "3.0.0"
3814+
resolved "https://registry.yarnpkg.com/request-progress/-/request-progress-3.0.0.tgz#4ca754081c7fec63f505e4faa825aa06cd669dbe"
3815+
dependencies:
3816+
throttleit "^1.0.0"
3817+
37663818
37673819
version "2.81.0"
37683820
resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0"
@@ -3986,6 +4038,10 @@ set-value@^2.0.0:
39864038
is-plain-object "^2.0.3"
39874039
split-string "^3.0.1"
39884040

4041+
"setimmediate@>= 1.0.1 < 2", "setimmediate@>= 1.0.2 < 2":
4042+
version "1.0.5"
4043+
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
4044+
39894045
shortid@^2.2.8:
39904046
version "2.2.8"
39914047
resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.8.tgz#033b117d6a2e975804f6f0969dbe7d3d0b355131"
@@ -4014,6 +4070,12 @@ slash@^1.0.0:
40144070
version "1.0.0"
40154071
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
40164072

4073+
"slice-stream@>= 1.0.0 < 2":
4074+
version "1.0.0"
4075+
resolved "https://registry.yarnpkg.com/slice-stream/-/slice-stream-1.0.0.tgz#5b33bd66f013b1a7f86460b03d463dec39ad3ea0"
4076+
dependencies:
4077+
readable-stream "~1.0.31"
4078+
40174079
snapdragon-node@^2.0.1:
40184080
version "2.1.1"
40194081
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"
@@ -4341,6 +4403,10 @@ text-encoding@^0.6.4:
43414403
version "0.6.4"
43424404
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
43434405

4406+
throttleit@^1.0.0:
4407+
version "1.0.0"
4408+
resolved "https://registry.yarnpkg.com/throttleit/-/throttleit-1.0.0.tgz#9e785836daf46743145a5984b6268d828528ac6c"
4409+
43444410
through2-filter@^2.0.0:
43454411
version "2.0.0"
43464412
resolved "https://registry.yarnpkg.com/through2-filter/-/through2-filter-2.0.0.tgz#60bc55a0dacb76085db1f9dae99ab43f83d622ec"
@@ -4450,6 +4516,10 @@ tough-cookie@~2.3.0, tough-cookie@~2.3.3:
44504516
dependencies:
44514517
punycode "^1.4.1"
44524518

4519+
"traverse@>=0.3.0 <0.4":
4520+
version "0.3.9"
4521+
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.3.9.tgz#717b8f220cc0bb7b44e40514c22b2e8bbc70d8b9"
4522+
44534523
tree-kill@^1.1.0:
44544524
version "1.2.0"
44554525
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.0.tgz#5846786237b4239014f05db156b643212d4c6f36"
@@ -4620,6 +4690,17 @@ untildify@^3.0.2:
46204690
version "3.0.2"
46214691
resolved "https://registry.yarnpkg.com/untildify/-/untildify-3.0.2.tgz#7f1f302055b3fea0f3e81dc78eb36766cb65e3f1"
46224692

4693+
unzip@^0.1.11:
4694+
version "0.1.11"
4695+
resolved "https://registry.yarnpkg.com/unzip/-/unzip-0.1.11.tgz#89749c63b058d7d90d619f86b98aa1535d3b97f0"
4696+
dependencies:
4697+
binary ">= 0.3.0 < 1"
4698+
fstream ">= 0.1.30 < 1"
4699+
match-stream ">= 0.0.2 < 1"
4700+
pullstream ">= 0.4.1 < 1"
4701+
readable-stream "~1.0.31"
4702+
setimmediate ">= 1.0.1 < 2"
4703+
46234704
upath@^1.0.0:
46244705
version "1.0.4"
46254706
resolved "https://registry.yarnpkg.com/upath/-/upath-1.0.4.tgz#ee2321ba0a786c50973db043a50b7bcba822361d"

0 commit comments

Comments
 (0)