Skip to content

Commit 19f5b15

Browse files
authored
Tweak API (#59)
1 parent 3ee4a8a commit 19f5b15

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

docs/source/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ customized :code:`unasync.Rule` instances to :code:`unasync.cmdclass_build_py()`
8181
# This rule's 'fromdir' is more specific so will take precedent
8282
# over the above rule if the path is within /ahip/tests/...
8383
# This rule adds an additional token replacement over the default replacements.
84-
unasync.Rule("/ahip/tests/", "/hip/tests/", replacements={"ahip": "hip"}),
84+
unasync.Rule("/ahip/tests/", "/hip/tests/", additional_replacements={"ahip": "hip"}),
8585
])},
8686
...
8787
)
@@ -99,7 +99,7 @@ You can also use unasync without setuptools, to run unasync on tests, for exampl
9999
unasync.unasync_files(
100100
[file1, file2, ...],
101101
rules=[
102-
unasync.Rule("tests/", "tests_sync/", replacements={"ahip": "hip"}),
102+
unasync.Rule("tests/", "tests_sync/", additional_replacements={"ahip": "hip"}),
103103
]
104104
)
105105

src/unasync/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
class Rule:
3838
"""A single set of rules for 'unasync'ing file(s)"""
3939

40-
def __init__(self, fromdir, todir, replacements=None):
40+
def __init__(self, fromdir, todir, additional_replacements=None):
4141
self.fromdir = fromdir.replace("/", os.sep)
4242
self.todir = todir.replace("/", os.sep)
4343

4444
# Add any additional user-defined token replacements to our list.
4545
self.token_replacements = _ASYNC_TO_SYNC.copy()
46-
for key, val in (replacements or {}).items():
46+
for key, val in (additional_replacements or {}).items():
4747
self.token_replacements[key] = val
4848

4949
def _match(self, filepath):
@@ -63,7 +63,7 @@ def _match(self, filepath):
6363

6464
return False
6565

66-
def unasync_file(self, filepath):
66+
def _unasync_file(self, filepath):
6767
with open(filepath, "rb") as f:
6868
write_kwargs = {}
6969
if sys.version_info[0] >= 3:
@@ -120,7 +120,7 @@ def unasync_files(fpath_list, rules):
120120
found_weight = weight
121121

122122
if found_rule:
123-
found_rule.unasync_file(f)
123+
found_rule._unasync_file(f)
124124

125125

126126
Token = collections.namedtuple("Token", ["type", "string", "start", "end", "line"])

tests/data/example_custom_pkg/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
unasync.Rule(
1818
fromdir="/ahip/tests/",
1919
todir="/hip/tests/",
20-
replacements={"ahip": "hip"},
20+
additional_replacements={"ahip": "hip"},
2121
),
2222
]
2323
)

tests/test_unasync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_rule_on_short_path():
3737
def test_unasync(tmpdir, source_file):
3838

3939
rule = unasync.Rule(fromdir=ASYNC_DIR, todir=str(tmpdir))
40-
rule.unasync_file(os.path.join(ASYNC_DIR, source_file))
40+
rule._unasync_file(os.path.join(ASYNC_DIR, source_file))
4141

4242
encoding = "latin-1" if "encoding" in source_file else "utf-8"
4343
with io.open(os.path.join(SYNC_DIR, source_file), encoding=encoding) as f:

0 commit comments

Comments
 (0)