mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 06:44:18 +00:00
Automatically create output directories
This commit is contained in:
parent
28aa67314e
commit
efc15cf4f1
2 changed files with 5 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
"""The base class and interface for all formatting plugins."""
|
"""The base class and interface for all formatting plugins."""
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
from typing import IO
|
from typing import IO
|
||||||
from typing import List
|
from typing import List
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
@ -76,6 +77,8 @@ class BaseFormatter:
|
||||||
This defaults to initializing :attr:`output_fd` if :attr:`filename`
|
This defaults to initializing :attr:`output_fd` if :attr:`filename`
|
||||||
"""
|
"""
|
||||||
if self.filename:
|
if self.filename:
|
||||||
|
dirname = os.path.dirname(os.path.abspath(self.filename))
|
||||||
|
os.makedirs(dirname, exist_ok=True)
|
||||||
self.output_fd = open(self.filename, "a")
|
self.output_fd = open(self.filename, "a")
|
||||||
|
|
||||||
def handle(self, error: "Violation") -> None:
|
def handle(self, error: "Violation") -> None:
|
||||||
|
|
|
||||||
|
|
@ -343,10 +343,10 @@ def test_output_file(tmpdir, capsys):
|
||||||
tmpdir.join("t.py").write("import os\n")
|
tmpdir.join("t.py").write("import os\n")
|
||||||
|
|
||||||
with tmpdir.as_cwd():
|
with tmpdir.as_cwd():
|
||||||
_call_main(["t.py", "--output-file=f"], retv=1)
|
_call_main(["t.py", "--output-file=a/b/f"], retv=1)
|
||||||
|
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert out == err == ""
|
assert out == err == ""
|
||||||
|
|
||||||
expected = "t.py:1:1: F401 'os' imported but unused\n"
|
expected = "t.py:1:1: F401 'os' imported but unused\n"
|
||||||
assert tmpdir.join("f").read() == expected
|
assert tmpdir.join("a/b/f").read() == expected
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue