Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): handle large version numbers in setup.cfg #1906

Merged
merged 3 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions __snapshots__/setup-cfg.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
exports['setup.cfg updateContent updates big 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 = googleapis-packages@google.com

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


`

exports['setup.cfg updateContent updates version in setup.cfg 1'] = `
# Copyright 2020 Google LLC
#
Expand Down
2 changes: 1 addition & 1 deletion src/updaters/python/setup-cfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class SetupCfg extends DefaultUpdater {
*/
updateContent(content: string): string {
return content.replace(
/(version ?= ?)[0-9]+\.[0-9]+\.[0-9](?:-\w+)?/,
/(version ?= ?)[0-9]+\.[0-9]+\.[0-9]+(?:-\w+)?/,
`$1${this.version}`
);
}
Expand Down
44 changes: 44 additions & 0 deletions test/updaters/fixtures/setup-big-version.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 = 123.456.789
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 = googleapis-packages@google.com

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

11 changes: 11 additions & 0 deletions test/updaters/setup-cfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,16 @@ describe('setup.cfg', () => {
const newContent = version.updateContent(oldContent);
snapshot(newContent);
});
it('updates big version in setup.cfg', async () => {
const oldContent = readFileSync(
resolve(fixturesPath, './setup-big-version.cfg'),
'utf8'
).replace(/\r\n/g, '\n');
const version = new SetupCfg({
version: Version.parse('0.6.0'),
});
const newContent = version.updateContent(oldContent);
snapshot(newContent);
});
});
});