Skip to content

Commit 53cce23

Browse files
authored
fix: [OSM-855] fixed python 3.12 support (#229)
1 parent 517a2d4 commit 53cce23

File tree

18 files changed

+3637
-100
lines changed

18 files changed

+3637
-100
lines changed

.circleci/config.yml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,43 @@ jobs:
3030
steps:
3131
- checkout
3232
- setup_remote_docker
33-
- run:
34-
name: Run tests
35-
command: |
36-
BUILDKIT_PROGRESS=plain \
37-
DOCKER_BUILDKIT=1 \
38-
docker build \
39-
--build-arg NODE_VERSION=<< parameters.node_version >> \
40-
--build-arg PYTHON_VERSION=<< parameters.python_version >> \
41-
-t snyk-python-plugin:integration-tests-<< parameters.python_version >> \
42-
-f test/Dockerfile .
43-
docker run --rm snyk-python-plugin:integration-tests-<< parameters.python_version >>
33+
- when:
34+
condition:
35+
equal: [ "3.12", <<parameters.python_version>>]
36+
steps:
37+
- run:
38+
name: Run tests
39+
command: |
40+
BUILDKIT_PROGRESS=plain \
41+
DOCKER_BUILDKIT=1 \
42+
docker build \
43+
--build-arg NODE_VERSION=<< parameters.node_version >> \
44+
--build-arg PYTHON_VERSION=<< parameters.python_version >> \
45+
--build-arg PY_TEST_CMD=test:pysrc3_12 \
46+
-t snyk-python-plugin:integration-tests-<< parameters.python_version >> \
47+
-f test/Dockerfile .
48+
docker run --rm snyk-python-plugin:integration-tests-<< parameters.python_version >>
49+
- when:
50+
condition:
51+
or:
52+
- equal: [ "3.8", <<parameters.python_version>>]
53+
- equal: [ "3.9", <<parameters.python_version>>]
54+
- equal: [ "3.10", <<parameters.python_version>>]
55+
- equal: [ "3.11", <<parameters.python_version>>]
56+
steps:
57+
- run:
58+
name: Run tests
59+
command: |
60+
BUILDKIT_PROGRESS=plain \
61+
DOCKER_BUILDKIT=1 \
62+
docker build \
63+
--build-arg NODE_VERSION=<< parameters.node_version >> \
64+
--build-arg PYTHON_VERSION=<< parameters.python_version >> \
65+
--build-arg PY_TEST_CMD=test:pysrc3 \
66+
-t snyk-python-plugin:integration-tests-<< parameters.python_version >> \
67+
-f test/Dockerfile .
68+
docker run --rm snyk-python-plugin:integration-tests-<< parameters.python_version >>
69+
4470
4571
build:
4672
<<: *defaults
@@ -108,6 +134,7 @@ workflows:
108134
'3.9',
109135
'3.10',
110136
'3.11',
137+
'3.12',
111138
]
112139
filters:
113140
branches:

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ Snyk helps you find, fix and monitor for known vulnerabilities in your dependenc
3131

3232
## Supported Pip & Python versions (requirements.txt)
3333

34-
| Pip / Python |2.7|3.6|3.7|3.8|3.9|
35-
|----------------|---|---|---|---|---|
36-
| 10.0.0 ||||||
37-
| 18.1.0 ||||||
34+
| Pip / Python |2.7|3.6|3.7|3.8|3.9|3.10|3.11|3.12|
35+
|----------------|---|---|---|---|---|---|---|---|
36+
| 10.0.0 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅
37+
| 18.1.0 |||||||||
3838

3939
## Supported Poetry versions (`pyproject.toml` and `poetry.lock`)
4040
All known versions are expected to be supported (current latest version is 1.1.6)

dev-requirements.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
pipenv==2022.4.8; python_version >= '3.6'
1+
pipenv==2022.4.8; python_version == '3.8'
2+
pipenv==2022.4.8; python_version == '3.9'
3+
pipenv==2022.4.8; python_version == '3.10'
4+
pipenv==2022.4.8; python_version == '3.11'
5+
pipenv==2023.11.15; python_version == '3.12'
26
pipenv==2018.11.26; python_version == '2.7'
3-
virtualenv==20.15.1; python_version >= '3.6'
7+
virtualenv==20.15.1; python_version == '3.8'
8+
virtualenv==20.15.1; python_version == '3.9'
9+
virtualenv==20.15.1; python_version == '3.10'
10+
virtualenv==20.15.1; python_version == '3.11'
11+
virtualenv==20.25.0; python_version == '3.12'
412
virtualenv==16.2.0; python_version == '2.7'
513
mock

