Skip to content

Commit

Permalink
CiscoDevNet#681 update versioning
Browse files Browse the repository at this point in the history
- generator will now look for latest version in sdk/version.json and update setup.py and CMakeLists.txt
- created templates for setup.py and CMakeLists under sdk/_common/setup_templates
- going forward, any changes to be made to setup.py or CMakeLists.txt should be applied to the templates
- going forward, to update the latest version, simply update sdk/version.json
  • Loading branch information
ylil93 committed Apr 11, 2018
1 parent d0e3f2f commit 16810ab
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ gen-api/
*.idea
scripts
sdk/cpp/core/tests/confd/ydktest/cli-history
sdk/cpp/core/CMakeLists.txt
sdk/python/core/ydk/models/ydktest
sdk/python/core/setup.py
92 changes: 42 additions & 50 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from argparse import ArgumentParser

import fileinput
import json
import logging
import os
import shutil
Expand All @@ -47,10 +48,34 @@ def init_verbose_logger():
# add the handlers to the logger
logger.addHandler(ch)

def print_setup_file(language, ydk_root):
local_name = ''
keyword = ''
if language == 'cpp':
local_name = 'CMakeLists.txt'
keyword = '_YDK_CPP_CORE_VERSION_'
elif language == 'python':
local_name = 'setup.py'
keyword = '_YDK_PYTHON_CORE_VERSION_'
else:
raise Exception('Language {0} has no setup file'.format(language))

template_file = os.path.join(ydk_root, 'sdk/_common/setup_templates/core_%s' % local_name)
setup_file = os.path.join(ydk_root, 'sdk', language, 'core', local_name)
if os.path.isfile(setup_file):
os.remove(setup_file)

lines = ''
with open(template_file, 'r+') as fd:
lines = fd.read()
if keyword in lines:
release = get_release(ydk_root)
lines = lines.replace(keyword, release)
with open(setup_file, 'w+') as fd:
fd.write(lines)

def print_about_page(ydk_root, py_api_doc_gen, release, is_bundle):
if is_bundle:
return

def print_about_page(ydk_root, py_api_doc_gen, release):
repo = Repo(ydk_root)
url = repo.remote().url.split('://')[-1].split('.git')[0]
commit_id = str(repo.head.commit)
Expand All @@ -66,7 +91,7 @@ def print_about_page(ydk_root, py_api_doc_gen, release, is_bundle):

# modify about_ydk.rst page
lines = ''
with open(os.path.join(ydk_root, 'sdk', '_docsgen_common', 'about_ydk.rst'), 'r+') as fd:
with open(os.path.join(ydk_root, 'sdk/_common/docsgen/about_ydk.rst'), 'r+') as fd:
lines = fd.read()
if 'git clone repo-url' in lines:
lines = lines.replace('repo-url', 'https://{0}.git'.format(url))
Expand All @@ -82,46 +107,10 @@ def print_about_page(ydk_root, py_api_doc_gen, release, is_bundle):
fd.write(lines)


def get_release_version(output_directory, language):
if language == 'python':
return get_py_release_version(output_directory)
elif language == 'cpp':
return get_cpp_release_version(output_directory)
elif language == 'go':
return get_go_release_version(output_directory)
else:
raise Exception('Language {0} not yet supported'.format(language))


def get_py_release_version(output_directory):
setup_file = os.path.join(output_directory, 'setup.py')
with open(setup_file, 'r') as f:
for line in f:
if ('version=' in line or 'version =' in line or
'NMSP_PKG_VERSION' in line and '$VERSION$' not in line or
line.startswith('VERSION =')):
rv = line[line.find('=')+1:].strip(' \'"\n')
release = "release=" + rv
version = "version=" + rv
break
return (release, version)


