Skip to content

unasync changes #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2023
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
files: ^(ahk/_async/.*\.py|\.unasync-rewrite\.py|tests/_async/.*\.py)
pass_filenames: false
additional_dependencies:
- unasync
- git+https://github.com/spyoungtech/unasync.git@unasync-remove
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once python-trio/unasync#75 is merged and the new unasync version is published to pypi, we can remove this change

- tokenize_rt
- black
- id: set-constants
Expand Down
39 changes: 0 additions & 39 deletions .unasync-rewrite.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,15 @@
import ast
import os
import shutil
import subprocess
import sys

import black
from black import check_stability_and_equivalence
from tokenize_rt import reversed_enumerate
from tokenize_rt import src_to_tokens
from tokenize_rt import tokens_to_src

GIT_EXECUTABLE = shutil.which('git')

changes = 0


def _rewrite_file(filename: str) -> int:
with open(filename, encoding='UTF-8') as f:
contents = f.read()
tree = ast.parse(contents, filename=filename)
tokens = src_to_tokens(contents)
nodes_on_lines_to_remove = []
for tok in tokens:
if tok.name == 'COMMENT' and 'unasync: remove' in tok.src:
nodes_on_lines_to_remove.append(tok.line)
lines_to_remove = set()
for node in ast.walk(tree):
if hasattr(node, 'lineno') and node.lineno in nodes_on_lines_to_remove:
for lineno in range(node.lineno, node.end_lineno + 1):
lines_to_remove.add(lineno)
for i, tok in reversed_enumerate(tokens):
if tok.line in lines_to_remove:
tokens.pop(i)
new_contents = tokens_to_src(tokens)
if new_contents != contents:
with open(filename, 'w') as f:
f.write(new_contents)
return new_contents != contents


def _copyfunc(src, dst, *, follow_symlinks=True):
global changes
with open(src, encoding='UTF-8') as f:
Expand Down Expand Up @@ -70,17 +41,7 @@ def main() -> int:
if os.path.isdir('build'):
shutil.rmtree('build')
subprocess.run([sys.executable, 'setup.py', 'build_py'], check=True)
for root, dirs, files in os.walk('build/lib/ahk/_sync'):
for fname in files:
if fname.endswith('.py'):
fp = os.path.join(root, fname)
_rewrite_file(fp)
subprocess.run([sys.executable, '_tests_setup.py', 'build_py'], check=True)
for root, dirs, files in os.walk('build/lib/tests/_sync'):
for fname in files:
if fname.endswith('.py'):
fp = os.path.join(root, fname)
_rewrite_file(fp)
shutil.copytree('build/lib/ahk/_sync', 'ahk/_sync', dirs_exist_ok=True, copy_function=_copyfunc)
shutil.copytree('build/lib/tests/_sync', 'tests/_sync', dirs_exist_ok=True, copy_function=_copyfunc)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[build-system]
requires = ["setuptools", "unasync", "tokenize-rt"]
requires = ["setuptools", "unasync @ https://github.com/spyoungtech/unasync/archive/refs/heads/unasync-remove.zip", "tokenize-rt"]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once python-trio/unasync#75 is merged and the new unasync version is published to pypi, we can remove this change

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]

name = ahk
version = 1.1.0rc1
version = 1.1.0rc2
author_email = [email protected]
author = Spencer Young
description = A Python wrapper for AHK
Expand Down