diff --git a/__snapshots__/python-file-with-version.js b/__snapshots__/python-file-with-version.js index f4bb91fb9..4744614b8 100644 --- a/__snapshots__/python-file-with-version.js +++ b/__snapshots__/python-file-with-version.js @@ -3,6 +3,11 @@ __version__ = '0.6.0' ` +exports['src/project/__init__.py updateContent updates version in src/project/__init__.py 1'] = ` +__version__ = '0.6.0' + +` + exports['version.py updateContent updates version in version.py 1'] = ` # Copyright 2020 Google LLC # diff --git a/__snapshots__/python.js b/__snapshots__/python.js index a23ff5906..fde537330 100644 --- a/__snapshots__/python.js +++ b/__snapshots__/python.js @@ -168,6 +168,9 @@ version = "0.123.5" filename: project/__init__.py __version__ = '0.123.5' +filename: src/project/__init__.py +__version__ = '0.123.5' + filename: src/version.py # Copyright 2020 Google LLC # @@ -743,6 +746,9 @@ version = "0.123.5" filename: project/__init__.py __version__ = '0.123.5' +filename: src/project/__init__.py +__version__ = '0.123.5' + filename: src/version.py # Copyright 2020 Google LLC # diff --git a/src/releasers/python.ts b/src/releasers/python.ts index a9d9660c3..dcd64ba48 100644 --- a/src/releasers/python.ts +++ b/src/releasers/python.ts @@ -107,6 +107,7 @@ export class Python extends ReleasePR { : `file ${chalk.green('pyproject.toml')} did not exist` ); } + // TODO: figure out refactor that makes logic for updating __init__.py, version.py, __version__.py etc., configurable updates.push( new PythonFileWithVersion({ path: this.addPath(`${projectName}/__init__.py`), @@ -115,6 +116,14 @@ export class Python extends ReleasePR { packageName: packageName.name, }) ); + updates.push( + new PythonFileWithVersion({ + path: this.addPath(`src/${projectName}/__init__.py`), + changelogEntry, + version: candidate.version, + packageName: packageName.name, + }) + ); // There should be only one version.py, but foreach in case that is incorrect const versionPyFilesSearch = this.gh.findFilesByFilename( 'version.py', diff --git a/test/fixtures/manifest/repo/python/src/foolib/__init__.py b/test/fixtures/manifest/repo/python/src/foolib/__init__.py new file mode 100644 index 000000000..5a5df3bef --- /dev/null +++ b/test/fixtures/manifest/repo/python/src/foolib/__init__.py @@ -0,0 +1 @@ +__version__ = '1.2.3' diff --git a/test/manifest.ts b/test/manifest.ts index 122709a26..a8b88c6cc 100644 --- a/test/manifest.ts +++ b/test/manifest.ts @@ -152,6 +152,7 @@ describe('Manifest', () => { 'python/HISTORY.md', 'package-lock.json', 'python/foolib/__init__.py', + 'python/src/foolib/__init__.py', 'npm-shrinkwrap.json', 'samples/package.json', 'CHANGELOG.md', diff --git a/test/releasers/python.ts b/test/releasers/python.ts index c9f2d6ca6..417dc57f4 100644 --- a/test/releasers/python.ts +++ b/test/releasers/python.ts @@ -134,6 +134,12 @@ describe('Python', () => { version: expectedVersion, packageName: pkgName, }), + new PythonFileWithVersion({ + path: `src/${pkgName}/__init__.py`, + changelogEntry: perUpdateChangelog, + version: expectedVersion, + packageName: pkgName, + }), new PythonFileWithVersion({ path: 'src/version.py', changelogEntry: perUpdateChangelog, @@ -195,6 +201,12 @@ describe('Python', () => { version: expectedVersion, packageName: pkgName, }), + new PythonFileWithVersion({ + path: `src/${pkgName}/__init__.py`, + changelogEntry: perUpdateChangelog, + version: expectedVersion, + packageName: pkgName, + }), new PythonFileWithVersion({ path: 'src/version.py', changelogEntry: perUpdateChangelog, @@ -237,6 +249,7 @@ describe('Python', () => { stubFilesToUpdate(releasePR.gh, [ 'pyproject.toml', 'project/__init__.py', + 'src/project/__init__.py', 'setup.py', 'src/version.py', 'setup.cfg', @@ -304,6 +317,7 @@ describe('Python', () => { stubFilesToUpdate(releasePR.gh, [ 'pyproject.toml', 'project/__init__.py', + 'src/project/__init__.py', 'setup.py', 'src/version.py', 'setup.cfg', diff --git a/test/updaters/fixtures/src/project/__init__.py b/test/updaters/fixtures/src/project/__init__.py new file mode 100644 index 000000000..b50da94dd --- /dev/null +++ b/test/updaters/fixtures/src/project/__init__.py @@ -0,0 +1 @@ +__version__ = '3.2.1' diff --git a/test/updaters/python-file-with-version.ts b/test/updaters/python-file-with-version.ts index fd66282bb..b530a6473 100644 --- a/test/updaters/python-file-with-version.ts +++ b/test/updaters/python-file-with-version.ts @@ -57,3 +57,22 @@ describe('project/__init__.py', () => { }); }); }); + +describe('src/project/__init__.py', () => { + describe('updateContent', () => { + it('updates version in src/project/__init__.py', async () => { + const oldContent = readFileSync( + resolve(fixturesPath, './src/project/__init__.py'), + 'utf8' + ).replace(/\r\n/g, '\n'); + const version = new PythonFileWithVersion({ + path: 'src/project/__init__.py', + changelogEntry: '', + version: '0.6.0', + packageName: '', + }); + const newContent = version.updateContent(oldContent); + snapshot(newContent); + }); + }); +});