Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/85.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add public method ``map_in_to_out_file_path`` to ``Rule`` to allow for easier customization via inheritance.
5 changes: 4 additions & 1 deletion src/unasync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading