Skip to content

Commit e72fe94

Browse files
committed
PYSCAN-36: Migrate from Hatch to Poetry (#27)
1 parent 3b92b61 commit e72fe94

File tree

5 files changed

+695
-112
lines changed

5 files changed

+695
-112
lines changed

.github/workflows/build-pr.yml

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,40 @@ on:
44
push:
55
branches: [ "master" ]
66
pull_request:
7-
branches: [ "master" ]
7+
branches:
8+
- master
9+
- 'feature/**'
810

911
jobs:
10-
build:
11-
12+
test:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read # required by actions/checkout
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
pipx install poetry
29+
poetry install
30+
- name: Check tests
31+
run: |
32+
poetry run pytest tests/
33+
analysis:
1234
runs-on: ubuntu-latest
1335
permissions:
1436
id-token: write # required by SonarSource/vault-action-wrapper
1537
contents: read # required by actions/checkout
1638
pull-requests: read # required by SonarSource/sonarcloud-github-action
1739
strategy:
1840
fail-fast: false
19-
2041
steps:
2142
- name: Get vault secrets
2243
id: secrets
@@ -31,26 +52,24 @@ jobs:
3152
uses: actions/setup-python@v4
3253
with:
3354
python-version: |
34-
3.8
35-
3.9
36-
3.10
37-
3.11
3855
3.12
3956
- name: Install dependencies
4057
run: |
41-
python -m pip install --upgrade pip
42-
python -m pip install hatch
43-
- name: Check tests and generate coverage
44-
run: |
45-
hatch run test:cov_xml
46-
env:
47-
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_PASSWORD }}
58+
pipx install poetry
59+
poetry install
4860
- name: Check formatting
4961
run: |
50-
hatch run tool:format
62+
poetry run black src/ tests/ --check
5163
- name: Check licensing
5264
run: |
53-
hatch run tool:license_check
65+
poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2023 -n "Sonar Scanner Python" -E .py -d src/
66+
poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2023 -n "Sonar Scanner Python" -E .py -d tests/
67+
git diff --name-only --exit-code ./src ./tests
68+
- name: Check tests and generate coverage
69+
run: |
70+
poetry run pytest --cov-report=xml:coverage.xml --cov-config=pyproject.toml --cov=src --cov-branch tests
71+
env:
72+
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_PASSWORD }}
5473
- name: SonarCloud Scan
5574
uses: SonarSource/sonarcloud-github-action@master
5675
env:

README.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,35 @@ See the __SonarScanner__ [documentation](https://docs.sonarsource.com/sonarqube/
116116
## Prerequisites
117117

118118
- Python 3.12
119-
- [Hatch](https://hatch.pypa.io/latest/install/)
119+
- [pipx](https://github.com/pypa/pipx)
120120

121-
## Install virtual env and create a new environment
121+
## Install poetry
122122

123-
Run `python3 -m pip install --user virtualenv`
124-
125-
Then create a new env with `python3 -m venv <name of your venv>`
126-
127-
Activate the venv with `source <name of your venv>/bin/activate`
123+
Install poetry with `pipx install poetry`
128124

129125
# Run the main script
130126

131-
Run `python3 main.py <args>`
127+
Run `python src/py_sonar_scanner`
132128

133129
# Run the tests
134130

135-
Run `hatch run test:test`
131+
Run `poetry install` to install the dependencies
132+
133+
## Run the tests only
134+
135+
Run `poetry run pytest test/`
136+
137+
## Run the tests with coverage and results displayed in the terminal
138+
139+
Run `poetry run pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src --cov-branch tests`
140+
141+
## Run the tests with coverage and store the result in an xml file
142+
143+
Run `poetry run pytest --cov-report=xml:coverage.xml --cov-config=pyproject.toml --cov=src --cov-branch tests`
136144

137145
# Build the package
138146

139-
Run `hatch build` to create the package.
147+
Run `poetry build` to create the package.
140148
The binaries will be located in the `dist` directory at the root level of the project.
141149

142150
# Publish the script
@@ -153,25 +161,28 @@ Also `dist/*` can be a bit more precise to upload a specific version of the bina
153161
To update the version use the hatch command:
154162

155163
```
156-
hatch version "X.Y.Z"
164+
poetry version "X.Y.Z"
157165
```
158166
For more options on the version update see [the hatch documentation](https://hatch.pypa.io/latest/version/)
159167

160168
# Tooling
161169
## Formatting
162170

163-
Run `hatch run tool:format` to run the check the formatting on all files.
164-
To automatically apply formatting, run `hatch run tool:apply_format`.
171+
Run `poetry run black src/ tests/ --check` to run the check the formatting on all files.
172+
To automatically apply formatting, run `poetry run black src/ tests/`.
165173

166174
## Type checking
167175

168-
Run `hatch run tool:type_check` to execute the type checking on all files.
176+
Run `poetry run mypy src/ tests/ --ignore-missing-imports` to execute the type checking on all files.
169177

170178
## License header
171179

172180
Before pushing, please check if all files have a license header.
173-
If not all files have a license header please execute: `hatch run tool:license`.
174-
181+
If not all files have a license header please execute:
182+
```
183+
poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2023 -n "Sonar Scanner Python" -E .py -d src/
184+
poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2023 -n "Sonar Scanner Python" -E .py -d tests/
185+
```
175186

176187
# License
177188

0 commit comments

Comments
 (0)