Skip to content

Commit

Permalink
Allow for defining arbitrary project version and name in configuratio…
Browse files Browse the repository at this point in the history
…n - close twisted#165

    This allows for the towncrier to be seamlessly used in non-python projects
  • Loading branch information
fizyk committed Nov 12, 2019
1 parent 3d01a19 commit e55496b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
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
.python-version
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,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"
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"),
"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 to define ``project_version`` and ``project_name`` in configuration.
This allows to use towncrier seamlessly in the non-pythyon projects.

0 comments on commit e55496b

Please sign in to comment.