def get_cpp_release_version(output_directory):
version_string = ''
VERSION = re.compile(r"project\(ydk.* VERSION (?P<version>[\d+\.+]*) LANGUAGES C CXX\)")
cmake_file = os.path.join(output_directory, 'CMakeLists.txt')
with open(cmake_file) as f:
for line in f:
major_match = VERSION.match(line)
if major_match:
version_string = major_match.group('version')
release = "release=%s" % version_string
version = "version=%s" % version_string
return (release, version)

def get_go_release_version(output_directory):
return ("release=test", "version=test")
def get_release(ydk_root):
with open(os.path.join(ydk_root, 'sdk', 'version.json')) as f:
versions = json.load(f)
return versions['core']


def copy_docs_from_bundles(output_directory, destination_dir):
Expand Down Expand Up @@ -154,13 +143,13 @@ def generate_documentations(output_directory, ydk_root, language, is_bundle, is_
py_api_doc_gen = os.path.join(output_directory, 'docsgen')
py_api_doc = os.path.join(output_directory, 'docs_expanded')
# if it is package type
release = ''
version = ''
if is_core:
release, version = get_release_version(output_directory, language)
rv = get_release(ydk_root)
release = 'release=%s' % rv
version = 'version=%s' % rv
os.mkdir(py_api_doc)
# print about YDK page
print_about_page(ydk_root, py_api_doc_gen, release, is_bundle)

if not is_bundle:
print_about_page(ydk_root, py_api_doc_gen, rv)

if is_core:
copy_docs_from_bundles(output_directory, py_api_doc_gen)
Expand Down Expand Up @@ -386,6 +375,9 @@ def _get_time_taken(start_time):
elif options.python:
language = 'python'

if language != 'go' and options.core:
print_setup_file(language, ydk_root)

try:
if options.adhoc_bundle_name:
adhoc_bundle_file = generate_adhoc_bundle(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.0.0)
cmake_policy(SET CMP0048 NEW)
project(ydk VERSION 0.7.2 LANGUAGES C CXX)
project(ydk VERSION _YDK_CPP_CORE_VERSION_ LANGUAGES C CXX)


set(YDK_DESCRIPTION "YANG Development Kit Library. The library for YDK API.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
NMSP_PKG_DEPENDENCIES = ["$DEPENDENCY$"]

# Define and modify version number and package name here,
# Namespace packages are share same prefix: "ydk-models"
# Namespace packages share the same prefix: "ydk-models"
NAME = 'ydk'
VERSION = '0.7.2-dev'
VERSION = '_YDK_PYTHON_CORE_VERSION_'
INSTALL_REQUIREMENTS = ['pybind11>=2.1.1']


Expand Down
Binary file removed sdk/cpp/core/docsgen/icon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions sdk/cpp/core/docsgen/icon.ico
Binary file removed sdk/cpp/core/docsgen/logo.png
Binary file not shown.
1 change: 1 addition & 0 deletions sdk/cpp/core/docsgen/logo.png
2 changes: 1 addition & 1 deletion sdk/go/core/docsgen/Makefile
2 changes: 1 addition & 1 deletion sdk/go/core/docsgen/_static
2 changes: 1 addition & 1 deletion sdk/go/core/docsgen/icon.ico
2 changes: 1 addition & 1 deletion sdk/go/core/docsgen/logo.png
2 changes: 1 addition & 1 deletion sdk/go/core/docsgen/make.bat
2 changes: 1 addition & 1 deletion sdk/go/core/docsgen/ydk.models.rst
2 changes: 1 addition & 1 deletion sdk/python/core/docsgen/_static
Binary file removed sdk/python/core/docsgen/icon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions sdk/python/core/docsgen/icon.ico
Binary file removed sdk/python/core/docsgen/logo.png
Binary file not shown.
1 change: 1 addition & 0 deletions sdk/python/core/docsgen/logo.png
7 changes: 7 additions & 0 deletions sdk/version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"core": "0.7.1",
"ietf": "0.1.5",
"openconfig": "0.1.5",
"cisco_ios_xr": "6.3.2",
"cisco_ios_xe": "16.8.1"
}

0 comments on commit 16810ab

Please sign in to comment.