Skip to content
Permalink
Browse files
feat(python): support src/packagename/__init__.py (#1062)
* feat(python): support src/packagename/__init__.py

For the popular src directory layout,
https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure

* Update test snapshots

* docs: add TODO note about configurability refactor for Python files

Co-authored-by: Benjamin E. Coe <bencoe@google.com>
Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
3 people committed Sep 24, 2021
1 parent 0549a30 commit 598667da5a623c3fb057874840b3c308d225c627
@@ -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
#
@@ -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
#
@@ -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',
@@ -0,0 +1 @@
__version__ = '1.2.3'
@@ -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',
@@ -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',
@@ -0,0 +1 @@
__version__ = '3.2.1'
@@ -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);
});
});
});

0 comments on commit 598667d

Please sign in to comment.