Skip to content

Commit

Permalink
Merge pull request #2 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.6
  • Loading branch information
pomponchik authored Nov 29, 2023
2 parents 947059c + 5a2a307 commit 2108549
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 50 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .github/workflows/tests_and_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +21,7 @@ jobs:

- name: Install the library
shell: bash
run: python setup.py install
run: pip install .

- name: Install dependencies
shell: bash
Expand Down
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore = ['E501', 'E712']
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
![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)
[![codecov](https://codecov.io/gh/pomponchik/astrologic/graph/badge.svg?token=GC8NH2FGJ9)](https://codecov.io/gh/pomponchik/astrologic)
[![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) исходной функции. Парсинг происходит полностью "под капотом" и невидим для пользователя.
Expand Down
6 changes: 3 additions & 3 deletions astrologic/__init__.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions astrologic/decorators/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ast
import inspect
import functools
import textwrap
import importlib

import astunparse
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion astrologic/decorators/if_switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def visit_If(self, node):
else:
return node.body
return node
except:
except Exception:
return node
return RewriteName().visit(tree)

Expand Down
6 changes: 3 additions & 3 deletions astrologic/decorators/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions astrologic/decorators/tail_recursion_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[build-system]
requires = ['setuptools==68.0.0']
build-backend = 'setuptools.build_meta'

[project]
name = 'astrologic'
version = '0.0.6'
authors = [
{ name='Evgeniy Blinov', email='[email protected]' },
]
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',
'Programming Language :: Python :: 3.12',
'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'
3 changes: 2 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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
astunparse==1.6.3
ruff==0.0.290
34 changes: 0 additions & 34 deletions setup.py

This file was deleted.

0 comments on commit 2108549

Please sign in to comment.