Skip to content

Commit 3cc47ec

Browse files
committed
fix: Bump Python runtime and fix runtime upgrades OD-969
Python 3.11.17 drops eMudhra roots; versioned Python/Go dirs and venv rebuilds make bumps take effect on existing installs. CI uses a project token, refreshes drifted trivy/PMD fixtures and compares self-closing PMD rules on Unix.
1 parent d0c48cd commit 3cc47ec

23 files changed

Lines changed: 437 additions & 202 deletions

File tree

‎.codacy/codacy.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ runtimes:
22
- go@1.26.10
33
- java@17.0.10
44
- node@22.23.4
5-
- python@3.11.11
5+
- python@3.11.17
66
tools:
77
- eslint@9.38.0
88
- lizard@1.17.31

‎.github/workflows/it-test.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ jobs:
7474
exit $LASTEXITCODE
7575
}
7676
env:
77-
CODACY_API_TOKEN: ${{ secrets.CODACY_API_TOKEN }}
77+
CODACY_CLI_TEST_PROJECT_TOKEN: ${{ secrets.CODACY_CLI_TEST_PROJECT_TOKEN }}
7878

7979
- name: Run init tests on Unix
8080
if: matrix.os != 'windows-latest'
8181
id: run_init_tests_unix
8282
continue-on-error: true
8383
shell: bash
8484
env:
85-
CODACY_API_TOKEN: ${{ secrets.CODACY_API_TOKEN }}
85+
CODACY_CLI_TEST_PROJECT_TOKEN: ${{ secrets.CODACY_CLI_TEST_PROJECT_TOKEN }}
8686
run: |
8787
chmod +x integration-tests/run.sh
8888
./integration-tests/run.sh

‎cmd/init_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestConfigFileTemplate(t *testing.T) {
2323
tools: []domain.Tool{},
2424
expected: []string{
2525
"node@22.23.4",
26-
"python@3.11.11",
26+
"python@3.11.17",
2727
"eslint@8.57.0",
2828
"trivy@0.69.3",
2929
"pylint@3.3.6",
@@ -45,7 +45,7 @@ func TestConfigFileTemplate(t *testing.T) {
4545
"eslint@9.4.0",
4646
},
4747
notExpected: []string{
48-
"python@3.11.11",
48+
"python@3.11.17",
4949
"pylint",
5050
"pmd",
5151
"trivy",
@@ -61,7 +61,7 @@ func TestConfigFileTemplate(t *testing.T) {
6161
},
6262
},
6363
expected: []string{
64-
"python@3.11.11",
64+
"python@3.11.17",
6565
"pylint@3.4.0",
6666
},
6767
notExpected: []string{
@@ -91,7 +91,7 @@ func TestConfigFileTemplate(t *testing.T) {
9191
"trivy@0.60.0",
9292
},
9393
notExpected: []string{
94-
"python@3.11.11",
94+
"python@3.11.17",
9595
"pylint",
9696
"pmd",
9797
},
@@ -122,7 +122,7 @@ func TestConfigFileTemplate(t *testing.T) {
122122
},
123123
expected: []string{
124124
"node@22.23.4",
125-
"python@3.11.11",
125+
"python@3.11.17",
126126
"eslint@9.4.0",
127127
"trivy@0.60.0",
128128
"pylint@3.4.0",

‎config/config.go‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ func (c *ConfigType) IsRuntimeInstalled(name string, runtime *plugins.RuntimeInf
399399

400400
// IsToolInstalled checks if a tool is already installed
401401
func (c *ConfigType) IsToolInstalled(name string, tool *plugins.ToolInfo) bool {
402+
if tool.Runtime == "python" {
403+
if runtimeInfo, ok := c.Runtimes()["python"]; ok && !venvUsesRuntime(tool, runtimeInfo) {
404+
return false
405+
}
406+
}
407+
402408
// If there are no binaries, check the install directory
403409
if len(tool.Binaries) == 0 {
404410
_, err := os.Stat(tool.InstallDir)
@@ -427,6 +433,21 @@ func (c *ConfigType) IsToolInstalled(name string, tool *plugins.ToolInfo) bool {
427433
return false
428434
}
429435

436+
// venvUsesRuntime is false when the venv was built on another runtime, so a Python bump rebuilds it.
437+
func venvUsesRuntime(toolInfo *plugins.ToolInfo, runtimeInfo *plugins.RuntimeInfo) bool {
438+
cfg, err := os.ReadFile(filepath.Join(toolInfo.InstallDir, "venv", "pyvenv.cfg"))
439+
if err != nil {
440+
return false
441+
}
442+
runtimeBin := filepath.Dir(runtimeInfo.Binaries["python3"])
443+
for _, line := range strings.Split(string(cfg), "\n") {
444+
if key, value, ok := strings.Cut(line, "="); ok && strings.TrimSpace(key) == "home" {
445+
return filepath.Clean(strings.TrimSpace(value)) == filepath.Clean(runtimeBin)
446+
}
447+
}
448+
return false
449+
}
450+
430451
// Global singleton config-file
431452
var Config = ConfigType{}
432453

‎config/runtimes-installer.go‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,25 @@ func downloadAndExtractRuntime(runtimeInfo *plugins.RuntimeInfo) error {
118118
}
119119
defer file.Close()
120120

121+
extractDir := filepath.Dir(runtimeInfo.InstallDir)
122+
if err := os.MkdirAll(extractDir, constants.DefaultDirPerms); err != nil {
123+
return fmt.Errorf("failed to create extract directory: %w", err)
124+
}
125+
121126
// Extract based on file extension
122127
logger.Debug("Extracting runtime", logrus.Fields{
123128
"runtime": runtimeInfo.Name,
124129
"version": runtimeInfo.Version,
125130
"fileName": fileName,
126-
"extractDirectory": runtimesDir,
131+
"extractDirectory": extractDir,
127132
})
128133

129134
if strings.HasSuffix(fileName, ".zip") {
130-
err = utils.ExtractZip(file.Name(), runtimesDir)
135+
err = utils.ExtractZip(file.Name(), extractDir)
131136
} else if strings.HasSuffix(fileName, ".tar.xz") || strings.HasSuffix(fileName, ".txz") {
132-
err = utils.ExtractTarXz(file, runtimesDir)
137+
err = utils.ExtractTarXz(file, extractDir)
133138
} else {
134-
err = utils.ExtractTarGz(file, runtimesDir)
139+
err = utils.ExtractTarGz(file, extractDir)
135140
}
136141
if err != nil {
137142
return fmt.Errorf("failed to extract runtime: %w", err)

‎config/tools-installer.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func installPythonTool(name string, toolInfo *plugins.ToolInfo) error {
417417
"venvDir": filepath.Join(toolInfo.InstallDir, "venv"),
418418
})
419419

420-
cmd := exec.Command(pythonBinary, "-m", "venv", filepath.Join(toolInfo.InstallDir, "venv"))
420+
cmd := exec.Command(pythonBinary, "-m", "venv", "--clear", filepath.Join(toolInfo.InstallDir, "venv"))
421421
output, err := cmd.CombinedOutput()
422422
if err != nil {
423423
return fmt.Errorf("failed to create venv: %s\nError: %w", string(output), err)

‎config/tools-installer_test.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,18 @@ func TestAddDownloadBasedTool(t *testing.T) {
145145
expectedBinaryPath := filepath.Join(expectedInstallDir, "trivy")
146146
assert.Equal(t, expectedBinaryPath, trivyInfo.Binaries["trivy"])
147147
}
148+
149+
func TestVenvUsesRuntime(t *testing.T) {
150+
toolDir := t.TempDir()
151+
assert.NoError(t, os.MkdirAll(filepath.Join(toolDir, "venv"), 0755))
152+
cfg := "home = /runtimes/cpython-3.11.11/python/bin\nversion = 3.11.11\n"
153+
assert.NoError(t, os.WriteFile(filepath.Join(toolDir, "venv", "pyvenv.cfg"), []byte(cfg), 0644))
154+
tool := &plugins.ToolInfo{InstallDir: toolDir}
155+
156+
same := &plugins.RuntimeInfo{Binaries: map[string]string{"python3": "/runtimes/cpython-3.11.11/python/bin/python3"}}
157+
bumped := &plugins.RuntimeInfo{Binaries: map[string]string{"python3": "/runtimes/cpython-3.11.17/python/bin/python3"}}
158+
159+
assert.True(t, venvUsesRuntime(tool, same))
160+
assert.False(t, venvUsesRuntime(tool, bumped))
161+
assert.False(t, venvUsesRuntime(&plugins.ToolInfo{InstallDir: t.TempDir()}, same))
162+
}

‎integration-tests/config-discover/expected/codacy.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ runtimes:
22
- dart@3.7.2
33
- java@17.0.10
44
- node@22.23.4
5-
- python@3.11.11
5+
- python@3.11.17
66
tools:
77
- dartanalyzer@3.7.2
88
- eslint@8.57.0

‎integration-tests/config-discover/expected/tools-configs/ruleset.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
<rule ref="category/java/errorprone.xml/AvoidInstanceofChecksInCatchClause"/>
9090
<rule ref="category/java/errorprone.xml/AvoidMultipleUnaryOperators"/>
9191
<rule ref="category/java/errorprone.xml/BrokenNullCheck"/>
92-
<rule ref="category/java/errorprone.xml/CheckSkipResult"/>
9392
<rule ref="category/java/errorprone.xml/CompareObjectsWithEquals">
9493
<properties>
9594
<property name="typesThatCompareByReference" value="java.lang.Enum,java.lang.Class"/>

‎integration-tests/init-with-token/expected/codacy.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
runtimes:
22
- java@17.0.10
33
- node@22.23.4
4-
- python@3.11.11
4+
- python@3.11.17
55
tools:
66
- eslint@8.57.0
77
- lizard@1.22.2

0 commit comments

Comments
 (0)