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

Add version.py template #39

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .nengobones.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
project_name: Nengo Bones
pkg_name: nengo_bones
repo_name: nengo/nengo-bones
version:
major: 0
minor: 2
patch: 2
release: false

description: Tools for managing Nengo projects
copyright_start: 2018
Expand Down Expand Up @@ -160,3 +165,12 @@ docs_conf_py:
gitignore:
extra:
- docs/examples/**/*.py

version_py:
extra_doc: |
The API of nengo-bones is different from other libraries, so we increment
version numbers as follows:

1. Major version when command line scripts change significantly.
2. Minor version when changes require patches to downstream projects.
3. Patch version when changes do not require downstream patches.
6 changes: 2 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import os

import nengo_bones

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
Expand Down Expand Up @@ -63,8 +61,8 @@
project = "Nengo Bones"
authors = "Applied Brain Research"
copyright = "2018-2019 Applied Brain Research"
version = ".".join(nengo_bones.__version__.split(".")[:2]) # Short X.Y version
release = nengo_bones.__version__ # Full version, with tags
version = "0.2"
release = "0.2.2.dev0"

# -- HTML output
templates_path = ["_templates"]
Expand Down
1 change: 1 addition & 0 deletions nengo_bones/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
"MANIFEST.in": "manifest_in",
"setup.cfg": "setup_cfg",
"setup.py": "setup_py",
"version.py": "version_py", # TODO: how to incorporate pkg_name ?
}
12 changes: 11 additions & 1 deletion nengo_bones/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ def fill_defaults(config):
cfg = config["docs_conf_py"]
cfg.setdefault("nengo_logo", "general-full-light.svg")

# Automatically fill in full version
v = config["version"]
v["full"] = "{}.{}.{}{}".format(
v["major"], v["minor"], v["patch"], "" if v["release"] else ".dev0"
)


def validate_config(config):
"""
Expand All @@ -127,7 +133,11 @@ def validate_config(config):
config : dict
Dictionary containing configuration values.
"""
mandatory = ["project_name", "pkg_name", "repo_name", "travis_yml.jobs"]
mandatory = [
"project_name", "pkg_name", "repo_name", "travis_yml.jobs",
"version", "version.major", "version.minor", "version.patch",
"version.release",
]

for entry in mandatory:
tmp = config
Expand Down
21 changes: 18 additions & 3 deletions nengo_bones/scripts/generate_bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def render_template(ctx, cfg_key, output_file, template_file=None, **kwargs):
output_file = os.path.join(ctx.obj["output_dir"], output_file)
with open(output_file, "w") as f:
f.write(template.render(
version=nengo_bones.__version__,
bones_version=nengo_bones.__version__,
**kwargs,
# pass in the top-level config options as well
# TODO: separate "top-level" config into its own section?
Expand Down Expand Up @@ -138,7 +138,7 @@ def ci_scripts(ctx):
with open(path, "w") as f:
f.write(template.render(
pkg_name=config["pkg_name"], repo_name=config["repo_name"],
version=nengo_bones.__version__, **params))
bones_version=nengo_bones.__version__, **params))

# Mark CI script as executable
st = os.stat(path)
Expand All @@ -163,7 +163,7 @@ def travis_yml(ctx):

