Skip to content

Commit 6cae8a5

Browse files
authored
Merge pull request #196 from spyoungtech/unasync
unasync changes
2 parents 4f84ebd + 512d9b0 commit 6cae8a5

File tree

4 files changed

+3
-42
lines changed

4 files changed

+3
-42
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
files: ^(ahk/_async/.*\.py|\.unasync-rewrite\.py|tests/_async/.*\.py)
1111
pass_filenames: false
1212
additional_dependencies:
13-
- unasync
13+
- git+https://github.com/spyoungtech/unasync.git@unasync-remove
1414
- tokenize_rt
1515
- black
1616
- id: set-constants

.unasync-rewrite.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,15 @@
1-
import ast
21
import os
32
import shutil
43
import subprocess
54
import sys
65

76
import black
8-
from black import check_stability_and_equivalence
9-
from tokenize_rt import reversed_enumerate
10-
from tokenize_rt import src_to_tokens
11-
from tokenize_rt import tokens_to_src
127

138
GIT_EXECUTABLE = shutil.which('git')
149

1510
changes = 0
1611

1712

18-
def _rewrite_file(filename: str) -> int:
19-
with open(filename, encoding='UTF-8') as f:
20-
contents = f.read()
21-
tree = ast.parse(contents, filename=filename)
22-
tokens = src_to_tokens(contents)
23-
nodes_on_lines_to_remove = []
24-
for tok in tokens:
25-
if tok.name == 'COMMENT' and 'unasync: remove' in tok.src:
26-
nodes_on_lines_to_remove.append(tok.line)
27-
lines_to_remove = set()
28-
for node in ast.walk(tree):
29-
if hasattr(node, 'lineno') and node.lineno in nodes_on_lines_to_remove:
30-
for lineno in range(node.lineno, node.end_lineno + 1):
31-
lines_to_remove.add(lineno)
32-
for i, tok in reversed_enumerate(tokens):
33-
if tok.line in lines_to_remove:
34-
tokens.pop(i)
35-
new_contents = tokens_to_src(tokens)
36-
if new_contents != contents:
37-
with open(filename, 'w') as f:
38-
f.write(new_contents)
39-
return new_contents != contents
40-
41-
4213
def _copyfunc(src, dst, *, follow_symlinks=True):
4314
global changes
4415
with open(src, encoding='UTF-8') as f:
@@ -70,17 +41,7 @@ def main() -> int:
7041
if os.path.isdir('build'):
7142
shutil.rmtree('build')
7243
subprocess.run([sys.executable, 'setup.py', 'build_py'], check=True)
73-
for root, dirs, files in os.walk('build/lib/ahk/_sync'):
74-
for fname in files:
75-
if fname.endswith('.py'):
76-
fp = os.path.join(root, fname)
77-
_rewrite_file(fp)
7844
subprocess.run([sys.executable, '_tests_setup.py', 'build_py'], check=True)
79-
for root, dirs, files in os.walk('build/lib/tests/_sync'):
80-
for fname in files:
81-
if fname.endswith('.py'):
82-
fp = os.path.join(root, fname)
83-
_rewrite_file(fp)
8445
shutil.copytree('build/lib/ahk/_sync', 'ahk/_sync', dirs_exist_ok=True, copy_function=_copyfunc)
8546
shutil.copytree('build/lib/tests/_sync', 'tests/_sync', dirs_exist_ok=True, copy_function=_copyfunc)
8647

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[build-system]
2-
requires = ["setuptools", "unasync", "tokenize-rt"]
2+
requires = ["setuptools", "unasync @ https://github.com/spyoungtech/unasync/archive/refs/heads/unasync-remove.zip", "tokenize-rt"]

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[metadata]
22

33
name = ahk
4-
version = 1.1.0rc1
4+
version = 1.1.0rc2
55
author_email = [email protected]
66
author = Spencer Young
77
description = A Python wrapper for AHK

0 commit comments

Comments
 (0)