Skip to content

Commit ecae7cc

Browse files
authored
PYSCAN-20: Transfer py-sonar-scanner to the official sonar repository
2 parents 70c0846 + 4522fca commit ecae7cc

File tree

12 files changed

+703
-0
lines changed

12 files changed

+703
-0
lines changed

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: sonar-release
2+
# This workflow is triggered when publishing a new github release
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
pypi-publish:
10+
name: Upload release to TestPyPI
11+
runs-on: ubuntu-latest
12+
environment:
13+
name: pypi
14+
permissions:
15+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
16+
contents: read
17+
steps:
18+
# retrieve your distributions here
19+
- uses: actions/checkout@v3
20+
- name: Set up Python
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: '3.x'
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install build
28+
- name: Build package
29+
run: python -m build
30+
- name: Publish package distributions to TestPyPI
31+
uses: pypa/gh-action-pypi-publish@release/v1
32+
with:
33+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
34+
repository-url: https://test.pypi.org/legacy/

.gitignore

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
.python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
.idea/
161+
162+
163+
# Sonar
164+
*.scanner
165+
*.scannerwork

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
11
# sonar-scanner-python
22
A wrapper around SonarScanner CLI, available on PyPI.
3+
4+
# Installation
5+
## Prerequisites
6+
7+
- Python 3.12
8+
- [Hatch](https://hatch.pypa.io/latest/install/)
9+
10+
## Install virtual env and create a new environment
11+
12+
Run `python3 -m pip install --user virtualenv`
13+
14+
Then create a new env with `python3 -m venv <name of your venv>`
15+
16+
Activate the venv with `source <name of your venv>/bin/activate`
17+
18+
# Run the main script
19+
20+
Run `python3 main.py <args>`
21+
22+
# Run the tests
23+
24+
Run `hatch run test:test`
25+
26+
27+
# Publish the script
28+
29+
Make sure to have the latest version of PyPA with `python3 -m pip install --upgrade build`
30+
31+
Run `python3 -m build` to create the binaries
32+
33+
Run if needed `python3 -python3 -m pip install --upgrade twine` to upgrade to the latest version of twine
34+
35+
Run `python3 -m twine upload --repository testpypi dist/*`
36+
37+
`--repository testpypi` can be removed to push to the prod PyPI instance.
38+
Also `dist/*` can be a bit more precise to upload a specific version of the binaries
39+
40+
## Before push
41+
42+
Please check if all files have a license header.
43+
If not all files have a license header please execute: `hatch run tool:license`.
44+
45+
## License
46+
47+
Copyright 2011-2023 SonarSource.
48+
49+
Licensed under the [GNU Lesser General Public License, Version 3.0](http://www.gnu.org/licenses/lgpl.txt)

license_header.tmpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
${projectname}
2+
Copyright (C) ${years} ${owner}.
3+
mailto:info AT sonarsource DOT com
4+
5+
This program is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 3 of the License, or (at your option) any later version.
9+
This program is distributed in the hope that it will be useful,
10+
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License
16+
along with this program; if not, write to the Free Software Foundation,
17+
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

pyproject.toml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "py-sonar-scanner_DAVID_K"
7+
dynamic = ["version"]
8+
authors = [
9+
{ name="Guillaume Dequenne", email="[email protected]" },
10+
{ name="Maksim Grebeniuk", email="[email protected]" },
11+
{ name="David Kunzmann", email="[email protected]" },
12+
]
13+
description = "Sonar Scanner for the Python Ecosystem"
14+
readme = "README.md"
15+
license = {file = "LICENSE"}
16+
requires-python = ">=3.12"
17+
classifiers = [
18+
"Programming Language :: Python :: 3",
19+
"Operating System :: OS Independent",
20+
]
21+
22+
dependencies = [
23+
"toml>=0.10.2",
24+
]
25+
26+
[project.urls]
27+
"Homepage" = "https://github.com/joke1196/py-sonar-scanner"
28+
"Bug Tracker" = "https://github.com/joke1196/py-sonar-scanner/issues"
29+
30+
[project.scripts]
31+
"py-sonar-scanner" = "py_sonar_scanner.__main__:scan"
32+
33+
[tool.hatch.envs.default]
34+
python="3.12"
35+
36+
[tool.hatch.version]
37+
path = "src/py_sonar_scanner/__about__.py"
38+
39+
[tool.hatch.build.targets.wheel]
40+
only-include = ["src/py_sonar_scanner"]
41+
sources = ["src"]
42+
43+
[tool.hatch.envs.test]
44+
dependencies = [
45+
"coverage[toml]",
46+
"pytest",
47+
"pytest-cov",
48+
"pytest-mock",
49+
]
50+
51+
[tool.hatch.envs.test.scripts]
52+
test = "pytest tests/"
53+
cov = 'pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=tests'
54+
55+
[[tool.hatch.envs.test.matrix]]
56+
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
57+
58+
[tool.hatch.envs.tool]
59+
dependencies = [
60+
"licenseheaders",
61+
"black"
62+
]
63+
64+
[tool.hatch.envs.tool.scripts]
65+
license = 'python -m licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2023 -n "Sonar Scanner Python" -E .py'
66+
format = 'python -m black src/ tests/ --check'
67+
68+
[tool.black]
69+
line-length = 89
70+
target-version = ["py38", "py39", "py310", "py311", "py312"]

src/py_sonar_scanner/__about__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Sonar Scanner Python
3+
# Copyright (C) 2011-2023 SonarSource SA.
4+
# mailto:info AT sonarsource DOT com
5+
#
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 3 of the License, or (at your option) any later version.
10+
# This program is distributed in the hope that it will be useful,
11+
#
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with this program; if not, write to the Free Software Foundation,
18+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
#
20+
__version__ = "0.0.6"
21+
__author__ = "Python Squad"

src/py_sonar_scanner/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Sonar Scanner Python
3+
# Copyright (C) 2011-2023 SonarSource SA.
4+
# mailto:info AT sonarsource DOT com
5+
#
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU Lesser General Public
8+
# License as published by the Free Software Foundation; either
9+
# version 3 of the License, or (at your option) any later version.
10+
# This program is distributed in the hope that it will be useful,
11+
#
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
# Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with this program; if not, write to the Free Software Foundation,
18+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
#

0 commit comments

Comments
 (0)