Skip to content

Commit

Permalink
Build command supports multiple projects with one config
Browse files Browse the repository at this point in the history
The create command already supports this.
  • Loading branch information
iliakur committed Sep 26, 2023
1 parent 239f841 commit 5921bab
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/towncrier/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ def __main(
click.echo("Finding news fragments...", err=to_err)

if config.directory is not None:
fragment_base_directory = os.path.abspath(config.directory)
fragment_base_directory = os.path.abspath(
os.path.join(base_directory, config.directory)
)
fragment_directory = None
else:
fragment_base_directory = os.path.abspath(
Expand Down
34 changes: 34 additions & 0 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,3 +1344,37 @@ def test_with_topline_and_template_and_draft(self):

self.assertEqual(0, result.exit_code, result.output)
self.assertEqual(expected_output, result.output)

@with_isolated_runner
def test_multiple_projects_share_one_config(self, runner):
"""
Multiple projects with independent changelogs share one towncrier
configuration.
For this to work:
1. We need to leave `config.package` empty.
2. We need to pass `--dir` to `create` and `build` explicitly.
It must point to the project folder.
3. We need to pass `--config` pointing at the global configuration.
4. We need to make sure `config.directory` and `config.filename` are resolved
relative to what we passed as `--dir`.
"""
# We don't want to specify the package because we have multiple ones.
Path("pyproject.toml").write_text(
"[tool.towncrier]\n" + 'directory = "changelog.d"\n'
)
# Each subproject contains the source code...
Path("foo/foo").mkdir(parents=True)
Path("foo/foo/__init__.py").write_text("")
# ... and the changelog machinery.
Path("foo/changelog.d").mkdir()
Path("foo/changelog.d/123.feature").write_text("Adds levitation")
self.assertFalse(Path("foo/NEWS.rst").exists())

result = runner.invoke(
cli,
("--yes", "--config", "pyproject.toml", "--dir", "foo", "--version", "1.0"),
)

self.assertEqual(0, result.exit_code)
self.assertTrue(Path("foo/NEWS.rst").exists())

0 comments on commit 5921bab

Please sign in to comment.