Skip to content

Commit 76a03b8

Browse files
authored
Merge pull request #85 from robsdedude/feat/custom-file-mapping
Allow for custom file path mapping
2 parents 0470588 + 11ff9da commit 76a03b8

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

newsfragments/85.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add public method ``map_in_to_out_file_path`` to ``Rule`` to allow for easier customization via inheritance.

src/unasync/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ def _unasync_file(self, filepath):
7171
tokens = tokenize_rt.src_to_tokens(f.read())
7272
tokens = self._unasync_tokens(tokens)
7373
result = tokenize_rt.tokens_to_src(tokens)
74-
outfilepath = filepath.replace(self.fromdir, self.todir)
74+
outfilepath = self.map_in_to_out_file_path(filepath)
7575
os.makedirs(os.path.dirname(outfilepath), exist_ok=True)
7676
with open(outfilepath, "wb") as f:
7777
f.write(result.encode(encoding))
7878

79+
def map_in_to_out_file_path(self, in_file_path):
80+
return in_file_path.replace(self.fromdir, self.todir)
81+
7982
def _unasync_tokens(self, tokens):
8083
skip_next = False
8184
for i, token in enumerate(tokens):

0 commit comments

Comments
 (0)