Skip to content

Commit fca32a6

Browse files
authored
fix: removed setuptools installation on the plugin (#246)
1 parent 710311f commit fca32a6

File tree

4 files changed

+218
-49
lines changed

4 files changed

+218
-49
lines changed

lib/dependencies/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export async function getDependencies(
2727
options = {};
2828
}
2929
let command = options.command || 'python';
30-
const pythonCmd = command;
3130
const includeDevDeps = !!(options.dev || false);
3231

3332
// handle poetry projects by parsing manifest & lockfile and return a dep-graph
@@ -52,7 +51,6 @@ export async function getDependencies(
5251
getMetaData(command, baseargs, root, targetFile),
5352
inspectInstalledDeps(
5453
command,
55-
pythonCmd,
5654
baseargs,
5755
root,
5856
targetFile,

lib/dependencies/inspect-implementation.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ 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-
1411
const returnedTargetFile = (originalTargetFile) => {
1512
const basename = path.basename(originalTargetFile);
1613

@@ -209,38 +206,8 @@ function dumpAllFilesInTempDir(tempDirName: string) {
209206
});
210207
}
211208

212-
async function updateSetuptools(
213-
setuptoolsVersion: string,
214-
dir: string,
215-
pythonEnv,
216-
command: string
217-
) {
218-
// For python 3.12, setuptools needs to be updated
219-
// due to removal of some deprecated packages
220-
// see: https://github.com/pypa/pip/pull/11997
221-
222-
const pythonVersion = await subProcess.execute(command, ['--version'], {
223-
cwd: dir,
224-
env: pythonEnv,
225-
});
226-
227-
if (!PYTHON_3_12_REGEX.test(pythonVersion)) {
228-
return;
229-
}
230-
231-
await subProcess.execute(
232-
`${command} -m pip install setuptools==${setuptoolsVersion}`,
233-
[],
234-
{
235-
cwd: dir,
236-
env: pythonEnv,
237-
}
238-
);
239-
}
240-
241209
export async function inspectInstalledDeps(
242210
command: string,
243-
pythonCmd: string,
244211
baseargs: string[],
245212
root: string,
246213
targetFile: string,
@@ -258,13 +225,6 @@ export async function inspectInstalledDeps(
258225
try {
259226
const pythonEnv = getPythonEnv(targetFile);
260227

261-
await updateSetuptools(
262-
UPDATED_SETUPTOOLS_VERSION,
263-
root,
264-
pythonEnv,
265-
pythonCmd
266-
);
267-
268228
// See ../../pysrc/README.md
269229
const output = await subProcess.execute(
270230
command,

pysrc/pip_resolve.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import utils
88
import requirements
99
import pipfile
10-
import setup_file
1110
import codecs
1211
from operator import le, lt, gt, ge, eq, ne
1312
from constants import DepsManager
@@ -135,6 +134,7 @@ def create_children_recursive(
135134
def create_dir_as_root():
136135
name, version = None, None
137136
if os.path.basename(req_file_path) == 'setup.py':
137+
import setup_file
138138
with open(req_file_path, "r") as setup_py_file:
139139
name, version = setup_file.parse_name_and_version(setup_py_file.read())
140140

@@ -231,7 +231,7 @@ def matches_python_version(requirement):
231231

232232
# Gloss over the 'and' case and return true on the first matching python version
233233

234-
for sub_exp in re.split("\s*(?:and|or)\s*", cond_text):
234+
for sub_exp in re.split(r"\s*(?:and|or)\s*", cond_text):
235235
match = PYTHON_MARKER_REGEX.search(sub_exp)
236236

237237
if match:
@@ -329,6 +329,7 @@ def get_requirements_for_setuptools(requirements_file_path):
329329
list[Requirement]: if requirements were found.
330330
empty list: if no requirements were found in the requirements file.
331331
"""
332+
import setup_file
332333
with open(requirements_file_path, 'r') as f:
333334
setup_py_file_content = f.read()
334335
requirements_data = setup_file.parse_requirements(setup_py_file_content)

test/system/inspect.spec.ts

Lines changed: 215 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,221 @@ describe('inspect', () => {
305305
compareTransitiveLines(result.dependencyGraph, expected);
306306
}
307307
);
308+
it.each([
309+
{
310+
workspace: 'pip-app',
311+
uninstallPackages: [],
312+
pluginOpts: {},
313+
expected: [
314+
{
315+
pkg: {
316+
name: 'jaraco.collections',
317+
version: '5.0.1',
318+
},
319+
directDeps: ['irc'],
320+
},
321+
{
322+
pkg: {
323+
name: 'django-appconf',
324+
version: '1.0.6',
325+
},
326+
directDeps: ['django-select2'],
327+
},
328+
],
329+
},
330+
{
331+
workspace: 'pip-app-bom',
332+
uninstallPackages: [],
333+
pluginOpts: {},
334+
expected: [
335+
{
336+
pkg: {
337+
name: 'markupsafe',
338+
version: '2.1.5',
339+
},
340+
directDeps: ['jinja2'],
341+
},
342+
],
343+
},
344+
{
345+
workspace: 'pip-app-deps-with-urls',
346+
uninstallPackages: [],
347+
pluginOpts: {},
348+
expected: [
349+
{
350+
pkg: {
351+
name: 'markupsafe',
352+
version: '2.1.5',
353+
},
354+
directDeps: ['jinja2'],
355+
},
356+
],
357+
},
358+
{
359+
workspace: 'pip-app-without-markupsafe',
360+
uninstallPackages: ['MarkupSafe'],
361+
pluginOpts: { allowMissing: true },
362+
expected: [
363+
{
364+
pkg: {
365+
name: 'markupsafe',
366+
version: '?',
367+
},
368+
directDeps: ['jinja2'],
369+
},
370+
],
371+
},
372+
{
373+
workspace: 'pip-app-deps-not-installed',
374+
uninstallPackages: [],
375+
pluginOpts: { allowMissing: true },
376+
expected: [
377+
{
378+
pkg: {
379+
name: 's3transfer',
380+
version: '0.10.2',
381+
},
382+
directDeps: ['awss'],
383+
},
384+
],
385+
},
386+
{
387+
workspace: 'pip-app-trusted-host',
388+
uninstallPackages: [],
389+
pluginOpts: {},
390+
expected: [
391+
{
392+
pkg: {
393+
name: 'markupsafe',
394+
version: '2.1.5',
395+
},
396+
directDeps: ['jinja2'],
397+
},
398+
],
399+
},
400+
{
401+
workspace: 'pip-app-deps-with-dashes',
402+
uninstallPackages: [],
403+
pluginOpts: {},
404+
expected: [
405+
{
406+
pkg: {
407+
name: 'dj-database-url',
408+
version: '0.4.2',
409+
},
410+
directDeps: ['dj-database-url'],
411+
},
412+
],
413+
},
414+
{
415+
workspace: 'pip-app-with-openapi_spec_validator',
416+
uninstallPackages: [],
417+
pluginOpts: {},
418+
expected: [
419+
{
420+
pkg: {
421+
name: 'jsonschema',
422+
version: '4.23.0',
423+
},
424+
directDeps: ['openapi-spec-validator'],
425+
},
426+
],
427+
},
428+
{
429+
workspace: 'pip-app-deps-conditional',
430+
uninstallPackages: [],
431+
pluginOpts: {},
432+
expected: [
433+
{
434+
pkg: {
435+
name: 'posix-ipc',
436+
version: '1.0.0',
437+
},
438+
directDeps: ['posix-ipc'],
439+
},
440+
],
441+
},
442+
{
443+
workspace: 'pip-app-deps-editable',
444+
uninstallPackages: [],
445+
pluginOpts: {},
446+
expected: [
447+
{
448+
pkg: {
449+
name: 'posix-ipc',
450+
version: '1.0.0',
451+
},
452+
directDeps: ['posix-ipc'],
453+
},
454+
],
455+
},
456+
{
457+
workspace: 'pip-app-deps-canonicalization',
458+
uninstallPackages: [],
459+
pluginOpts: {},
460+
expected: [
461+
{
462+
pkg: {
463+
name: 'zope.interface',
464+
version: '5.4.0',
465+
},
466+
directDeps: ['zope.interface'],
467+
},
468+
{
469+
pkg: {
470+
name: 'twisted',
471+
version: '23.10.0',
472+
},
473+
directDeps: ['twisted'],
474+
},
475+
],
476+
},
477+
{
478+
workspace: 'pip-app-optional-dependencies',
479+
uninstallPackages: [],
480+
pluginOpts: {},
481+
expected: [
482+
{
483+
pkg: {
484+
name: 'opentelemetry-distro',
485+
version: '0.35b0',
486+
},
487+
directDeps: ['opentelemetry-distro'],
488+
},
489+
],
490+
},
491+
{
492+
workspace: 'pip-app-dev-alpha-beta-python-version',
493+
uninstallPackages: [],
494+
pluginOpts: {},
495+
expected: [
496+
{
497+
pkg: {
498+
name: 'requests',
499+
version: '2.31.0',
500+
},
501+
directDeps: ['requests'],
502+
},
503+
],
504+
},
505+
])(
506+
'should get a valid dependency graph for workspace = $workspace without setuptools previously installed',
507+
async ({ workspace, uninstallPackages, pluginOpts, expected }) => {
508+
testUtils.chdirWorkspaces(workspace);
509+
testUtils.ensureVirtualenv(workspace);
510+
tearDown = testUtils.activateVirtualenv(workspace);
511+
testUtils.pipUninstall('setuptools');
512+
testUtils.pipInstall();
513+
if (uninstallPackages) {
514+
uninstallPackages.forEach((pkg) => {
515+
testUtils.pipUninstall(pkg);
516+
});
517+
}
518+
519+
const result = await inspect('.', FILENAMES.pip.manifest, pluginOpts);
520+
compareTransitiveLines(result.dependencyGraph, expected);
521+
}
522+
);
308523

309524
it('should fail on missing transitive dependencies', async () => {
310525
const workspace = 'pip-app';
@@ -439,7 +654,6 @@ describe('inspect', () => {
439654
status: 0,
440655
} as SpawnSyncReturns<Buffer>);
441656
mockedExecute.mockResolvedValueOnce('Python 3.9.5');
442-
mockedExecute.mockResolvedValueOnce('Python 3.9.5');
443657
mockedExecute.mockResolvedValueOnce(
444658
'{"name": "pipenv-app", "version": "0.0.0", "dependencies": {"jinja2": {"name": "jinja2", "version": "3.0.1", "dependencies": {"MarkupSafe": {"name": "markupsafe", "version": "2.0.1"}}}}, "packageFormatVersion": "pip:0.0.1"}'
445659
);
@@ -563,7 +777,6 @@ describe('inspect', () => {
563777
});
564778

565779
it('should return correct target file for setuptools project when relative path to setup lock file is passed', async () => {
566-
mockedExecute.mockResolvedValueOnce('Python 3.9.5');
567780
mockedExecute.mockResolvedValueOnce('Python 3.9.5');
568781
mockedExecute.mockResolvedValueOnce(
569782
'{"name": "pipenv-app", "version": "0.0.0", "dependencies": {"jinja2": {"name": "jinja2", "version": "3.0.1", "dependencies": {"MarkupSafe": {"name": "markupsafe", "version": "2.0.1"}}}}, "packageFormatVersion": "pip:0.0.1"}'
@@ -589,7 +802,6 @@ describe('inspect', () => {
589802
status: 0,
590803
} as SpawnSyncReturns<Buffer>);
591804
mockedExecute.mockResolvedValueOnce('Python 3.9.5');
592-
mockedExecute.mockResolvedValueOnce('Python 3.9.5');
593805
mockedExecute.mockResolvedValueOnce(
594806
fs.readFileSync(
595807
'test/fixtures/dence-dep-graph/pip_resolve_output.json',
@@ -640,7 +852,6 @@ describe('inspect', () => {
640852

641853
describe('manifest file is empty', () => {
642854
it('should throw EmptyManifestError', async () => {
643-
mockedExecute.mockResolvedValueOnce('Python 3.9.5');
644855
mockedExecute.mockResolvedValueOnce('Python 3.9.5');
645856
mockedExecute.mockRejectedValueOnce(
646857
'No dependencies detected in manifest.'
@@ -655,7 +866,6 @@ describe('inspect', () => {
655866

656867
describe('required packages were not installed', () => {
657868
it('should throw RequiredPackagesMissingError', async () => {
658-
mockedExecute.mockResolvedValueOnce('Python 3.9.5');
659869
mockedExecute.mockResolvedValueOnce('Python 3.9.5');
660870
mockedExecute.mockRejectedValueOnce('Required packages missing');
661871
const manifestFilePath = 'path/to/requirements.txt';

0 commit comments

Comments
 (0)