File tree Expand file tree Collapse file tree 3 files changed +16
-6
lines changed
Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 1- __version__ = "0.3.0 "
1+ __version__ = "0.3.1 "
22
33from .app import App as App
44from .fastapi import FastAPIDependency as FastAPIDependency
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import inspect
4+ import logging
45from collections .abc import Callable
56from dataclasses import dataclass , field
67from importlib import import_module
@@ -137,7 +138,13 @@ def import_module(
137138
138139 # Support applications that are not wrapped in a Python package.
139140 # In that case `self.package_name` is ".".
140- module = import_module (name if self .package_name == "." else f"{ self .package_name } .{ name } " )
141+ import_name = name if self .package_name == "." else f"{ self .package_name } .{ name } "
142+ try :
143+ module = import_module (import_name )
144+ except Exception :
145+ # Handle potential misconfigurations with a simple warning, instead of an exception.
146+ logging .getLogger ("holm" ).warning (f"Failed to import module { name } at: { import_name } " )
147+ return None
141148
142149 if not validate (module ):
143150 raise ValueError (f"Invalid module: { name } " )
Original file line number Diff line number Diff line change @@ -137,18 +137,21 @@ def _discover_app_packages(config: AppConfig) -> set[PackageInfo]:
137137 @lru_cache ()
138138 def is_excluded (path : Path ) -> bool :
139139 """Returns whether the given file or package path should be excluded from the application."""
140- rel_path = path .relative_to (config .root_dir )
141140 return any (
142141 # Exclude if a path segment starts with an underscore but does not end with one.
143142 # Path segments that both start and end with an underscore represent path parameters!
144- p .startswith ("_" ) and not p .endswith ("_" )
145- for p in rel_path .parts
143+ (p .startswith ("_" ) and not p .endswith ("_" ))
144+ # Also exclude paths that start with a dot (virtual env, git, etc.)
145+ or p .startswith ("." )
146+ for p in path .parts
146147 )
147148
148149 return {
149150 PackageInfo .from_marker_file (f , config = config )
150151 for f in config .app_dir .rglob ("*.py" )
151- if f .stem in module_names and not is_excluded (f .parent ) # Pass the parent to make use of caching
152+ if f .stem in module_names
153+ # Pass the relative path of the parent to make the best use of caching
154+ and not is_excluded (f .parent .relative_to (config .root_dir ))
152155 }
153156
154157
You can’t perform that action at this time.
0 commit comments