Skip to content

Commit 9478759

Browse files
committed
feat: enhance RAM monitoring and configuration management in FortScript
1 parent 52b63ae commit 9478759

7 files changed

Lines changed: 139 additions & 101 deletions

File tree

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ log_level: "INFO"
138138
You can pass all configurations directly in Python code without needing a YAML file:
139139
140140
```python
141-
from fortscript import FortScript
141+
from fortscript import FortScript, RamConfig
142142

143143
app = FortScript(
144144
projects=[
@@ -149,8 +149,7 @@ app = FortScript(
149149
{"name": "GTA V", "process": "gta5"},
150150
{"name": "OBS Studio", "process": "obs64"},
151151
],
152-
ram_threshold=90,
153-
ram_safe=80,
152+
ram_config=RamConfig(threshold=90, safe=80),
154153
log_level="INFO",
155154
)
156155

@@ -188,7 +187,7 @@ app.run()
188187
Run custom functions when scripts are paused or resumed:
189188

190189
```python
191-
from fortscript import FortScript
190+
from fortscript import FortScript, Callbacks
192191

193192
def when_paused():
194193
print("🎮 Gaming mode active! Scripts paused.")
@@ -198,8 +197,10 @@ def when_resumed():
198197

199198
app = FortScript(
200199
config_path="fortscript.yaml",
201-
on_pause=when_paused,
202-
on_resume=when_resumed,
200+
callbacks=Callbacks(
201+
on_pause=when_paused,
202+
on_resume=when_resumed,
203+
)
203204
)
204205

205206
app.run()
@@ -210,7 +211,7 @@ app.run()
210211
To keep your code organized, you can separate project and process lists into variables.
211212