template = ctx.obj["env"].get_template(".travis.yml.template")
with open(os.path.join(ctx.obj["output_dir"], ".travis.yml"), "w") as f:
f.write(template.render(version=nengo_bones.__version__,
f.write(template.render(bones_version=nengo_bones.__version__,
**config["travis_yml"]))


Expand Down Expand Up @@ -263,5 +263,20 @@ def gitignore(ctx):
render_template(ctx, "gitignore", ".gitignore")


@main.command()
@click.pass_context
def version_py(ctx):
"""Generate {{ pkg_name }}/version.py file."""

pkg_name = ctx.obj["config"]["pkg_name"]
output_dir = os.path.join(ctx.obj["output_dir"], pkg_name)

if not os.path.exists(output_dir):
os.makedirs(output_dir)

render_template(ctx, "version_py", "%s/version.py" % (pkg_name,),
template_file="version.py.template")


if __name__ == "__main__":
main(obj={}) # pragma: no cover pylint: disable=no-value-for-parameter
2 changes: 1 addition & 1 deletion nengo_bones/templates/.codecov.yml.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Automatically generated by nengo-bones, do not edit this file directly
# Version: {{ version }}
# Version: {{ bones_version }}

codecov:
{% if skip_appveyor %}
Expand Down
2 changes: 1 addition & 1 deletion nengo_bones/templates/.gitignore.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Automatically generated by nengo-bones, do not edit this file directly
# Version: {{ version }}
# Version: {{ bones_version }}

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion nengo_bones/templates/.travis.yml.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Automatically generated by nengo-bones, do not edit this file directly
# Version: {{ version }}
# Version: {{ bones_version }}

language: python
python: {{ python }}
Expand Down
2 changes: 1 addition & 1 deletion nengo_bones/templates/CONTRIBUTING.rst.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.. Automatically generated by nengo-bones, do not edit this file directly
.. Version: {{ version }}
.. Version: {{ bones_version }}

****************{{ '*' * project_name | length }}
Contributing to {{ project_name }}
Expand Down
2 changes: 1 addition & 1 deletion nengo_bones/templates/CONTRIBUTORS.rst.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.. Automatically generated by nengo-bones, do not edit this file directly
.. Version: {{ version }}
.. Version: {{ bones_version }}

*************{{ '*' * project_name | length }}
{{ project_name }} contributors
Expand Down
2 changes: 1 addition & 1 deletion nengo_bones/templates/LICENSE.rst.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.. Automatically generated by nengo-bones, do not edit this file directly
.. Version: {{ version }}
.. Version: {{ bones_version }}

********{{ '*' * project_name|length }}
{{ project_name }} license
Expand Down
2 changes: 1 addition & 1 deletion nengo_bones/templates/MANIFEST.in.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Automatically generated by nengo-bones, do not edit this file directly
# Version: {{ version }}
# Version: {{ bones_version }}

global-include *.py
global-include *.sh
Expand Down
2 changes: 1 addition & 1 deletion nengo_bones/templates/base_script.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#!/usr/bin/env bash

# Automatically generated by nengo-bones, do not edit this file directly
# Version: {{ version }}
# Version: {{ bones_version }}

NAME=$0
COMMAND=$1
Expand Down
8 changes: 3 additions & 5 deletions nengo_bones/templates/docs_conf.py.template
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
#
# Automatically generated by nengo-bones, do not edit this file directly
# Version: {{ version }}
# Version: {{ bones_version }}

import os

import {{ pkg_name }}

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
Expand Down Expand Up @@ -75,8 +73,8 @@ pygments_style = "sphinx"
project = "{{ project_name }}"
authors = "{{ author }}"
copyright = "{{ copyright_start }}-{{ copyright_end }} {{ author }}"
version = ".".join({{ pkg_name }}.__version__.split(".")[:2]) # Short X.Y version
release = {{ pkg_name }}.__version__ # Full version, with tags
version = "{{ version.major }}.{{ version.minor }}"
release = "{{ version.full }}"

# -- HTML output
templates_path = ["_templates"]
Expand Down
2 changes: 1 addition & 1 deletion nengo_bones/templates/setup.cfg.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Automatically generated by nengo-bones, do not edit this file directly
# Version: {{ version }}
# Version: {{ bones_version }}

[build_sphinx]
source-dir = docs
Expand Down
14 changes: 3 additions & 11 deletions nengo_bones/templates/setup.py.template
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env python

# Automatically generated by nengo-bones, do not edit this file directly
# Version: {{ version }}

import io
import os
import runpy
# Version: {{ bones_version }}

try:
from setuptools import find_packages, setup
Expand All @@ -21,15 +17,11 @@ def read(*filenames, **kwargs):
sep = kwargs.get("sep", "\n")
buf = []
for filename in filenames:
with io.open(filename, encoding=encoding) as f:
with open(filename, encoding=encoding) as f:
buf.append(f.read())
return sep.join(buf)


root = os.path.dirname(os.path.realpath(__file__))
version = runpy.run_path(os.path.join(
root, "{{ pkg_name }}", "version.py"))["version"]

{% block install_req %}
install_req = [
{% for pkg in install_req %}
Expand All @@ -55,7 +47,7 @@ tests_req = [

setup(
name="{{ pkg_name|replace("_", "-") }}",
version=version,
version="{{ version.full }}",
author="{{ author }}",
author_email="{{ author_email }}",
packages=find_packages(),
Expand Down
18 changes: 18 additions & 0 deletions nengo_bones/templates/version.py.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Automatically generated by nengo-bones, do not edit this file directly
# Version: {{ bones_version }}

"""{{ project_name }} version information.

We use semantic versioning (see http://semver.org/).
and conform to PEP440 (see https://www.python.org/dev/peps/pep-0440/).
'.dev0' will be added to the version unless the code base represents
a release version. Release versions are git tagged with the version.
{% if extra_doc %}
{{ extra_doc }}
{% endif %}
"""

name = "{{ pkg_name | replace("_", "-") }}"
version_info = ({{ version.major }}, {{ version.minor }}, {{ version.patch }})
release = {{ version.release }}
version = "{{ version.full }}"
29 changes: 26 additions & 3 deletions nengo_bones/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ def test_find_config():


def test_fill_defaults():
init_cfg = {"travis_yml": {"jobs": [{"script": "docs-test"}]},
"codecov_yml": {}}
init_cfg = {
"travis_yml": {"jobs": [{"script": "docs-test"}]},
"codecov_yml": {},
"version": {
"major": 3, "minor": 2, "patch": 1, "release": False,
}
}
config.fill_defaults(init_cfg)

assert init_cfg["travis_yml"]["python"] == "3.6"
Expand All @@ -28,9 +33,15 @@ def test_fill_defaults():
assert init_cfg["codecov_yml"]["abs_target"] == "auto"
assert init_cfg["codecov_yml"]["diff_target"] == "100%"

assert init_cfg["version"]["full"] == "3.2.1.dev0"


def test_validate_config():
mandatory = ["project_name", "pkg_name", "repo_name", "travis_yml.jobs"]
mandatory = [
"project_name", "pkg_name", "repo_name", "travis_yml.jobs",
"version", "version.major", "version.minor", "version.patch",
"version.release",
]
init_cfg = {"travis_yml": {}}
for entry in mandatory:
with pytest.raises(KeyError, match="must define %s" % entry):
Expand Down Expand Up @@ -75,6 +86,13 @@ def test_load_config(tmpdir):
"project_name": "Dummy",
"pkg_name": "dummy",
"repo_name": "dummyorg/dummy",
"version": {
"major": 3,
"minor": 2,
"patch": 1,
"release": False,
"full": "3.2.1.dev0",
},
"author": "A Dummy",
"author_email": "[email protected]",
"copyright_start": 0,
Expand Down Expand Up @@ -106,6 +124,11 @@ def test_load_config(tmpdir):
project_name: Dummy
pkg_name: dummy
repo_name: dummyorg/dummy
version:
major: 3
minor: 2
patch: 1
release: false
author: A Dummy
author_email: [email protected]
copyright_start: 0
Expand Down
Loading