lib/dependencies/inspect-implementation.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { buildDepGraph, PartialDepTree } from './build-dep-graph';
88
import { FILENAMES } from '../types';
99
import { EmptyManifestError, RequiredPackagesMissingError } from '../errors';
1010

11+
const PYTHON_3_12_REGEX = new RegExp('^Python 3.12.*');
12+
const UPDATED_SETUPTOOLS_VERSION = '68.0.0';
13+
1114
const returnedTargetFile = (originalTargetFile) => {
1215
const basename = path.basename(originalTargetFile);
1316

@@ -163,6 +166,8 @@ function createAssets() {
163166
path.join(__dirname, '../../pysrc/pkg_resources_py3/_vendor/pyparsing.py'),
164167
path.join(__dirname, '../../pysrc/pkg_resources_py3/__init__.py'),
165168
path.join(__dirname, '../../pysrc/pkg_resources_py3/extern/__init__.py'),
169+
170+
path.join(__dirname, '../../pysrc/pkg_resources_py3_12/__init__.py'),
166171
];
167172
}
168173

@@ -203,6 +208,30 @@ function dumpAllFilesInTempDir(tempDirName: string) {
203208
});
204209
}
205210

211+
async function updateSetuptools(
212+
setuptoolsVersion: string,
213+
dir: string,
214+
pythonEnv
215+
) {
216+
// For python 3.12, setuptools needs to be updated
217+
// due to removal of some deprecated packages
218+
// see: https://github.com/pypa/pip/pull/11997
219+
220+
const pythonVersion = await subProcess.execute(`python`, ['--version'], {
221+
cwd: dir,
222+
env: pythonEnv,
223+
});
224+
225+
if (!PYTHON_3_12_REGEX.test(pythonVersion)) {
226+
return;
227+
}
228+
229+
await subProcess.execute(`pip install setuptools==${setuptoolsVersion}`, [], {
230+
cwd: dir,
231+
env: pythonEnv,
232+
});
233+
}
234+
206235
export async function inspectInstalledDeps(
207236
command: string,
208237
baseargs: string[],
@@ -221,6 +250,9 @@ export async function inspectInstalledDeps(
221250
dumpAllFilesInTempDir(tempDirObj.name);
222251
try {
223252
const pythonEnv = getPythonEnv(targetFile);
253+
254+
await updateSetuptools(UPDATED_SETUPTOOLS_VERSION, root, pythonEnv);
255+
224256
// See ../../pysrc/README.md
225257
const output = await subProcess.execute(
226258
command,

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
"format:check": "prettier --check '{lib,test}/**/*.{js,ts}'",
1515
"format": "prettier --write '{lib,test}/**/*.{js,ts}'",
1616
"prepare": "npm run build",
17-
"test": "npm run test:pysrc && npm run test:jest",
17+
"test": "npm run test:jest",
1818
"test:jest": "jest",
19-
"test:pysrc": "python -m unittest discover pysrc",
19+
"test:pysrc2": "cd pysrc; python -m unittest test_pip_resolve_py2 test_pipfile",
20+
"test:pysrc3": "cd pysrc; python -m unittest test_pip_resolve_py3 test_pipfile",
21+
"test:pysrc3_12": "cd pysrc; python -m unittest test_pip_resolve_py3_12 test_pipfile",
2022
"lint": "npm run build-tests && npm run format:check && eslint --cache '{lib,test}/**/*.{js,ts}'"
2123
},
2224
"author": "snyk.io",

pysrc/pkg_resources.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import sys
22

33
if sys.version_info >= (3, 0):
4-
from pkg_resources_py3 import *
4+
if sys.version_info.minor >= 12:
5+
from pkg_resources_py3_12 import *
6+
else:
7+
from pkg_resources_py3 import *
58
else:
69
from pkg_resources_py2 import *

pysrc/pkg_resources_py3_12/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright Jason R. Coombs
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to
5+
deal in the Software without restriction, including without limitation the
6+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
sell copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
IN THE SOFTWARE.

0 commit comments

Comments
 (0)