Skip to content

Commit

Permalink
fix(python): warn on dynamic pyproject.toml versioning (#1983)
Browse files Browse the repository at this point in the history
This PR makes sure that people that use dynamic versioning in the `pyproject.toml`
file receive a warning instead of an error. See #1804.

Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
rickstaa and chingor13 authored Jul 10, 2023
1 parent 4099f8a commit 5ee5baa
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/updaters/python/pyproject-toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
// limitations under the License.

import * as TOML from '@iarna/toml';
import {replaceTomlValue} from '../../util/toml-edit';
import {logger as defaultLogger, Logger} from '../../util/logger';
import {replaceTomlValue} from '../../util/toml-edit';
import {DefaultUpdater} from '../default';

// TODO: remove support for `poetry.tool` when Poetry will use `project`.

interface PyProjectContent {
name: string;
version: string;
dynamic?: string[];
}

/**
Expand Down Expand Up @@ -52,6 +53,14 @@ export class PyProjectToml extends DefaultUpdater {
const project = parsed.project || parsed.tool?.poetry;

if (!project?.version) {
// Throw warning if the version is dynamically generated.
if (project?.dynamic && project.dynamic.includes('version')) {
const msg =
"dynamic version found in 'pyproject.toml'. Skipping update.";
logger.warn(msg);
return content;
}

const msg = 'invalid file';
logger.error(msg);
throw new Error(msg);
Expand Down

0 comments on commit 5ee5baa

Please sign in to comment.