-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move `_bootstrap_components` to root node. closes #771 * unexplained `MPI.barrier` found * remove outdated manual bootstrap calls * cleaned up some more polluting test scaffolds * add package spec. closes #785 * install `exceptiongroup` * bump dep for api change * fix missing import * improved attribute hints for dict and list * fix more missing imports
- Loading branch information
Showing
12 changed files
with
193 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from exceptiongroup import ExceptionGroup | ||
|
||
from bsb.exceptions import PackageRequirementWarning | ||
from bsb.reporting import warn | ||
|
||
|
||
class MissingRequirementErrors(ExceptionGroup): | ||
pass | ||
|
||
|
||
def get_missing_requirement_reason(package): | ||
from importlib.metadata import PackageNotFoundError, version | ||
|
||
from packaging.requirements import InvalidRequirement, Requirement | ||
|
||
try: | ||
req = Requirement(package) | ||
except InvalidRequirement: | ||
return f"Can't check package requirement '{package}': invalid requirement" | ||
try: | ||
ver = version(req.name) | ||
except PackageNotFoundError: | ||
return f"Missing package '{req.name}'. You may experience errors or differences in results." | ||
else: | ||
if not ver in req.specifier: | ||
return ( | ||
f"Installed version of '{req.name}' ({ver}) " | ||
f"does not match requirements: '{req}'. You may experience errors or differences in results." | ||
) | ||
|
||
|
||
def get_missing_packages(packages): | ||
return [ | ||
package | ||
for package in packages | ||
if get_missing_requirement_reason(package) is not None | ||
] | ||
|
||
|
||
def get_unmet_package_reasons(packages): | ||
return [ | ||
reason | ||
for package in packages | ||
if (reason := get_missing_requirement_reason(package)) is not None | ||
] | ||
|
||
|
||
def warn_missing_packages(packages): | ||
for warning in get_unmet_package_reasons(packages): | ||
warn(warning, PackageRequirementWarning) | ||
|
||
|
||
def raise_missing_packages(packages): | ||
raise MissingRequirementErrors( | ||
"Your model is missing requirement(s)", | ||
[ | ||
PackageRequirementWarning(warning) | ||
for warning in get_unmet_package_reasons(packages) | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.