Skip to content

Commit

Permalink
feat(python): support packagename/__init__.py without pyproject.toml (g…
Browse files Browse the repository at this point in the history
…oogleapis#1026)

* feat: support packagename/__init__.py without pyproject.toml

* test: update tests

Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
scop and bcoe committed Sep 9, 2021
1 parent d37311c commit f461ff7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/releasers/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class Python extends ReleasePR {

const parsedPyProject = await this.getPyProject();
const pyProject = parsedPyProject?.project || parsedPyProject?.tool?.poetry;
let projectName = packageName.name;
if (pyProject) {
updates.push(
new PyProjectToml({
Expand All @@ -98,25 +99,22 @@ export class Python extends ReleasePR {
packageName: packageName.name,
})
);

if (pyProject.name) {
updates.push(
new PythonFileWithVersion({
path: this.addPath(`${pyProject.name}/__init__.py`),
changelogEntry,
version: candidate.version,
packageName: packageName.name,
})
);
}
projectName = pyProject.name;
} else {
logger.warn(
parsedPyProject
? 'invalid pyproject.toml'
: `file ${chalk.green('pyproject.toml')} did not exist`
);
}

updates.push(
new PythonFileWithVersion({
path: this.addPath(`${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
1 change: 1 addition & 0 deletions test/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ describe('Manifest', () => {
'python/CHANGELOG.md',
'python/HISTORY.md',
'package-lock.json',
'python/foolib/__init__.py',
'npm-shrinkwrap.json',
'samples/package.json',
'CHANGELOG.md',
Expand Down
12 changes: 12 additions & 0 deletions test/releasers/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ describe('Python', () => {
version: expectedVersion,
packageName: pkgName,
}),
new PythonFileWithVersion({
path: `${pkgName}/__init__.py`,
changelogEntry: perUpdateChangelog,
version: expectedVersion,
packageName: pkgName,
}),
new PythonFileWithVersion({
path: 'src/version.py',
changelogEntry: perUpdateChangelog,
Expand Down Expand Up @@ -183,6 +189,12 @@ describe('Python', () => {
version: expectedVersion,
packageName: pkgName,
}),
new PythonFileWithVersion({
path: `${pkgName}/__init__.py`,
changelogEntry: perUpdateChangelog,
version: expectedVersion,
packageName: pkgName,
}),
new PythonFileWithVersion({
path: 'src/version.py',
changelogEntry: perUpdateChangelog,
Expand Down

0 comments on commit f461ff7

Please sign in to comment.