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

feat(python): support src/packagename/__init__.py #1062

Merged
merged 5 commits into from Sep 24, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions __snapshots__/python-file-with-version.js
Expand Up @@ -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
#
Expand Down
6 changes: 6 additions & 0 deletions __snapshots__/python.js
Expand Up @@ -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
#
Expand Down Expand Up @@ -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
#
Expand Down
9 changes: 9 additions & 0 deletions src/releasers/python.ts
Expand Up @@ -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`),
Expand All @@ -115,6 +116,14 @@ export class Python extends ReleasePR {
packageName: packageName.name,
})
);
updates.push(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding a // TODO: figure out refactor that makes logic for updating __init__.py, etc., configurable

I'm a little worried about the number of optional paths we've added at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

FWIW after this one's in, pretty much the last one re filenames I'm aware some projects could appreciate would be updating __version__.py files anywhere in the tree. That could be handled just like version.py currently is.

But at that point I think all the "standard" ways to refer to the version would be addressed and a reasonable alternative to configurability might be to nudge projects to use a more common filename to place their __version__ in.

Then again while the __version__ symbol is probably the most prominent, some projects use just version or VERSION...

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',
Expand Down
@@ -0,0 +1 @@
__version__ = '1.2.3'
1 change: 1 addition & 0 deletions test/manifest.ts
Expand Up @@ -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',
Expand Down
14 changes: 14 additions & 0 deletions test/releasers/python.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions test/updaters/fixtures/src/project/__init__.py
@@ -0,0 +1 @@
__version__ = '3.2.1'
19 changes: 19 additions & 0 deletions test/updaters/python-file-with-version.ts
Expand Up @@ -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);
});
});
});