Skip to content

Commit

Permalink
fix(python): handle large version numbers in setup.cfg (#1906)
Browse files Browse the repository at this point in the history
* test: failing test for large python version in setup.cfg

* fix(python): handle large version numbers in setup.cfg
  • Loading branch information
chingor13 authored Apr 10, 2023
1 parent 52fc1bb commit 9a7b11f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
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);
});
});
});

0 comments on commit 9a7b11f

Please sign in to comment.