Skip to content

Commit 040ef7e

Browse files
SCANPY-138 Support python custom analyzer properties (#169)
1 parent 224a318 commit 040ef7e

3 files changed

Lines changed: 116 additions & 11 deletions

File tree

src/pysonar_scanner/configuration/cli.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,5 +395,48 @@ def __parse_cli_args(cls) -> argparse.Namespace:
395395
type=str,
396396
help="Python version used for the project",
397397
)
398+
parser.add_argument(
399+
"--sonar-python-pylint-report-path",
400+
"-Dsonar.python.pylint.reportPath",
401+
type=str,
402+
help="Path to third-parties issues report file for pylint",
403+
)
404+
parser.add_argument(
405+
"--sonar-python-coverage-report-paths",
406+
"-Dsonar.python.coverage.reportPaths",
407+
type=str,
408+
help="Comma-delimited list of paths to coverage reports in the Cobertura XML format.",
409+
)
410+
parser.add_argument(
411+
"--sonar-python-skip-unchanged",
412+
type=bool,
413+
action=argparse.BooleanOptionalAction,
414+
help="Override the SonarQube configuration of skipping or not the analysis of unchanged Python files",
415+
)
416+
parser.add_argument(
417+
"-Dsonar.python.skipUnchanged",
418+
type=bool,
419+
help="Equivalent to --sonar-python-skip-unchanged",
420+
)
421+
parser.add_argument(
422+
"--sonar-python-xunit-report-path",
423+
"-Dsonar.python.xunit.reportPath",
424+
type=str,
425+
help="Path to the report of test execution, relative to project's root",
426+
)
427+
parser.add_argument(
428+
"--sonar-python-xunit-skip-details",
429+
type=bool,
430+
action=argparse.BooleanOptionalAction,
431+
help="When enabled, the test execution statistics is provided only on project level",
432+
)
433+
parser.add_argument(
434+
"-Dsonar.python.xunit.skipDetails",
435+
type=bool,
436+
help="Equivalent to -Dsonar.python.xunit.skipDetails",
437+
)
438+
parser.add_argument(
439+
"--sonar-modules", "-Dsonar.modules", type=str, help="Comma-delimited list of modules to analyze"
440+
)
398441

399442
return parser.parse_args()

src/pysonar_scanner/configuration/properties.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,18 @@
8181
SONAR_PULLREQUEST_BRANCH: Key = "sonar.pullrequest.branch"
8282
SONAR_PULLREQUEST_BASE: Key = "sonar.pullrequest.base"
8383
SONAR_PYTHON_VERSION: Key = "sonar.python.version"
84+
SONAR_PYTHON_PYLINT_REPORT_PATH: Key = "sonar.python.pylint.reportPath"
85+
SONAR_PYTHON_COVERAGE_REPORT_PATHS: Key = "sonar.python.coverage.reportPaths"
86+
SONAR_PYTHON_SKIP_UNCHANGED: Key = "sonar.python.skipUnchanged"
8487
SONAR_NEWCODE_REFERENCE_BRANCH: Key = "sonar.newCode.referenceBranch"
8588
SONAR_SCM_REVISION: Key = "sonar.scm.revision"
8689
SONAR_BUILD_STRING: Key = "sonar.buildString"
8790
SONAR_SOURCE_ENCODING: Key = "sonar.sourceEncoding"
8891
SONAR_WORKING_DIRECTORY: Key = "sonar.working.directory"
8992
SONAR_SCM_FORCE_RELOAD_ALL: Key = "sonar.scm.forceReloadAll"
90-
93+
SONAR_MODULES: Key = "sonar.modules"
94+
SONAR_PYTHON_XUNIT_REPORT_PATH = "sonar.python.xunit.reportPath"
95+
SONAR_PYTHON_XUNIT_SKIP_DETAILS = "sonar.python.xunit.skipDetails"
9196
TOML_PATH: Key = "toml-path"
9297

9398

