Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/usethis/_core/show.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import annotations

from usethis._config import usethis_config
from usethis._console import plain_print
from usethis._init import ensure_pyproject_toml
from usethis._integrations.project.name import get_project_name
from usethis._integrations.sonarqube.config import get_sonar_project_properties

Expand All @@ -12,6 +10,4 @@ def show_name() -> None:


def show_sonarqube_config() -> None:
with usethis_config.set(quiet=True):
ensure_pyproject_toml()
plain_print(get_sonar_project_properties())
15 changes: 13 additions & 2 deletions src/usethis/_integrations/sonarqube/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,33 @@ def get_sonar_project_properties() -> str:
if path.exists() and path.is_file():
return path.read_text(encoding="utf-8")

# Get Python version
try:
python_version = _get_short_version(Path(".python-version").read_text().strip())
except (FileNotFoundError, _NonstandardPythonVersionError):
python_version = get_python_version()

# Get Project key
try:
project_key = PyprojectTOMLManager()[
["tool", "usethis", "sonarqube", "project-key"]
]
except (FileNotFoundError, KeyError):
except KeyError:
msg = "Could not find SonarQube project key at 'tool.usethis.sonarqube.project-key' in 'pyproject.toml'."
raise MissingProjectKeyError(msg) from None
except FileNotFoundError:
msg = "Could not find 'pyproject.toml' for SonarQube project key at 'tool.usethis.sonarqube.project-key'."
raise MissingProjectKeyError(msg) from None
_validate_project_key(project_key)

# Get verbosity setting
try:
verbose = PyprojectTOMLManager()[["tool", "usethis", "sonarqube", "verbose"]]
except (FileNotFoundError, KeyError):
verbose = False
verbose = TypeAdapter(bool).validate_python(verbose)

# Get exclusions
try:
exclusions = PyprojectTOMLManager()[
["tool", "usethis", "sonarqube", "exclusions"]
Expand All @@ -56,11 +63,15 @@ def get_sonar_project_properties() -> str:
for exclusion in exclusions:
TypeAdapter(str).validate_python(exclusion)

# Get coverage report output path
try:
coverage_output = PyprojectTOMLManager()[["tool", "coverage", "xml", "output"]]
except (FileNotFoundError, KeyError):
except KeyError:
msg = "XML coverage report file path not found at 'tool.coverage.xml.output' in 'pyproject.toml'."
raise CoverageReportConfigNotFoundError(msg) from None
except FileNotFoundError:
msg = "Could not find 'pyproject.toml' for coverage report file path at 'tool.coverage.xml.output'."
raise CoverageReportConfigNotFoundError(msg) from None

# No file, so construct the contents
source_dir_str = get_source_dir_str()
Expand Down