Skip to content
Merged
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
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ customized :code:`unasync.Rule` instances to :code:`unasync.cmdclass_build_py()`
# This rule's 'fromdir' is more specific so will take precedent
# over the above rule if the path is within /ahip/tests/...
# This rule adds an additional token replacement over the default replacements.
unasync.Rule("/ahip/tests/", "/hip/tests/", replacements={"ahip": "hip"}),
unasync.Rule("/ahip/tests/", "/hip/tests/", additional_replacements={"ahip": "hip"}),
])},
...
)
Expand All @@ -99,7 +99,7 @@ You can also use unasync without setuptools, to run unasync on tests, for exampl
unasync.unasync_files(
[file1, file2, ...],
rules=[
unasync.Rule("tests/", "tests_sync/", replacements={"ahip": "hip"}),
unasync.Rule("tests/", "tests_sync/", additional_replacements={"ahip": "hip"}),
]
)

Expand Down
8 changes: 4 additions & 4 deletions src/unasync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
class Rule:
"""A single set of rules for 'unasync'ing file(s)"""

def __init__(self, fromdir, todir, replacements=None):
def __init__(self, fromdir, todir, additional_replacements=None):
self.fromdir = fromdir.replace("/", os.sep)
self.todir = todir.replace("/", os.sep)

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

def _match(self, filepath):
Expand All @@ -63,7 +63,7 @@ def _match(self, filepath):

return False

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

if found_rule:
found_rule.unasync_file(f)
found_rule._unasync_file(f)


Token = collections.namedtuple("Token", ["type", "string", "start", "end", "line"])
Expand Down
2 changes: 1 addition & 1 deletion tests/data/example_custom_pkg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
unasync.Rule(
fromdir="/ahip/tests/",
todir="/hip/tests/",
replacements={"ahip": "hip"},
additional_replacements={"ahip": "hip"},
),
]
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_unasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_rule_on_short_path():
def test_unasync(tmpdir, source_file):

rule = unasync.Rule(fromdir=ASYNC_DIR, todir=str(tmpdir))
rule.unasync_file(os.path.join(ASYNC_DIR, source_file))
rule._unasync_file(os.path.join(ASYNC_DIR, source_file))

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