Skip to content

Commit

Permalink
Revert "feat(manager/poetry): extract python as a dependency from `py…
Browse files Browse the repository at this point in the history
…project.toml` (#24236)"

This reverts commit 46c10be.
  • Loading branch information
rarkins committed Sep 5, 2023
1 parent 80a81ce commit 76e26e3
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 84 deletions.
22 changes: 0 additions & 22 deletions lib/modules/manager/poetry/__snapshots__/extract.spec.ts.snap
Expand Up @@ -471,17 +471,6 @@ exports[`modules/manager/poetry/extract extractPackageFile() extracts multiple d
},
"versioning": "poetry",
},
{
"commitMessageTopic": "Python",
"currentValue": "~2.7 || ^3.4",
"datasource": "docker",
"depName": "python",
"depType": "dependencies",
"managerData": {
"nestedVersion": false,
},
"versioning": "poetry",
},
{
"currentValue": "^3.0",
"datasource": "pypi",
Expand Down Expand Up @@ -565,17 +554,6 @@ exports[`modules/manager/poetry/extract extractPackageFile() handles multiple co
exports[`modules/manager/poetry/extract extractPackageFile() resolves lockedVersions from the lockfile 1`] = `
{
"deps": [
{
"commitMessageTopic": "Python",
"currentValue": "^3.9",
"datasource": "docker",
"depName": "python",
"depType": "dependencies",
"managerData": {
"nestedVersion": false,
},
"versioning": "poetry",
},
{
"currentValue": "*",
"datasource": "pypi",
Expand Down
26 changes: 1 addition & 25 deletions lib/modules/manager/poetry/artifacts.spec.ts
@@ -1,4 +1,3 @@
import { codeBlock } from 'common-tags';
import { join } from 'upath';
import { envMock, mockExecAll } from '../../../../test/exec-util';
import { Fixtures } from '../../../../test/fixtures';
Expand All @@ -9,7 +8,7 @@ import * as docker from '../../../util/exec/docker';
import * as _hostRules from '../../../util/host-rules';
import * as _datasource from '../../datasource';
import type { UpdateArtifactsConfig } from '../types';
import { getPoetryRequirement, getPythonConstraint } from './artifacts';
import { getPoetryRequirement } from './artifacts';
import { updateArtifacts } from '.';

const pyproject1toml = Fixtures.get('pyproject.1.toml');
Expand All @@ -34,29 +33,6 @@ const adminConfig: RepoGlobalConfig = {
const config: UpdateArtifactsConfig = {};

describe('modules/manager/poetry/artifacts', () => {
describe('getPythonConstraint', () => {
const pythonVersion = '3.11.3';
const poetryLock = codeBlock`
[metadata]
python-versions = "${pythonVersion}"
`;

it('detects from pyproject.toml', () => {
const pythonVersion = '3.11.5';
const pyprojectContent = codeBlock`
[tool.poetry.dependencies]
python = "${pythonVersion}"
`;
expect(getPythonConstraint(pyprojectContent, poetryLock)).toBe(
pythonVersion
);
});

it('detects from poetry.ock', () => {
expect(getPythonConstraint('', poetryLock)).toBe(pythonVersion);
});
});

describe('getPoetryRequirement', () => {
const poetry12lock = Fixtures.get('poetry12.lock');
const poetry142lock = Fixtures.get('poetry142.lock');
Expand Down
25 changes: 2 additions & 23 deletions lib/modules/manager/poetry/artifacts.ts
Expand Up @@ -22,33 +22,12 @@ import { Lockfile, PoetrySchemaToml } from './schema';
import type { PoetryFile, PoetrySource } from './types';

export function getPythonConstraint(
pyProjectContent: string,
existingLockFileContent: string
): string | null {
// Read Python version from `pyproject.toml` first as it could have been updated
const pyprojectPythonConstraint = Result.parse(
pyProjectContent,
PoetrySchemaToml.transform(
({ packageFileContent }) =>
packageFileContent.deps.find((dep) => dep.depName === 'python')
?.currentValue
)
).unwrapOrNull();
if (pyprojectPythonConstraint) {
logger.debug('Using python version from pyproject.toml');
return pyprojectPythonConstraint;
}

const lockfilePythonConstraint = Result.parse(
return Result.parse(
existingLockFileContent,
Lockfile.transform(({ pythonVersions }) => pythonVersions)
).unwrapOrNull();
if (lockfilePythonConstraint) {
logger.debug('Using python version from poetry.lock');
return lockfilePythonConstraint;
}

return null;
}

export function getPoetryRequirement(
Expand Down Expand Up @@ -179,7 +158,7 @@ export async function updateArtifacts({
}
const pythonConstraint =
config?.constraints?.python ??
getPythonConstraint(newPackageFileContent, existingLockFileContent);
getPythonConstraint(existingLockFileContent);
const poetryConstraint =
config.constraints?.poetry ??
getPoetryRequirement(newPackageFileContent, existingLockFileContent);
Expand Down
9 changes: 3 additions & 6 deletions lib/modules/manager/poetry/extract.spec.ts
Expand Up @@ -48,7 +48,7 @@ describe('modules/manager/poetry/extract', () => {
it('extracts multiple dependencies', async () => {
const res = await extractPackageFile(pyproject1toml, filename);
expect(res?.deps).toMatchSnapshot();
expect(res?.deps).toHaveLength(10);
expect(res?.deps).toHaveLength(9);
expect(res?.extractedConstraints).toEqual({
python: '~2.7 || ^3.4',
});
Expand All @@ -74,7 +74,7 @@ describe('modules/manager/poetry/extract', () => {
it('can parse TOML v1 heterogeneous arrays', async () => {
const res = await extractPackageFile(pyproject12toml, filename);
expect(res).not.toBeNull();
expect(res?.deps).toHaveLength(3);
expect(res?.deps).toHaveLength(2);
});

it('extracts registries', async () => {
Expand Down Expand Up @@ -184,10 +184,7 @@ describe('modules/manager/poetry/extract', () => {
const res = await extractPackageFile(pyproject11toml, filename);
expect(res).toMatchSnapshot({
extractedConstraints: { python: '^3.9' },
deps: [
{ depName: 'python', currentValue: '^3.9' },
{ depName: 'boto3', lockedVersion: '1.17.5' },
],
deps: [{ lockedVersion: '1.17.5' }],
});
});

Expand Down
7 changes: 1 addition & 6 deletions lib/modules/manager/poetry/extract.ts
Expand Up @@ -7,7 +7,6 @@ import {
readLocalFile,
} from '../../../util/fs';
import { Result } from '../../../util/result';
import { DockerDatasource } from '../../datasource/docker';
import type { PackageFileContent } from '../types';
import { Lockfile, PoetrySchemaToml } from './schema';

Expand Down Expand Up @@ -38,11 +37,7 @@ export async function extractPackageFile(
if (dep.currentValue) {
pythonVersion = dep.currentValue;
}
return {
...dep,
datasource: DockerDatasource.id,
commitMessageTopic: 'Python',
};
return null;
}

const packageName = dep.packageName ?? dep.depName;
Expand Down
2 changes: 0 additions & 2 deletions lib/modules/manager/poetry/index.ts
@@ -1,5 +1,4 @@
import type { Category } from '../../../constants';
import { DockerDatasource } from '../../datasource/docker';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { PypiDatasource } from '../../datasource/pypi';

Expand All @@ -10,7 +9,6 @@ export { updateLockedDependency } from './update-locked';
export const supportedDatasources = [
PypiDatasource.id,
GithubTagsDatasource.id,
DockerDatasource.id,
];

export const supportsLockFileMaintenance = true;
Expand Down

0 comments on commit 76e26e3

Please sign in to comment.