def run(self): if self.config.print_config: self.print_config() if self.config.print_plugin: self.print_plugin() if self.config.print_service: self.print_service() server_config = asdict(self.config, keys=fields(ServerConfig)) run(self, **server_config)
def load_env_config() -> EnvConfig: envfile_path = os.getenv('RSSANT_CONFIG') if envfile_path: envfile_path = os.path.abspath(os.path.expanduser(envfile_path)) print(f'* Load envfile at {envfile_path}') load_dotenv(envfile_path) configs = {} for name in fields(EnvConfig): key = ('RSSANT_' + name).upper() configs[name] = os.environ.get(key, None) return EnvConfig(configs)
def to_common(story: Story) -> CommonStory: d = {} for key in fields(CommonStory): value = story.__dict__.get(key, None) if value is not None: d[key] = value content = d.get('content', None) if content: d['content_length'] = len(content) d['dt_created'] = story.dt_created d['feed_id'] = story.feed_id d['offset'] = story.offset return CommonStory(d)
def to_common(story: Story) -> CommonStory: d = {} for key in fields(CommonStory): value = story.__dict__.get(key, None) if value is not None: d[key] = value content = d.get('content', None) if content: d['content_length'] = len(content) d['dt_created'] = story.dt_created d['feed_id'] = story.feed_id d['offset'] = story.offset # some very old data may not have unique_id if not d.get('unique_id'): d['unique_id'] = d.get('link') or f'{story.feed_id}-{story.offset}' return CommonStory(d)
def _active_plugins(self): self.contexts = [] self.decorators = [] self.provides = {f'config.{key}' for key in fields(self.config)} for plugin in self.plugins: plugin.active(self) if hasattr(plugin, 'context'): self.contexts.append(plugin.context) if hasattr(plugin, 'decorator'): self.decorators.append(plugin.decorator) if hasattr(plugin, 'provides'): self.provides.update(plugin.provides) for plugin in self.plugins: if not hasattr(plugin, 'requires'): continue requires = set(plugin.requires) missing = ', '.join(requires - self.provides) if missing: msg = f'the requires {missing} of plugin {plugin} is missing' raise DependencyError(msg)
def test_fields(): assert fields(User) == {"id", "name"} user = User(id=123, name="test") assert fields(user) == {"id", "name"}