-
Notifications
You must be signed in to change notification settings - Fork 1
Create AutoDiscover class in infra/module.py #4
base: master
Are you sure you want to change the base?
Conversation
09474d7 to
f6fcc7f
Compare
f6fcc7f to
e22647d
Compare
| continue | ||
|
|
||
| if ( | ||
| obj.is_file() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💅 Tem uns espaços a mais aqui... acho que da pra alinhar o obj com and.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hahaha eu deixei para alinhar a condição... mas posso voltar também 🎉
| return module_name[module_name.find(self.root):] | ||
|
|
||
| def __get_root_parts(self, path): | ||
| def get_root_parts(path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depois me explica isso aqui? haha 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hahaha
Esse método serve para buscar o root package ou man package para fazer o import corretamente, pois nesse momento só tem o caminho absoluto do arquivo, como: /app/app/infra/event_bus/subscribes
O nome do módulo para funcionar deve ser: app.infra.event_bus.subscribes..., saka?
O que essa função faz é subir os niveis enquanto achar o __init__.py entre eles. Quando não achar significa que chegou no root da aplicação.
Esse root serve de aux para normalizar o nome do módulo, pois como disse, só tem o caminho absoluto dos arquivos e vem algo como já mencionei.
O normalize exclui tudo que vem antes do man package e aí o import fica limpo, como: app.infra.event_bus.subscribes.operations
Saka?
Isso foi feito para ser genérico, pois podemos chamar o autodiscover em qualquer lugar, como por exemplo em app.api para buscar as views. 🤔
No description provided.