diff --git a/newsfragments/85.feature.rst b/newsfragments/85.feature.rst new file mode 100644 index 0000000..5378344 --- /dev/null +++ b/newsfragments/85.feature.rst @@ -0,0 +1 @@ +Add public method ``map_in_to_out_file_path`` to ``Rule`` to allow for easier customization via inheritance. diff --git a/src/unasync/__init__.py b/src/unasync/__init__.py index e669b9a..9cf329a 100644 --- a/src/unasync/__init__.py +++ b/src/unasync/__init__.py @@ -71,11 +71,14 @@ def _unasync_file(self, filepath): tokens = tokenize_rt.src_to_tokens(f.read()) tokens = self._unasync_tokens(tokens) result = tokenize_rt.tokens_to_src(tokens) - outfilepath = filepath.replace(self.fromdir, self.todir) + outfilepath = self.map_in_to_out_file_path(filepath) os.makedirs(os.path.dirname(outfilepath), exist_ok=True) with open(outfilepath, "wb") as f: f.write(result.encode(encoding)) + def map_in_to_out_file_path(self, in_file_path): + return in_file_path.replace(self.fromdir, self.todir) + def _unasync_tokens(self, tokens): skip_next = False for i, token in enumerate(tokens):