212213
```python
213-
from fortscript import FortScript
214+
from fortscript import FortScript, RamConfig, Callbacks
214215

215216
# 1. Define your callbacks
216217
def notify_pause():
@@ -237,10 +238,11 @@ my_processes = [
237238
app = FortScript(
238239
projects=my_projects,
239240
heavy_process=my_processes,
240-
ram_threshold=90,
241-
ram_safe=80,
242-
on_pause=notify_pause,
243-
on_resume=notify_resume,
241+
ram_config=RamConfig(threshold=90, safe=80),
242+
callbacks=Callbacks(
243+
on_pause=notify_pause,
244+
on_resume=notify_resume
245+
),
244246
log_level="DEBUG",
245247
)
246248

@@ -316,10 +318,11 @@ def on_resume():
316318
app = FortScript(
317319
projects=my_projects,
318320
heavy_process=my_heavy_processes,
319-
ram_threshold=85,
320-
ram_safe=75,
321-
on_pause=on_pause,
322-
on_resume=on_resume,
321+
ram_config=RamConfig(threshold=85, safe=75),
322+
callbacks=Callbacks(
323+
on_pause=on_pause,
324+
on_resume=on_resume,
325+
),
323326
)
324327

325328
if __name__ == "__main__":
@@ -339,7 +342,7 @@ if __name__ == "__main__":
339342
- [ ] **Graceful Shutdown**: Try a graceful shutdown (SIGINT/CTRL+C) before forcing process termination.
340343
- [ ] **Dead Process Handling**: Periodically check if started processes are still alive.
341344
- [ ] **Project Abstraction**: Refactor into classes (`PythonProject`, `NodeProject`) to easily add new languages.
342-
- [ ] **Type Hinting**: Improve typing across all methods for better IDE support.
345+
- [x] **Type Hinting**: Improve typing across all methods for better IDE support.
343346

344347
### CLI
345348

README_ptBR.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ log_level: "INFO"
152152
Você pode passar todas as configurações diretamente no código Python, sem precisar de arquivo YAML:
153153

154154
```python
155-
from fortscript import FortScript
155+
from fortscript import FortScript, RamConfig
156156
157157
app = FortScript(
158158
projects=[
@@ -163,8 +163,7 @@ app = FortScript(
163163
{"name": "GTA V", "process": "gta5"},
164164
{"name": "OBS Studio", "process": "obs64"},
165165
],
166-
ram_threshold=90,
167-
ram_safe=80,
166+
ram_config=RamConfig(threshold=90, safe=80),
168167
log_level="INFO",
169168
)
170169
@@ -204,7 +203,7 @@ app.run()
204203
Execute funções personalizadas quando os scripts são pausados ou retomados:
205204

206205
```python
207-
from fortscript import FortScript
206+
from fortscript import FortScript, Callbacks
208207
209208
def quando_pausar():
210209
print("🎮 Modo gaming ativado! Scripts pausados.")
@@ -216,8 +215,10 @@ def quando_retomar():
216215
217216
app = FortScript(
218217
config_path="fortscript.yaml",
219-
on_pause=quando_pausar, # Função executada ao pausar
220-
on_resume=quando_retomar, # Função executada ao retomar
218+
callbacks=Callbacks(
219+
on_pause=quando_pausar, # Função executada ao pausar
220+
on_resume=quando_retomar, # Função executada ao retomar
221+
)
221222
)
222223
223224
app.run()
@@ -228,7 +229,7 @@ app.run()
228229
Para manter seu código organizado, você pode separar as listas de projetos e processos em variáveis.
229230

230231
```python
231-
from fortscript import FortScript
232+
from fortscript import FortScript, RamConfig, Callbacks
232233
233234
# 1. Defina seus callbacks
234235
def notificar_pausa():
@@ -255,10 +256,11 @@ meus_processos = [
255256
app = FortScript(
256257
projects=meus_projetos,
257258
heavy_process=meus_processos,
258-
ram_threshold=90, # Pausar se RAM > 90%
259-
ram_safe=80, # Retomar se RAM < 80%
260-
on_pause=notificar_pausa,
261-
on_resume=notificar_retomada,
259+
ram_config=RamConfig(threshold=90, safe=80),
260+
callbacks=Callbacks(
261+
on_pause=notificar_pausa,
262+
on_resume=notificar_retomada
263+
),
262264
log_level="DEBUG",
263265
)
264266
@@ -335,10 +337,11 @@ def ao_retomar():
335337
app = FortScript(
336338
projects=meus_projetos,
337339
heavy_process=meus_processos_pesados,
338-
ram_threshold=85,
339-
ram_safe=75,
340-
on_pause=ao_pausar,
341-
on_resume=ao_retomar,
340+
ram_config=RamConfig(threshold=85, safe=75),
341+
callbacks=Callbacks(
342+
on_pause=ao_pausar,
343+
on_resume=ao_retomar,
344+
),
342345
)
343346
344347
if __name__ == "__main__":
@@ -372,7 +375,6 @@ if __name__ == "__main__":
372375
- [ ] **Encerramento Amigável**: Tentar um encerramento gracioso (SIGINT/CTRL+C) antes de forçar o término do processo.
373376
- [ ] **Tratamento de Processos Mortos**: Verificar periodicamente se os processos iniciados ainda estão vivos.
374377
- [ ] **Abstração de Projetos**: Refatorar para classes (`PythonProject`, `NodeProject`) facilitando a adição de novas linguagens.
375-
- [ ] **Type Hinting**: Melhorar a tipagem em todos os métodos para melhor suporte em IDEs.
376378
- [ ] Arrumar bugs relacionado a path, atualmente se adicionar um script python e ele não estiver na raiz do projeto o venv não sera executado, fortscript tenta executar com python padrão, mas da erro por não possuir os imports e a janela do terminal se encerra
377379

378380
### CLI
@@ -400,6 +402,7 @@ if __name__ == "__main__":
400402
- [x] Níveis de log configuráveis (DEBUG, INFO, WARNING, ERROR)
401403
- [x] Encerramento seguro de processos (tree-kill)
402404
- [x] Adicionar opção de ativar ou desativar as janelas que aparecem dos scripts (Apenas em OS Windows)
405+
- [x] Type Hinting: Melhorar a tipagem em todos os métodos para melhor suporte em IDEs.
403406

404407
---
405408

src/fortscript/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .main import FortScript as FortScript
2-
from .games import GAMES as GAMES
1+
from .main import FortScript, RamConfig
2+
from .games import GAMES
33

4-
__all__ = ['FortScript', 'GAMES']
4+
__all__ = ['FortScript', 'RamConfig', 'GAMES']

src/fortscript/cookbook/project_with_arguments/main.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import os
33

4-
from fortscript import FortScript
4+
from fortscript import Callbacks, FortScript, RamConfig
55

66
# Basic logging configuration for the cookbook example
77
logging.basicConfig(format='%(message)s')
@@ -33,14 +33,20 @@ def on_resume():
3333
print('>>> [Event] System stable. Returning to development mode...')
3434

3535

36+
ram = RamConfig(
37+
threshold=90, # Pause if RAM usage exceeds 90%
38+
safe=80, # Resume only when RAM falls below 80% (Hysteresis)
39+
)
40+
3641
# Initialize FortScript with our custom configuration and events
3742
app = FortScript(
3843
projects=development_projects,
3944
heavy_process=productivity_blockers,
40-
ram_threshold=90, # Pause if RAM usage exceeds 90%
41-
ram_safe=80, # Resume only when RAM falls below 80% (Hysteresis)
42-
on_pause=on_pause,
43-
on_resume=on_resume,
45+
ram_config=ram,
46+
callbacks=Callbacks(
47+
on_pause=on_pause,
48+
on_resume=on_resume,
49+
),
4450
log_level='DEBUG', # Show detailed logs for debugging
4551
)
4652

src/fortscript/cookbook/project_with_games_list/main.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from fortscript import GAMES, Callbacks, FortScript, RamConfig
12
import logging
23
import os
34
import sys
@@ -8,7 +9,6 @@
89
if src_path not in sys.path:
910
sys.path.insert(0, src_path)
1011

11-
from fortscript import FortScript, GAMES
1212

1313
# Basic logging configuration
1414
logging.basicConfig(format='%(message)s')
@@ -36,10 +36,11 @@ def on_resume():
3636
app = FortScript(
3737
projects=development_projects,
3838
heavy_process=GAMES, # Using the imported list directly
39-
ram_threshold=95,
40-
ram_safe=85,
41-
on_pause=on_pause,
42-
on_resume=on_resume,
39+
ram_config=RamConfig(threshold=95, safe=85),
40+
callbacks=Callbacks(
41+
on_pause=on_pause,
42+
on_resume=on_resume,
43+
),
4344
log_level='DEBUG',
4445
)
4546

@@ -48,7 +49,8 @@ def on_resume():
4849
print('This example uses the pre-defined "GAMES" list from the library.')
4950
print(f'Loaded {len(GAMES)} game definitions automatically.')
5051

51-
# We will not call app.run() here to avoid blocking the CI/Interactive session indefinitely
52+
# We will not call app.run() here to avoid blocking
53+
# the CI/Interactive session indefinitely
5254
# but we will simulate the check to prove it works.
5355

5456
print('\n--- Verifying Configuration ---')
@@ -59,7 +61,6 @@ def on_resume():
5961
first_game = GAMES[0]['name']
6062
print(f'First monitored game: {first_game}')
6163

62-
print(
63-
"\n✅ Setup complete. To run the full loop, uncomment 'app.run()' in the code."
64-
)
64+
print('\n✅ Setup complete. '
65+
"To run the full loop, uncomment 'app.run()' in the code.")
6566
app.run()

src/fortscript/cookbook/project_with_yaml_file/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import os
33

4-
from fortscript import FortScript
4+
from fortscript import Callbacks, FortScript
55

66
# Basic logging configuration for the cookbook example
77
logging.basicConfig(level=logging.INFO, format='%(message)s')
@@ -23,7 +23,8 @@ def welcome_back():
2323

2424
# Initialize FortScript using the external YAML file and events
2525
app = FortScript(
26-
config_path=config_path, on_pause=alert_system, on_resume=welcome_back
26+
config_path=config_path,
27+
callbacks=Callbacks(on_pause=alert_system, on_resume=welcome_back),
2728
)
2829

2930

0 commit comments

Comments
 (0)