Skip to content

Commit cc162af

Browse files
Seppli11sonartech
authored andcommitted
SONARPY-3706 Invert -DskipTypeshed mvn flag (#815)
GitOrigin-RevId: a9a29df1f39ff3478490238e1cdf85682be4c03e
1 parent f4b5f06 commit cc162af

7 files changed

Lines changed: 30 additions & 10 deletions

File tree

.cirrus/analyze.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ function run_maven {
33
# No need for Maven phase "install" as the generated JAR files do not need to be installed
44
# in Maven local repository. Phase "verify" is enough.
55
mvn verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
6+
-DgenerateTypeshedStubs \
67
-Pcoverage \
78
-Dmaven.test.redirectTestOutputToFile=false \
89
-Dsonar.projectName="Python" \
@@ -60,6 +61,7 @@ elif [ "$PULL_REQUEST" != "false" ]; then
6061
elif [[ "$GITHUB_BRANCH" == "dogfood-on-"* ]] && [ "$PULL_REQUEST" == "false" ]; then
6162
echo '======= Build dogfood branch'
6263
mvn verify \
64+
-DgenerateTypeshedStubs \
6365
-DfailStubGenerationFast=true \
6466
-Dskip.its=true \
6567
--batch-mode \
@@ -74,6 +76,7 @@ else
7476
# in Maven local repository. Phase "verify" is enough.
7577

7678
mvn verify \
79+
-DgenerateTypeshedStubs \
7780
-Dmaven.test.redirectTestOutputToFile=false \
7881
--batch-mode \
7982
--errors \

.github-commons/actions/analyze/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ runs:
1616
with:
1717
maven-args: >-
1818
-Dsonar.organization=sonarsource -Dsonar.projectKey=${{ inputs.sonar-project-key }}
19-
-Dsonar.analysisCache.enabled=true -Dsonar.sca.recursiveManifestSearch=true -DfailStubGenerationFast=true -Dskip.its=true
19+
-Dsonar.analysisCache.enabled=true -Dsonar.sca.recursiveManifestSearch=true -DgenerateTypeshedStubs -DfailStubGenerationFast=true -Dskip.its=true
2020
deploy: false
2121
sonar-platform: ${{ inputs.sonarqube-instance }}
2222
scanner-java-opts: '-Xmx1G'

.github/actions/build-sonar-python/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ runs:
1111
uses: SonarSource/ci-github-actions/build-maven@v1
1212
id: build
1313
with:
14-
maven-args: '-DskipTests=true -Dsonar.skip=true -P-typeshed_serializer'
14+
maven-args: '-DskipTests=true -Dsonar.skip=true'
1515
deploy-pull-request: true
1616
sonar-platform: none
1717
mixed-privacy: true

.github/instructions/rules-testing.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ applyTo: "**/*checks*/**/*.java"
44
Each rule implementation needs to be well tested.
55
To do so, we have powerful utilities in `PythonCheckVerifier` that allows for verification.
66

7-
You can run the test for a given class with the shell command `mvn verify -DskipTypeshed -DskipObfuscation -f"python-checks/pom.xml" -Dtest=$YOUR_TEST_CLASS`
7+
You can run the test for a given class with the shell command `mvn verify -DskipObfuscation -f"python-checks/pom.xml" -Dtest=$YOUR_TEST_CLASS`
88
Replace the $YOUR_TEST_CLASS by the name of the test class, usually of the form SleepZeroInAsyncCheckTest for the SleepZeroInAsyncCheck rule.
99

1010
Look carefully at the terminal output, and make sure the test was successful.

.github/instructions/tdd-planning-execution-refactoring.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void test() {
121121

122122
### Test Execution Command
123123
```bash
124-
mvn verify -DskipTypeshed -DskipObfuscation -f python-checks/pom.xml -Dtest=YourTestClass
124+
mvn verify -DskipObfuscation -f python-checks/pom.xml -Dtest=YourTestClass
125125
```
126126

127127
## Key Success Practices

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ Sonar's [integrated code quality and code security](https://www.sonarsource.com/
2020

2121
The easiest way to build the Project is by running:
2222

23-
`mvn clean install -DskipTypeshed -P-private`
23+
`mvn clean install -P-private`
2424

2525
It builds only Java Maven modules, runs tests, and installs jar locally.
26-
The Python interpreter is not required in that case.
26+
The Python interpreter is not required in that case. Typeshed stub generation is skipped by default.
2727

2828
### Full build
2929

@@ -46,10 +46,27 @@ To execute the full build just run:
4646

4747
`mvn clean install -P-private`
4848

49-
The full build executes [Typeshed](https://github.com/python/typeshed) serializer script.
50-
It generates protobuf messages for Typeshed symbols (for standard Python API) and our customs symbols
49+
The full build executes [Typeshed](https://github.com/python/typeshed) serializer script.
50+
It generates protobuf messages for Typeshed symbols (for standard Python API) and our customs symbols
5151
(for Python libraries, e.g. [AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/work-with-cdk-python.html)).
52-
This helps with type inference and providing better rules.
52+
This helps with type inference and providing better rules.
53+
54+
### Typeshed Stub Generation
55+
56+
By default, Maven builds skip typeshed stub generation for faster build times. The stubs are pre-generated and committed to the repository.
57+
58+
To regenerate typeshed stubs, use the provided Docker script:
59+
```
60+
cd python-frontend/typeshed_serializer
61+
./build-with-docker.sh
62+
```
63+
64+
Alternatively, you can generate stubs during a Maven build by adding the `-DgenerateTypeshedStubs` flag:
65+
```
66+
mvn clean install -DgenerateTypeshedStubs
67+
```
68+
69+
Note: Stub generation requires Python 3.9+ and tox to be installed.
5370

5471
## How to contribute
5572

python-frontend/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
<activation>
164164
<property>
165165
<name>
166-
!skipTypeshed
166+
generateTypeshedStubs
167167
</name>
168168
</property>
169169
</activation>

0 commit comments

Comments
 (0)