pyinterfaces 0.0.1__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,119 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyinterfaces
3
+ Version: 0.1.1
4
+ Summary: Interface in POO with Python
5
+ License-Expression: MIT
6
+ License-File: license.txt
7
+ Keywords: interface,java,syntax,brunozolotareff,pyinterfaces
8
+ Author: Bruno Zolotareff
9
+ Author-email: brunozolotareff@gmail.com
10
+ Requires-Python: >=3.8
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Description-Content-Type: text/markdown
20
+
21
+ # pyinterfaces
22
+
23
+ A lightweight Python compiler extension that brings clean, Java-style interface syntax to Python using native braces `{}`.
24
+
25
+ [![PyPI version](https://shields.io)](https://pypi.org)
26
+ [![Python Versions](https://shields.io)](https://pypi.org)
27
+
28
+ ---
29
+
30
+ ## 📐 Why pyinterfaces? (Software Engineering Perspective)
31
+
32
+ In modern **Software Engineering**, separating *definition* from *implementation* is a core architectural principle.
33
+ Following SOLID principles—specifically the **Interface Segregation Principle (ISP)** and the **Dependency Inversion Principle (DIP)**—software components should depend on abstractions (interfaces), not on concrete logic.
34
+
35
+ While standard Python uses `abc.ABC` and `@abstractmethod` to enforce contracts, the syntax can often look cluttered, repetitive, and conceptually muddy (as Python abstract classes can accidentally mix actual logic with abstract models).
36
+
37
+ **`pyinterfaces`** bridges this gap by enforcing **Pure Interfaces**. It allows software engineers to declare strict structural contracts using the familiar, elegant, and universally understood Java/C# layout, keeping your architecture clean and highly readable.
38
+
39
+ ---
40
+
41
+ ## ✨ Features
42
+
43
+ - **Java-Style Syntax**: Declare structures using `Interface Name { ... }`.
44
+ - **Pure Abstraction**: No mixed implementation code allowed inside the contract block.
45
+ - **Runtime Enforcement**: Automatically triggers native Python `abc` validations under the hood.
46
+ - **Zero Overhead**: Translated seamlessly during file tokenization using custom stream decoding.
47
+
48
+ ---
49
+
50
+ ## 🚀 Installation
51
+
52
+ You can install `pyinterfaces` via `pip` or add it to your project using `poetry`:
53
+
54
+ ```bash
55
+ pip install pyinterfaces
56
+ ```
57
+
58
+ Or with Poetry:
59
+ ```bash
60
+ poetry add pyinterfaces
61
+ ```
62
+
63
+ ---
64
+
65
+ ## 💻 Usage
66
+
67
+ To enable the custom Java-like syntax parsing, you **must** include the magic encoding comment `# -*- coding: java_interface -*-` at the very first line of your Python script.
68
+
69
+ Here is a standard example of designing a decoupled Payment System:
70
+
71
+ ```python
72
+ # -*- coding: java_interface -*-
73
+ import pyinterfaces
74
+
75
+ # 1. Define the pure architectural contract
76
+ Interface PaymentProcessor {
77
+ process_payment(self, amount: float) -> bool
78
+ refund_payment(self, transaction_id: str) -> None
79
+ }
80
+
81
+ # 2. Implement the contract in standard Python classes
82
+ class PixProcessor(PaymentProcessor):
83
+ def process_payment(self, amount: float) -> bool:
84
+ print(f"Processing R\${amount} instantly via Pix.")
85
+ return True
86
+
87
+ def refund_payment(self, transaction_id: str) -> None:
88
+ print(f"Refunding transaction {transaction_id}.")
89
+
90
+ # 3. Compile-time / Runtime validation
91
+ class BrokenProcessor(PaymentProcessor):
92
+ def process_payment(self, amount: float) -> bool:
93
+ return True
94
+ # ERROR! Missing 'refund_payment' method implementation.
95
+ ```
96
+
97
+ If a developer attempts to instantiate `BrokenProcessor`, Python will instantly raise a `TypeError`, stating that the class failed to implement the strict contract requirements defined by your interface.
98
+
99
+ ---
100
+
101
+ ## 🛠️ How it works under the hood
102
+
103
+ `pyinterfaces` hooks directly into Python's native `codecs` registry. When the interpretator reads the `# -*- coding: java_interface -*-` header, it streams your file through our custom pre-processor, safely transforming the custom block syntax into fully valid standard Python `abc.ABC` structures before the code even executes.
104
+
105
+ ---
106
+
107
+ ## 👤 Author
108
+
109
+ - Created and maintained by **Bruno Zolotareff**
110
+ - PyPI Repository: [https://pypi.org](https://pypi.org)
111
+
112
+ ## 🤝 Acknowledgments
113
+
114
+ Special thanks to my friend **Leandro Reginaldo** for collaborating on the original concept, brainstorming the architectural ideas, and helping to shape the vision of `pyinterfaces`. This project wouldn't be the same without your insights!
115
+
116
+
117
+ ## 📄 License
118
+
119
+ This project is licensed under the MIT License.
@@ -0,0 +1,99 @@
1
+ # pyinterfaces
2
+
3
+ A lightweight Python compiler extension that brings clean, Java-style interface syntax to Python using native braces `{}`.
4
+
5
+ [![PyPI version](https://shields.io)](https://pypi.org)
6
+ [![Python Versions](https://shields.io)](https://pypi.org)
7
+
8
+ ---
9
+
10
+ ## 📐 Why pyinterfaces? (Software Engineering Perspective)
11
+
12
+ In modern **Software Engineering**, separating *definition* from *implementation* is a core architectural principle.
13
+ Following SOLID principles—specifically the **Interface Segregation Principle (ISP)** and the **Dependency Inversion Principle (DIP)**—software components should depend on abstractions (interfaces), not on concrete logic.
14
+
15
+ While standard Python uses `abc.ABC` and `@abstractmethod` to enforce contracts, the syntax can often look cluttered, repetitive, and conceptually muddy (as Python abstract classes can accidentally mix actual logic with abstract models).
16
+
17
+ **`pyinterfaces`** bridges this gap by enforcing **Pure Interfaces**. It allows software engineers to declare strict structural contracts using the familiar, elegant, and universally understood Java/C# layout, keeping your architecture clean and highly readable.
18
+
19
+ ---
20
+
21
+ ## ✨ Features
22
+
23
+ - **Java-Style Syntax**: Declare structures using `Interface Name { ... }`.
24
+ - **Pure Abstraction**: No mixed implementation code allowed inside the contract block.
25
+ - **Runtime Enforcement**: Automatically triggers native Python `abc` validations under the hood.
26
+ - **Zero Overhead**: Translated seamlessly during file tokenization using custom stream decoding.
27
+
28
+ ---
29
+
30
+ ## 🚀 Installation
31
+
32
+ You can install `pyinterfaces` via `pip` or add it to your project using `poetry`:
33
+
34
+ ```bash
35
+ pip install pyinterfaces
36
+ ```
37
+
38
+ Or with Poetry:
39
+ ```bash
40
+ poetry add pyinterfaces
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 💻 Usage
46
+
47
+ To enable the custom Java-like syntax parsing, you **must** include the magic encoding comment `# -*- coding: java_interface -*-` at the very first line of your Python script.
48
+
49
+ Here is a standard example of designing a decoupled Payment System:
50
+
51
+ ```python
52
+ # -*- coding: java_interface -*-
53
+ import pyinterfaces
54
+
55
+ # 1. Define the pure architectural contract
56
+ Interface PaymentProcessor {
57
+ process_payment(self, amount: float) -> bool
58
+ refund_payment(self, transaction_id: str) -> None
59
+ }
60
+
61
+ # 2. Implement the contract in standard Python classes
62
+ class PixProcessor(PaymentProcessor):
63
+ def process_payment(self, amount: float) -> bool:
64
+ print(f"Processing R\${amount} instantly via Pix.")
65
+ return True
66
+
67
+ def refund_payment(self, transaction_id: str) -> None:
68
+ print(f"Refunding transaction {transaction_id}.")
69
+
70
+ # 3. Compile-time / Runtime validation
71
+ class BrokenProcessor(PaymentProcessor):
72
+ def process_payment(self, amount: float) -> bool:
73
+ return True
74
+ # ERROR! Missing 'refund_payment' method implementation.
75
+ ```
76
+
77
+ If a developer attempts to instantiate `BrokenProcessor`, Python will instantly raise a `TypeError`, stating that the class failed to implement the strict contract requirements defined by your interface.
78
+
79
+ ---
80
+
81
+ ## 🛠️ How it works under the hood
82
+
83
+ `pyinterfaces` hooks directly into Python's native `codecs` registry. When the interpretator reads the `# -*- coding: java_interface -*-` header, it streams your file through our custom pre-processor, safely transforming the custom block syntax into fully valid standard Python `abc.ABC` structures before the code even executes.
84
+
85
+ ---
86
+
87
+ ## 👤 Author
88
+
89
+ - Created and maintained by **Bruno Zolotareff**
90
+ - PyPI Repository: [https://pypi.org](https://pypi.org)
91
+
92
+ ## 🤝 Acknowledgments
93
+
94
+ Special thanks to my friend **Leandro Reginaldo** for collaborating on the original concept, brainstorming the architectural ideas, and helping to shape the vision of `pyinterfaces`. This project wouldn't be the same without your insights!
95
+
96
+
97
+ ## 📄 License
98
+
99
+ This project is licensed under the MIT License.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ """
2
+ pyinterfaces - Java-style interfaces for Python.
3
+
4
+ Co-conceptualized and inspired by Leandro Reginaldo.
5
+ Maintained by Bruno Zolotareff.
6
+ """
7
+
8
+
9
+ from .compilador import registrar_syntax
10
+
11
+ # Ativa o mecanismo de codec assim que a biblioteca é importada
12
+ registrar_syntax()
@@ -0,0 +1,69 @@
1
+ import codecs
2
+ import io
3
+ import re
4
+
5
+ def traduzir_sintaxe_java(texto: str) -> str:
6
+ """
7
+ Varre o arquivo de texto substituindo a sintaxe 'Interface Nome { ... }'
8
+ por classes Python puras usando abc.ABC e @abstractmethod.
9
+ """
10
+ linhas = texto.split('\n')
11
+ resultado = ["from abc import ABC, abstractmethod\n"]
12
+ dentro_da_interface = False
13
+
14
+ for linha in linhas:
15
+ # 1. Detecta o início da declaração: 'Interface Nome {'
16
+ inicio_match = re.match(r'\s*Interface\s+(\w+)\s*\{', linha)
17
+ if inicio_match:
18
+ nome_interface = inicio_match.group(1)
19
+ resultado.append(f"class {nome_interface}(ABC):")
20
+ dentro_da_interface = True
21
+ continue
22
+
23
+ if dentro_da_interface:
24
+ # 2. Detecta o fechamento da interface com a chave '}'
25
+ if '}' in linha:
26
+ dentro_da_interface = False
27
+ continue
28
+
29
+ # 3. Limpa pontos e vírgulas do estilo Java e captura o método
30
+ metodo_limpo = linha.strip().replace(';', '')
31
+ if metodo_limpo:
32
+ # Transforma a assinatura em um método abstrato Python
33
+ resultado.append(f" @abstractmethod")
34
+ resultado.append(f" def {metodo_limpo}:")
35
+ resultado.append(f" pass")
36
+ else:
37
+ # Mantém qualquer outra linha de código Python normal intacta
38
+ resultado.append(linha)
39
+
40
+ return '\n'.join(resultado)
41
+
42
+ # --- INFRAESTRUTURA DE CODEC DO PYTHON (ATUALIZADA) ---
43
+
44
+ class JavaInterfaceDecoder(codecs.BufferedIncrementalDecoder):
45
+ def _buffer_decode(self, input, errors, final):
46
+ if final:
47
+ # CORREÇÃO: Força a conversão para bytes caso o Python envie um memoryview
48
+ dados_em_bytes = bytes(input)
49
+ texto_traduzido = traduzir_sintaxe_java(dados_em_bytes.decode('utf-8'))
50
+ return (texto_traduzido, len(input))
51
+ return ('', 0)
52
+
53
+ def buscar_codec(nome_codec):
54
+ if nome_codec == 'py_interface':
55
+ return codecs.CodecInfo(
56
+ name='py_interface',
57
+ encode=codecs.utf_8_encode,
58
+ # CORREÇÃO: Aplicamos o cast de bytes(input) também na leitura direta do decode
59
+ decode=lambda input, errors='strict': (traduzir_sintaxe_java(bytes(input).decode('utf-8')), len(input)),
60
+ incrementalencoder=codecs.utf_8_encode,
61
+ incrementaldecoder=JavaInterfaceDecoder,
62
+ streamreader=lambda stream, errors='strict': io.StringIO(traduzir_sintaxe_java(stream.read().decode('utf-8'))),
63
+ streamwriter=codecs.utf_8_encode
64
+ )
65
+ return None
66
+
67
+ def registrar_syntax():
68
+ """Registra o tradutor de código dentro do núcleo de encodings do Python"""
69
+ codecs.register(buscar_codec)
@@ -1,11 +1,14 @@
1
1
  [project]
2
2
  name = "pyinterfaces"
3
- version = "0.0.1"
3
+ version = "0.1.1"
4
4
  description = "Interface in POO with Python"
5
5
  authors = [
6
6
  {name = "Bruno Zolotareff",email = "brunozolotareff@gmail.com"}
7
7
  ]
8
- license = ""
8
+ readme = "README.md"
9
+ keywords = ["interface", "java", "syntax", "brunozolotareff", "pyinterfaces"]
10
+ packages = [{include = "pyinterfaces"}]
11
+ license = "MIT"
9
12
  requires-python = ">=3.8"
10
13
  dependencies = [
11
14
  ]
@@ -1,15 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: pyinterfaces
3
- Version: 0.0.1
4
- Summary: Interface in POO with Python
5
- Author: Bruno Zolotareff
6
- Author-email: brunozolotareff@gmail.com
7
- Requires-Python: >=3.8
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.8
10
- Classifier: Programming Language :: Python :: 3.9
11
- Classifier: Programming Language :: Python :: 3.10
12
- Classifier: Programming Language :: Python :: 3.11
13
- Classifier: Programming Language :: Python :: 3.12
14
- Classifier: Programming Language :: Python :: 3.13
15
- Classifier: Programming Language :: Python :: 3.14
File without changes