Skip to content

Commit

Permalink
Feature 651 version set in one place (dtcenter#663)
Browse files Browse the repository at this point in the history
* added __version__ to metplus that reads from docs/version

* read version file, use 'latest' tag of MET Docker image for released versions, i.e. v4.0, use 'develop' tag of MET Docker image for all others, i.e. feature branches, beta releases, etc.

* read version, use release version of data volume from dtcenter/metplus-data if testing a release, i.e. main_vX.Y, otherwise use metplus-data-dev

* fixed call to dirname

* Update conf.py

* [ci-skip] changed version to major release to test docker build hook changes

* removed v from version check because version file does not include v at the beginning

* changed version back -- setting version to 4.0 successfully used 'latest' for MET image tag

* print version number to screen before anything else is done in master_metplus

* set met version to X+6.Y for maj/min release, changed version to test [ci-skip]

* put met version computation into a script that is called by the build hooks file, changed version file back

* removed commented line that should not be needed

* remove duplicate tag that was commented out

* fixed call to get_met_version in build hooks file

* Removed accidentally commented line

* Made comment more clear

[ci-skip]

* Fixed typo in comment

* use develop as version in docs if not a major/minor/bugfix release

* Update ci/travis_jobs/get_data_volumes.py

Yes, this makes sense. The docker data volumes DO NOT change for bugfix versions. So we should look for docker data volumes tagged as vX.Y, not vX.Y.Z

Co-authored-by: George McCabe <[email protected]>

* Update ci/docker/hooks/get_met_version

Accepting suggestion to switch the MET DockerHub tag from $major"."$minor to $major"."$minor"-latest"

Co-authored-by: johnhg <[email protected]>
  • Loading branch information
georgemccabe and JohnHalleyGotway authored Oct 15, 2020
1 parent 883ab0d commit 80c54c5
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 26 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ Model Evaluation Tools Plus (METplus) Repository
[![Travis build status](https://travis-ci.org/DTCenter/METplus.svg?branch=develop)](https://travis-ci.org/DTCenter/METplus)
[![Latest Docs](https://img.shields.io/badge/docs-latest-brightgreen.svg)](https://dtcenter.github.io/METplus/)

<!--
[![Travis DTCenter_develop build_status](https://travis-ci.org/DTCenter/METplus.svg?branch=develop)](https://travis-ci.org/DTCenter/METplus)
-->

Welcome to the METplus GitHub repository hosted to the community through
the Developmental Testbed Center (DTC).
Expand Down
6 changes: 5 additions & 1 deletion ci/docker/hooks/build
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/bin/bash

docker build -t $IMAGE_NAME --build-arg SOURCE_BRANCH=$SOURCE_BRANCH --build-arg MET_BRANCH=develop --build-arg DO_GIT_CLONE=true .
# get version, use develop or X+6.Y for MET_BRANCH
met_branch=`$(dirname $DOCKERFILE_PATH)/hooks/get_met_version`

echo $met_branch
docker build -t $IMAGE_NAME --build-arg SOURCE_BRANCH=$SOURCE_BRANCH --build-arg MET_BRANCH=$met_branch --build-arg DO_GIT_CLONE=true .
14 changes: 14 additions & 0 deletions ci/docker/hooks/get_met_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# get version, use develop or X+6.Y for MET_BRANCH
version_file=$(dirname $DOCKERFILE_PATH)/../../docs/version

if cat $version_file | egrep -q '[0-9.]+$'; then
let major=$(cut -d '.' -f1 $version_file)+6
minor=$(cut -d '.' -f2 $version_file )
met_branch=$major"."$minor"-latest"
else
met_branch=develop
fi

echo $met_branch
17 changes: 15 additions & 2 deletions ci/travis_jobs/get_data_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@

from docker_utils import docker_get_volumes_last_updated

# this should be set to develop or a release version, i.e. vX.Y
METPLUS_VERSION = 'develop'
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
os.pardir,
os.pardir,)))

from metplus import __version__

# METPLUS_VERSION should be set to develop or a release version, i.e. vX.Y
# if version is set to X.Y without -betaZ or -dev, use that version
# otherwise use develop
if len(__version__.split('-')) == 1:
# only get first 2 numbers from version, i.e. X.Y.Z will use vX.Y
METPLUS_VERSION = f"v{'.'.join(__version__.split('.')[:2])}"

else:
METPLUS_VERSION = 'develop'

MODEL_APP_NAMES = ('met_tool_wrapper',
'convection_allowing_models',
Expand Down
23 changes: 17 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,34 @@
import os
from datetime import datetime
import sys
sys.path.insert(0, os.path.abspath('../ush'))
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
os.pardir)))
sys.path.append(os.path.abspath("./_ext"))
print(sys.path)

from metplus import __version__

# -- Project information -----------------------------------------------------

project = 'METplus'

author = 'UCAR/NCAR, NOAA, CSU/CIRA, and CU/CIRES'

# the stable version, displayed on front page of PDF
version = 'develop'
verinfo = version

# The full version, including alpha/beta/rc tags
release = f'{version}'
# i.e. 4.0-beta1-dev
release = __version__

# the stable version, displayed on front page of PDF extract X.Y version
# from release by splitting the string into a list
# using - as the delimeter, then getting the 1st item of the list
# if version is beta, rc, and/or dev then set version to develop for
# the documentation built for develop (not release)
if len(release.split('-')) > 1:
version = 'develop'
else:
version = f"{release.split('-')[0]}"

verinfo = version

release_year = '2020'

Expand Down
12 changes: 12 additions & 0 deletions metplus/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os

def get_metplus_version():
version_file = os.path.abspath(os.path.join(os.path.dirname(__file__),
os.pardir,
'docs',
'version'))
with open(version_file, 'r') as file_handle:
version = file_handle.read().strip()
return version

__version__ = get_metplus_version()
17 changes: 3 additions & 14 deletions metplus/util/met_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from . import time_util as time_util
from . import metplus_check

from .. import get_metplus_version

"""!@namespace met_util
@brief Provides Utility functions for METplus.
"""
Expand Down Expand Up @@ -86,7 +88,7 @@

def pre_run_setup(config_inputs):
from . import config_metplus
version_number = get_version_number()
version_number = get_metplus_version()
print(f'Starting METplus v{version_number}')

# Read config inputs and return a config instance
Expand Down Expand Up @@ -1022,19 +1024,6 @@ def get_lead_sequence(config, input_dict=None):

return out_leads

def get_version_number():
# read version file and return value
# get top level of METplus - parents[2] is 3 directories up from current file
# which is in ush/metplus/util
metplus_base = str(Path(__file__).parents[2])
version_file_path = os.path.join(metplus_base,
'docs',
'version')

with open(version_file_path, 'r') as version_file:
return version_file.read()


def round_0p5(val):
"""! Round to the nearest point five (ie 3.3 rounds to 3.5, 3.1
rounds to 3.0) Take the input value, multiply by two, round to integer
Expand Down
5 changes: 5 additions & 0 deletions ush/master_metplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from metplus.util import metplus_check
from metplus.util import pre_run_setup, run_metplus, post_run_cleanup
from metplus.util import get_process_list
from metplus import __version__ as metplus_version

'''!@namespace master_metplus
Main script the processes all the tasks in the PROCESS_LIST
Expand Down Expand Up @@ -73,6 +74,10 @@ def get_config_inputs_from_command_line():
invalid flag was provided, i.e. -a.
@returns list of config inputs
"""

# output version that is run to screen
print('Running METplus %s' % metplus_version)

# if not arguments were provided, print usage and exit
if len(sys.argv) < 2:
usage()
Expand Down

0 comments on commit 80c54c5

Please sign in to comment.