Skip to content

Commit

Permalink
feat(python): Add support to change version in setup.cfg (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
crwilcox authored Mar 20, 2020
1 parent 4d3315d commit 4a9ef3d
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 0 deletions.
47 changes: 47 additions & 0 deletions __snapshots__/setup-cfg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
exports['setup.cfg updateContent updates version in setup.cfg 1'] = `
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[metadata]
name = google-crc32c
version = 0.6.0
description = A python wrapper of the C library 'Google CRC32C'
url = https://github.com/googleapis/python-crc32c
long_description = file: README.md
long_description_content_type = text/markdown
author = Google LLC
author_email = [email protected]
license = Apache 2.0
platforms = Posix, MacOS X, Windows
classifiers =
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
[options]
zip_safe = True
python_requires = >=3.5
[options.extras_require]
testing = pytest
`
9 changes: 9 additions & 0 deletions src/releasers/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Commit } from '../graphql-to-commits';
import { Changelog } from '../updaters/changelog';
// Python specific.
import { SetupPy } from '../updaters/python/setup-py';
import { SetupCfg } from '../updaters/python/setup-cfg';

export class Python extends ReleasePR {
protected async _run() {
Expand Down Expand Up @@ -72,6 +73,14 @@ export class Python extends ReleasePR {
})
);

updates.push(
new SetupCfg({
path: 'setup.cfg',
changelogEntry,
version: candidate.version,
packageName: this.packageName,
})
);
updates.push(
new SetupPy({
path: 'setup.py',
Expand Down
40 changes: 40 additions & 0 deletions src/updaters/python/setup-cfg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Update, UpdateOptions, VersionsMap } from '../update';
import { GitHubFileContents } from '../../github';

export class SetupCfg implements Update {
path: string;
changelogEntry: string;
version: string;
versions?: VersionsMap;
packageName: string;
create: boolean;
contents?: GitHubFileContents;

constructor(options: UpdateOptions) {
this.create = false;
this.path = options.path;
this.changelogEntry = options.changelogEntry;
this.version = options.version;
this.packageName = options.packageName;
}
updateContent(content: string): string {
return content.replace(
/version ?= ?[0-9]+\.[0-9]+\.[0-9](-\w+)?/,
`version = ${this.version}`
);
}
}
44 changes: 44 additions & 0 deletions test/updaters/fixtures/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[metadata]
name = google-crc32c
version = 0.1.0
description = A python wrapper of the C library 'Google CRC32C'
url = https://github.com/googleapis/python-crc32c
long_description = file: README.md
long_description_content_type = text/markdown
author = Google LLC
author_email = [email protected]

license = Apache 2.0
platforms = Posix, MacOS X, Windows
classifiers =
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8

[options]
zip_safe = True
python_requires = >=3.5

[options.extras_require]
testing = pytest

40 changes: 40 additions & 0 deletions test/updaters/setup-cfg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { readFileSync } from 'fs';
import { basename, resolve } from 'path';
import * as snapshot from 'snap-shot-it';

import { SetupCfg } from '../../src/updaters/python/setup-cfg';

const fixturesPath = './test/updaters/fixtures';

describe('setup.cfg', () => {
describe('updateContent', () => {
it('updates version in setup.cfg', async () => {
const oldContent = readFileSync(
resolve(fixturesPath, './setup.cfg'),
'utf8'
).replace(/\r\n/g, '\n');
const version = new SetupCfg({
path: 'setup.cfg',
changelogEntry: '',
version: '0.6.0',
packageName: '',
});
const newContent = version.updateContent(oldContent);
snapshot(newContent);
});
});
});

0 comments on commit 4a9ef3d

Please sign in to comment.