Skip to content

Commit

Permalink
apply black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed May 4, 2023
1 parent 01b2c8a commit 14b1e32
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/unasync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,19 @@ def _unasync_tokenize(self, contents, filename):
comment_lines_locations = []
for token in tokens:
# find line numbers where "unasync: remove" comments are found
if token.name == 'COMMENT' and 'unasync: remove' in token.src: # XXX: maybe make this a little more strict
if (
token.name == "COMMENT" and "unasync: remove" in token.src
): # XXX: maybe make this a little more strict
comment_lines_locations.append(token.line)

lines_to_remove = set()
if comment_lines_locations: # only parse ast if we actually have "unasync: remove" comments
if (
comment_lines_locations
): # only parse ast if we actually have "unasync: remove" comments
tree = ast.parse(contents, filename=filename)
for node in ast.walk(tree):
# find nodes whose line number (start line) intersect with unasync: remove comments
if hasattr(node, 'lineno') and node.lineno in comment_lines_locations:
if hasattr(node, "lineno") and node.lineno in comment_lines_locations:
for lineno in range(node.lineno, node.end_lineno + 1):
# find all lines related to each node and mark those lines for removal
lines_to_remove.add(lineno)
Expand Down
3 changes: 3 additions & 0 deletions tests/data/async/removals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# isort: skip_file
# fmt: off
from common import (
a, b , c # these should stick around
)
Expand Down Expand Up @@ -34,3 +36,4 @@ async def another_method(self):
print('This line should stick around')
await self.something("the content in this line should be removed") # unasync: remove

# fmt: on
3 changes: 3 additions & 0 deletions tests/data/sync/removals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# isort: skip_file
# fmt: off
from common import (
a, b , c # these should stick around
)
Expand All @@ -21,3 +23,4 @@ def foobar(self):
def another_method(self):
print('This line should stick around')

# fmt: on
5 changes: 0 additions & 5 deletions tests/test_unasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_rule_on_short_path():

@pytest.mark.parametrize("source_file", TEST_FILES)
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))

Expand Down Expand Up @@ -64,7 +63,6 @@ def test_unasync_files(tmpdir):


def test_build_py_modules(tmpdir):

source_modules_dir = os.path.join(TEST_DIR, "example_mod")
mod_dir = str(tmpdir) + "/" + "example_mod"
shutil.copytree(source_modules_dir, mod_dir)
Expand All @@ -84,7 +82,6 @@ def test_build_py_modules(tmpdir):


def test_build_py_packages(tmpdir):

source_pkg_dir = os.path.join(TEST_DIR, "example_pkg")
pkg_dir = str(tmpdir) + "/" + "example_pkg"
shutil.copytree(source_pkg_dir, pkg_dir)
Expand All @@ -101,7 +98,6 @@ def test_build_py_packages(tmpdir):


def test_project_structure_after_build_py_packages(tmpdir):

source_pkg_dir = os.path.join(TEST_DIR, "example_pkg")
pkg_dir = str(tmpdir) + "/" + "example_pkg"
shutil.copytree(source_pkg_dir, pkg_dir)
Expand All @@ -121,7 +117,6 @@ def test_project_structure_after_build_py_packages(tmpdir):


def test_project_structure_after_customized_build_py_packages(tmpdir):

source_pkg_dir = os.path.join(TEST_DIR, "example_custom_pkg")
pkg_dir = str(tmpdir) + "/" + "example_custom_pkg"
shutil.copytree(source_pkg_dir, pkg_dir)
Expand Down

0 comments on commit 14b1e32

Please sign in to comment.