Skip to content

[BUG] Avoid exception on missing profile #734

@sbrunner

Description

@sbrunner

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Call prospector the following way, 'prospector --profile=dont_exists.yaml`
  2. See error:
Traceback (most recent call last):
  File "/home/sbrunner/.pyenv/versions/3.11.9/bin/prospector", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/run.py", line 197, in main
    config = ProspectorConfig()
             ^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/config/__init__.py", line 41, in __init__
    self.profile, self.strictness = self._get_profile(self.workdir, self.config)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/config/__init__.py", line 198, in _get_profile
    profile = ProspectorProfile.load(profile_name, profile_path, forced_inherits=forced_inherits)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/profiles/profile.py", line 109, in load
    data, inherits = _load_and_merge(
                     ^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/profiles/profile.py", line 352, in _load_and_merge
    data, inherit_list, shorthands_found = _load_profile(
                                           ^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/profiles/profile.py", line 441, in _load_profile
    base_contents = _load_content(name_or_path, profile_path)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/profiles/profile.py", line 174, in _load_content
    result = _load_content_package(str(name_or_path))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/profiles/profile.py", line 136, in _load_content_package
    data = pkgutil.get_data(module_name, file_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/.pyenv/versions/3.11.9/lib/python3.11/pkgutil.py", line 622, in get_data
    spec = importlib.util.find_spec(package)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib.util>", line 95, in find_spec
ModuleNotFoundError: No module named 'prospector_profile_dont_exists'

or:

  1. Call pip install prospector-profile-utils
  2. Call prospector the following way, 'prospector --profile=utils:dont_exists`
  3. See error:
Traceback (most recent call last):
  File "/home/sbrunner/.pyenv/versions/3.11.9/bin/prospector", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/run.py", line 197, in main
    config = ProspectorConfig()
             ^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/config/__init__.py", line 41, in __init__
    self.profile, self.strictness = self._get_profile(self.workdir, self.config)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/config/__init__.py", line 198, in _get_profile
    profile = ProspectorProfile.load(profile_name, profile_path, forced_inherits=forced_inherits)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/profiles/profile.py", line 109, in load
    data, inherits = _load_and_merge(
                     ^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/profiles/profile.py", line 355, in _load_and_merge
    data, inherit_list, shorthands_found = _load_profile(
                                           ^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/profiles/profile.py", line 444, in _load_profile
    base_contents = _load_content(name_or_path, profile_path)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/profiles/profile.py", line 177, in _load_content
    result = _load_content_package(str(name_or_path))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/workspace/prospector/prospector/profiles/profile.py", line 137, in _load_content_package
    data = pkgutil.get_data(module_name, file_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sbrunner/.pyenv/versions/3.11.9/lib/python3.11/pkgutil.py", line 640, in get_data
    return loader.get_data(resource_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap_external>", line 1130, in get_data
FileNotFoundError: [Errno 2] No such file or directory: '/home/sbrunner/workspace/prospector-profile-utils/prospector_profile_utils/dont_exists.yaml'

Expected behavior A clear and concise description of what you expected to happen.

Get a nice error

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions