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

Allow for defining arbitrary project version and name in configuratio… #166

Merged
merged 11 commits into from
Dec 7, 2020
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ apidocs/
.tox/
.coverage.*
.vscode
.idea
altendky marked this conversation as resolved.
Show resolved Hide resolved
.python-version
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ Towncrier has the following global options, which can be specified in the toml f
single_file = true # if false, filename is formatted like `title_format`.
filename = "NEWS.rst"
directory = "directory/of/news/fragments"
project_version = "project version if maintained separately"
fizyk marked this conversation as resolved.
Show resolved Hide resolved
project_name = "arbitrary project name"
template = "path/to/template.rst"
start_line = "start of generated content"
title_format = "{name} {version} ({project_date})" # or false if template includes title
Expand Down
2 changes: 2 additions & 0 deletions src/towncrier/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def parse_toml(base_path, config):
"single_file": single_file,
"filename": config.get("filename", "NEWS.rst"),
"directory": config.get("directory"),
"project_version": config.get("project_version"),
"project_name": config.get("project_name"),
Copy link
Member

Choose a reason for hiding this comment

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

Do the names in the configuration file need the project_ prefix? Or would name and version suffice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's a matter of preference, and short version is as good as longer. One does not use library_version or library_name variables after all...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although comming back, I used the project_ prefixes since I was extending the use of already existing variables in code

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I saw the code used longer names and that makes sense to me. I couldn't make up my mind so I thought about setuptools and checked Poetry and both of them use just name and version. I don't think it ends up being ambiguous. I don't feel strongly enough to push hard on this, but if you are comfortable with changing to the shorter, I think that's a touch more straightforward. Take your pick and we'll move on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, changed to shorter

"sections": sections,
"types": types,
"template": template,
Expand Down
28 changes: 16 additions & 12 deletions src/towncrier/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,24 @@ def __main(
)

if project_version is None:
project_version = get_version(
os.path.join(base_directory, config["package_dir"]), config["package"]
).strip()
project_version = config.get('project_version')
if project_version is None:
project_version = get_version(
os.path.join(base_directory, config["package_dir"]), config["package"]
).strip()

if project_name is None:
package = config.get("package")
if package:
project_name = get_project_name(
os.path.abspath(os.path.join(base_directory, config["package_dir"])),
package,
)
else:
# Can't determine a project_name, but maybe it is not needed.
project_name = ""
project_name = config.get('project_name')
if not project_name:
package = config.get("package")
if package:
project_name = get_project_name(
os.path.abspath(os.path.join(base_directory, config["package_dir"])),
package,
)
else:
# Can't determine a project_name, but maybe it is not needed.
project_name = ""

if project_date is None:
project_date = _get_date().strip()
Expand Down
2 changes: 2 additions & 0 deletions src/towncrier/newsfragments/165.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Allow definition of ``project_version`` and ``project_name`` in the configuration file.
fizyk marked this conversation as resolved.
Show resolved Hide resolved
This allows use of towncrier seamlessly with non-Python projects.
84 changes: 84 additions & 0 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,90 @@ def test_projectless_changelog(self):
).lstrip(),
)

def test_version_in_config(self):
"""The calling towncrier with version defined in configfile.

Specifying a version in toml file will be helpful if version
is maintained by bumpversion and it's not a python project.
"""
runner = CliRunner()

with runner.isolated_filesystem():
with open("pyproject.toml", "w") as f:
f.write("[tool.towncrier]\n" 'project_version = "7.8.9"\n')
os.mkdir("newsfragments")
with open("newsfragments/123.feature", "w") as f:
f.write("Adds levitation")

result = runner.invoke(
_main, ["--date", "01-01-2001", "--draft"]
)

self.assertEqual(0, result.exit_code, result.output)
self.assertEqual(
result.output,
dedent(
"""
Loading template...
Finding news fragments...
Rendering news fragments...
Draft only -- nothing has been written.
What is seen below is what would be written.

7.8.9 (01-01-2001)
==================

Features
--------

- Adds levitation (#123)

"""
).lstrip(),
)

def test_project_name_in_config(self):
"""The calling towncrier with project name defined in configfile.

Specifying a project name in toml file will be helpful to keep the
project name consistent as part of the towncrier configuration, not call.
"""
runner = CliRunner()

with runner.isolated_filesystem():
with open("pyproject.toml", "w") as f:
f.write("[tool.towncrier]\n" 'project_name = "ImGoProject"\n')
os.mkdir("newsfragments")
with open("newsfragments/123.feature", "w") as f:
f.write("Adds levitation")

result = runner.invoke(
_main, ["--version", "7.8.9", "--date", "01-01-2001", "--draft"]
)

self.assertEqual(0, result.exit_code, result.output)
self.assertEqual(
result.output,
dedent(
"""
Loading template...
Finding news fragments...
Rendering news fragments...
Draft only -- nothing has been written.
What is seen below is what would be written.

ImGoProject 7.8.9 (01-01-2001)
==============================

Features
--------

- Adds levitation (#123)

"""
).lstrip(),
)

def test_no_package_changelog(self):
"""The calling towncrier with any package argument.

Expand Down