summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@cosine.nl>2021-05-10 15:47:20 +0200
committerJouke Witteveen <j.witteveen@cosine.nl>2021-05-10 16:41:01 +0200
commitefc15cf4f10ad45f88bda1cb6578b9ef7a06cd8d (patch)
treedd6d5049906e7471b6739e6d3244081fbee06b05 /src
parent28aa67314e2c451002d6362c54aed6e08f4f9f19 (diff)
downloadflake8-efc15cf4f10ad45f88bda1cb6578b9ef7a06cd8d.tar.gz
Automatically create output directories
Diffstat (limited to 'src')
-rw-r--r--src/flake8/formatting/base.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/flake8/formatting/base.py b/src/flake8/formatting/base.py
index e362e65..806d9b8 100644
--- a/src/flake8/formatting/base.py
+++ b/src/flake8/formatting/base.py
@@ -1,5 +1,6 @@
"""The base class and interface for all formatting plugins."""
import argparse
+import os
from typing import IO
from typing import List
from typing import Optional
@@ -76,6 +77,8 @@ class BaseFormatter:
This defaults to initializing :attr:`output_fd` if :attr:`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")
def handle(self, error: "Violation") -> None: