From 2b00f33d20208ec182e0978c39e609d98bd716a5 Mon Sep 17 00:00:00 2001 From: Evgeniy Blinov Date: Wed, 29 Nov 2023 18:31:11 +0300 Subject: [PATCH 1/7] pyproject.toml instead the setup.py --- .github/workflows/tests_and_coverage.yml | 2 +- pyproject.toml | 32 ++++++++++++++++++++++ requirements_dev.txt | 1 + setup.py | 34 ------------------------ 4 files changed, 34 insertions(+), 35 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/tests_and_coverage.yml b/.github/workflows/tests_and_coverage.yml index 0693855..564a9f9 100644 --- a/.github/workflows/tests_and_coverage.yml +++ b/.github/workflows/tests_and_coverage.yml @@ -21,7 +21,7 @@ jobs: - name: Install the library shell: bash - run: python setup.py install + run: pip install . - name: Install dependencies shell: bash diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..712f464 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,32 @@ +[build-system] +requires = ['setuptools==68.0.0'] +build-backend = 'setuptools.build_meta' + +[project] +name = 'astrologic' +version = '0.0.5' +authors = [ + { name='Evgeniy Blinov', email='zheni-b@yandex.ru' }, +] +description = 'Автоматическая оптимизация кода на уровне АСТ' +readme = 'README.md' +requires-python = '>=3.7' +classifiers = [ + 'Operating System :: MacOS :: MacOS X', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'License :: OSI Approved :: MIT License', + 'Intended Audience :: Developers', + 'Topic :: Software Development :: Libraries', +] + +[project.urls] +'Source' = 'https://github.com/pomponchik/astrologic' +'Tracker' = 'https://github.com/pomponchik/astrologic/issues' diff --git a/requirements_dev.txt b/requirements_dev.txt index 495a146..9f6bc24 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,6 +1,7 @@ wheel==0.41.2 pip==23.2.1 twine==4.0.2 +build==0.9.0 pyparsing>=2.0.2 pytest==7.4.2 coverage==7.2.7 diff --git a/setup.py b/setup.py deleted file mode 100644 index 0fcd750..0000000 --- a/setup.py +++ /dev/null @@ -1,34 +0,0 @@ -from setuptools import setup, find_packages - -with open('README.md', 'r', encoding='utf8') as readme_file: - readme = readme_file.read() - -requirements = ['astunparse==1.6.3'] - -setup( - name='astrologic', - version='0.0.5', - author='Evgeniy Blinov', - author_email='zheni-b@yandex.ru', - description='Автоматическая оптимизация кода на уровне АСТ', - long_description=readme, - long_description_content_type='text/markdown', - url='https://github.com/pomponchik/astrologic', - packages=find_packages(exclude=('tests',)), - install_requires=requirements, - classifiers=[ - 'Operating System :: MacOS :: MacOS X', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Operating System :: POSIX :: Linux', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'License :: OSI Approved :: MIT License', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - ], -) From 9913a51730852ef93b95c301b91f023264d8ba27 Mon Sep 17 00:00:00 2001 From: Evgeniy Blinov Date: Wed, 29 Nov 2023 18:31:52 +0300 Subject: [PATCH 2/7] + python 3.12 --- .github/workflows/tests_and_coverage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests_and_coverage.yml b/.github/workflows/tests_and_coverage.yml index 564a9f9..acaa111 100644 --- a/.github/workflows/tests_and_coverage.yml +++ b/.github/workflows/tests_and_coverage.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [macos-latest, ubuntu-latest, windows-latest] - python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v2 From 64927ccf9e629e4c5ad1636e7dd99d44d9bd114b Mon Sep 17 00:00:00 2001 From: Evgeniy Blinov Date: Wed, 29 Nov 2023 18:36:02 +0300 Subject: [PATCH 3/7] no pip --- requirements_dev.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements_dev.txt b/requirements_dev.txt index 9f6bc24..96f520a 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,5 +1,4 @@ wheel==0.41.2 -pip==23.2.1 twine==4.0.2 build==0.9.0 pyparsing>=2.0.2 From c2bf9c9b77c4ec6e5f12b3ec5528ea349560fc76 Mon Sep 17 00:00:00 2001 From: Evgeniy Blinov Date: Wed, 29 Nov 2023 18:41:22 +0300 Subject: [PATCH 4/7] classifier --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 712f464..449ab65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ classifiers = [ 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'License :: OSI Approved :: MIT License', 'Intended Audience :: Developers', 'Topic :: Software Development :: Libraries', From c0e2b63aa1811a4da921e56f2b30830c4da266c3 Mon Sep 17 00:00:00 2001 From: Evgeniy Blinov Date: Wed, 29 Nov 2023 18:41:38 +0300 Subject: [PATCH 5/7] no version tag --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 449ab65..cc7a31c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = 'setuptools.build_meta' [project] name = 'astrologic' -version = '0.0.5' +version = '0.0.6' authors = [ { name='Evgeniy Blinov', email='zheni-b@yandex.ru' }, ] From c3bea7450b877a10b3c891410e299449d9fc5a8b Mon Sep 17 00:00:00 2001 From: Evgeniy Blinov Date: Wed, 29 Nov 2023 19:10:51 +0300 Subject: [PATCH 6/7] logo in the readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a5cf39e..a9f9520 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![logo](https://raw.githubusercontent.com/pomponchik/astrologic/develop/docs/assets/logo_3.png) +![logo](https://raw.githubusercontent.com/pomponchik/astrologic/main/docs/assets/logo_3.png) [![Downloads](https://static.pepy.tech/badge/astrologic/month)](https://pepy.tech/project/astrologic) [![Downloads](https://static.pepy.tech/badge/astrologic)](https://pepy.tech/project/astrologic) From 5a2a307bfea941ce7a01c7666cf2354fc458333a Mon Sep 17 00:00:00 2001 From: Evgeniy Blinov Date: Wed, 29 Nov 2023 19:19:27 +0300 Subject: [PATCH 7/7] ruff --- .github/workflows/lint.yml | 28 +++++++++++++++++++ .ruff.toml | 1 + README.md | 1 + astrologic/__init__.py | 6 ++-- astrologic/decorators/base.py | 3 +- astrologic/decorators/if_switcher.py | 2 +- astrologic/decorators/inline.py | 6 ++-- .../decorators/tail_recursion_optimization.py | 5 ++-- requirements_dev.txt | 1 + 9 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .ruff.toml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..f9f8bef --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,28 @@ +name: Lint + +on: + push + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.7'] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + shell: bash + run: pip install -r requirements_dev.txt + + - name: Run ruff + shell: bash + run: ruff astrologic diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..ec5b9a4 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1 @@ +ignore = ['E501', 'E712'] diff --git a/README.md b/README.md index a9f9520..bc08edb 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ [![Test-Package](https://github.com/pomponchik/astrologic/actions/workflows/tests_and_coverage.yml/badge.svg)](https://github.com/pomponchik/astrologic/actions/workflows/tests_and_coverage.yml) [![Python versions](https://img.shields.io/pypi/pyversions/astrologic.svg)](https://pypi.python.org/pypi/astrologic) [![PyPI version](https://badge.fury.io/py/astrologic.svg)](https://badge.fury.io/py/astrologic) +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) Пакет Astrologic содержит ряд инструментов, позволяющих "в рантайме" оптимизировать работу ваших функций или даже конструировать новые функции. Все это достигается за счет парсинга и преобразования [AST](https://docs.python.org/3/library/ast.html) исходной функции. Парсинг происходит полностью "под капотом" и невидим для пользователя. diff --git a/astrologic/__init__.py b/astrologic/__init__.py index 744da69..2032a22 100644 --- a/astrologic/__init__.py +++ b/astrologic/__init__.py @@ -1,3 +1,3 @@ -from astrologic.decorators.if_switcher import switcher -from astrologic.decorators.tail_recursion_optimization import no_recursion -from astrologic.decorators.inline import inline +from astrologic.decorators.if_switcher import switcher # noqa: F401 +from astrologic.decorators.tail_recursion_optimization import no_recursion # noqa: F401 +from astrologic.decorators.inline import inline # noqa: F401 diff --git a/astrologic/decorators/base.py b/astrologic/decorators/base.py index ffeb695..5ea9c5a 100644 --- a/astrologic/decorators/base.py +++ b/astrologic/decorators/base.py @@ -1,7 +1,6 @@ import ast import inspect import functools -import textwrap import importlib import astunparse @@ -75,7 +74,7 @@ def visit(_self, node): try: if isinstance(node, ast.Name): all_original_names.add(node.id) - except: + except Exception: pass Visiter().visit(tree) return all_original_names diff --git a/astrologic/decorators/if_switcher.py b/astrologic/decorators/if_switcher.py index 4253569..51793e2 100644 --- a/astrologic/decorators/if_switcher.py +++ b/astrologic/decorators/if_switcher.py @@ -14,7 +14,7 @@ def visit_If(self, node): else: return node.body return node - except: + except Exception: return node return RewriteName().visit(tree) diff --git a/astrologic/decorators/inline.py b/astrologic/decorators/inline.py index 6121036..bb2a6fe 100644 --- a/astrologic/decorators/inline.py +++ b/astrologic/decorators/inline.py @@ -23,7 +23,7 @@ def visit_Expr(_self, node): return declarations + new_block else: return _node - except Exception as e: + except Exception: return node return VisiterCalls().visit(tree) @@ -60,7 +60,7 @@ def visit_Name(_self, node): new_name = self.new_name(all_original_names, name, cached_names) node.id = new_name return node - except Exception as e: + except Exception: return node tree = ast.fix_missing_locations(Visiter().visit(tree)) declarations = self.get_declaration_block(tree, call_node, cached_names) @@ -69,7 +69,7 @@ def visit_Name(_self, node): def new_name(self, all_original_names, name, cache): if name in cache: return cache[name] - number = 0 + while True: new_name = 'generated_' + uuid.uuid4().hex if new_name not in all_original_names: diff --git a/astrologic/decorators/tail_recursion_optimization.py b/astrologic/decorators/tail_recursion_optimization.py index d24c721..b451553 100644 --- a/astrologic/decorators/tail_recursion_optimization.py +++ b/astrologic/decorators/tail_recursion_optimization.py @@ -10,8 +10,7 @@ class TailRecursionOptimization(BaseDecorator): @staticmethod def add_prefix_and_postfix(function_text, original_function): - function_name = original_function.__name__ - prefix = f"""def superfunction(*args, **kwargs): + prefix = """def superfunction(*args, **kwargs): is_recursion = False """ postfix = f""" while True: @@ -45,7 +44,7 @@ def is_recursion(self, function_name, node): if node.value.func.id == function_name: return True return False - except: + except Exception: return False def convert_tree_to_function(self, tree, original_function, namespace, debug_mode_on): diff --git a/requirements_dev.txt b/requirements_dev.txt index 96f520a..5411d73 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -5,3 +5,4 @@ pyparsing>=2.0.2 pytest==7.4.2 coverage==7.2.7 astunparse==1.6.3 +ruff==0.0.290