@@ -350,19 +355,19 @@ def env_variable_name(self) -> str:
350355
cli_getter=lambda args: args.toml_path
351356
),
352357
Property(
353-
name=SONAR_PROJECT_VERSION,
354-
default_value=None,
355-
cli_getter=lambda args: args.sonar_project_version
358+
name=SONAR_PROJECT_VERSION,
359+
default_value=None,
360+
cli_getter=lambda args: args.sonar_project_version
356361
),
357362
Property(
358-
name=SONAR_PROJECT_DESCRIPTION,
359-
default_value=None,
360-
cli_getter=lambda args: args.sonar_project_description
363+
name=SONAR_PROJECT_DESCRIPTION,
364+
default_value=None,
365+
cli_getter=lambda args: args.sonar_project_description
361366
),
362367
Property(
363-
name=SONAR_PYTHON_VERSION,
364-
default_value=None,
365-
cli_getter=lambda args: args.sonar_python_version
368+
name=SONAR_PYTHON_VERSION,
369+
default_value=None,
370+
cli_getter=lambda args: args.sonar_python_version
366371
),
367372
Property(
368373
name=SONAR_QUALITYGATE_WAIT,
@@ -453,7 +458,36 @@ def env_variable_name(self) -> str:
453458
name=SONAR_SCM_FORCE_RELOAD_ALL,
454459
default_value=None,
455460
cli_getter=lambda args: args.sonar_scm_force_reload_all or getattr(args, "Dsonar.scm.forceReloadAll")
461+
),
462+
Property(
463+
name=SONAR_PYTHON_PYLINT_REPORT_PATH,
464+
default_value=None,
465+
cli_getter=lambda args: args.sonar_python_pylint_report_path
466+
),
467+
Property(
468+
name=SONAR_PYTHON_COVERAGE_REPORT_PATHS,
469+
default_value=None,
470+
cli_getter=lambda args: args.sonar_python_coverage_report_paths
471+
),
472+
Property(
473+
name=SONAR_PYTHON_SKIP_UNCHANGED,
474+
default_value=None,
475+
cli_getter=lambda args: args.sonar_python_skip_unchanged or getattr(args, "Dsonar.python.skipUnchanged")
476+
),
477+
Property(
478+
name=SONAR_PYTHON_XUNIT_REPORT_PATH,
479+
default_value=None,
480+
cli_getter=lambda args: args.sonar_python_xunit_report_path
481+
),
482+
Property(
483+
name=SONAR_PYTHON_XUNIT_SKIP_DETAILS,
484+
default_value=None,
485+
cli_getter=lambda args: args.sonar_python_xunit_skip_details or getattr(args, "Dsonar.python.xunit.skipDetails")
486+
),
487+
Property(
488+
name=SONAR_MODULES,
489+
default_value=None,
490+
cli_getter=lambda args: args.sonar_modules
456491
)
457-
458492
]
459493
# fmt: on

tests/unit/test_configuration_cli.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
SONAR_SOURCE_ENCODING,
8181
SONAR_WORKING_DIRECTORY,
8282
SONAR_SCM_FORCE_RELOAD_ALL,
83+
SONAR_PYTHON_PYLINT_REPORT_PATH,
84+
SONAR_PYTHON_COVERAGE_REPORT_PATHS,
85+
SONAR_PYTHON_SKIP_UNCHANGED,
86+
SONAR_PYTHON_XUNIT_REPORT_PATH,
87+
SONAR_PYTHON_XUNIT_SKIP_DETAILS,
88+
SONAR_MODULES,
8389
)
8490

8591
EXPECTED_CONFIGURATION = {
@@ -139,6 +145,12 @@
139145
SONAR_SOURCE_ENCODING: "UTF-8",
140146
SONAR_WORKING_DIRECTORY: "/tmp/sonar",
141147
SONAR_SCM_FORCE_RELOAD_ALL: True,
148+
SONAR_PYTHON_PYLINT_REPORT_PATH: "path/to/pylint/report",
149+
SONAR_PYTHON_COVERAGE_REPORT_PATHS: "path/to/coverage1,path/to/coverage2",
150+
SONAR_PYTHON_SKIP_UNCHANGED: True,
151+
SONAR_PYTHON_XUNIT_REPORT_PATH: "path/to/xunit/report",
152+
SONAR_PYTHON_XUNIT_SKIP_DETAILS: True,
153+
SONAR_MODULES: "module1,module2",
142154
}
143155

144156

@@ -307,6 +319,16 @@ def test_impossible_os_choice(self):
307319
"--sonar-working-directory",
308320
"/tmp/sonar",
309321
"--sonar-scm-force-reload-all",
322+
"--sonar-python-pylint-report-path",
323+
"path/to/pylint/report",
324+
"--sonar-python-coverage-report-paths",
325+
"path/to/coverage1,path/to/coverage2",
326+
"--sonar-python-skip-unchanged",
327+
"--sonar-python-xunit-report-path",
328+
"path/to/xunit/report",
329+
"--sonar-python-xunit-skip-details",
330+
"--sonar-modules",
331+
"module1,module2",
310332
],
311333
)
312334
def test_all_cli_args(self):
@@ -373,6 +395,12 @@ def test_all_cli_args(self):
373395
"-Dsonar.working.directory=/tmp/sonar",
374396
"-Dsonar.scm.forceReloadAll=true",
375397
"-Dsonar.log.level=INFO",
398+
"-Dsonar.python.pylint.reportPath=path/to/pylint/report",
399+
"-Dsonar.python.coverage.reportPaths=path/to/coverage1,path/to/coverage2",
400+
"-Dsonar.python.skipUnchanged=true",
401+
"-Dsonar.python.xunit.reportPath=path/to/xunit/report",
402+
"-Dsonar.python.xunit.skipDetails=true",
403+
"-Dsonar.modules=module1,module2",
376404
],
377405
)
378406
def test_jvm_style_cli_args(self):

0 commit comments

Comments
 (0)