-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(python): Add support to change version in setup.cfg (#374)
- Loading branch information
Showing
5 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |