diff --git a/src/towncrier/build.py b/src/towncrier/build.py index 60e0e861..3a07bae1 100644 --- a/src/towncrier/build.py +++ b/src/towncrier/build.py @@ -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( diff --git a/src/towncrier/test/test_build.py b/src/towncrier/test/test_build.py index d4561263..35c5e5f1 100644 --- a/src/towncrier/test/test_build.py +++ b/src/towncrier/test/test_build.py @@ -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())