Skip to content

Commit

Permalink
Adjusted version parsing logic to effectively set "development" and s…
Browse files Browse the repository at this point in the history
…imilar labels as an alias to grabbing the most recent pipeline version

This allows us to be able to request "pipeline@1.0.0.dev1" via "pipeline@development".
Additionally if "pipeline@development" does exist in the search path, it is considered as the most recent version.
  • Loading branch information
bryce-turner committed Oct 10, 2023
1 parent abd7397 commit 1d13aa3
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions jetstream/pipelines.py
Expand Up @@ -48,6 +48,7 @@ class Pipeline:
these: can be anything
"""

def __init__(self, path=None, validate=True):
if path is None:
path = os.getcwd()
Expand Down Expand Up @@ -141,7 +142,6 @@ def set_environment_variables(self):
os.environ[k] = v



def find_pipelines(*dirs):
"""Generator yields all pipelines in given directories. Any pipeline found will also
be searched for nested pipelines. """
Expand Down Expand Up @@ -170,21 +170,39 @@ def find_pipelines(*dirs):
yield from find_pipelines(path)


def parse_pipeline_version(version):
"""
Pipeline versions generally should not use epochs however if an epoch is used, then it
should be less than 999 as in other words that means we had 999 versioning format changes
https://peps.python.org/pep-0440/#version-epochs
For example an epoch is used to fix this sort order:
1.0 2013.10
1.1 2014.04
2.0 ---> 1!1.0
2013.10 1!1.1
2014.04 1!2.0
"""
if version in ["dev", "develop", "development", "latest"]:
return parse_version("999!9")
else:
return parse_version(version)


def get_pipeline(name, version=None, searchpath=None):
"""Get a pipeline by name and version(optional)"""
if searchpath is None:
searchpath = jetstream.settings['pipelines']['searchpath'].get()
searchpath = searchpath.split(':')

if version is None:
if version in [None, "dev", "develop", "development", "latest"]:
# Find all but then sort by version and return the latest
matches = []
for p in find_pipelines(*searchpath):
if p.name == name:
matches.append(p)

if matches:
s = sorted(matches, key=lambda p: parse_version(p.version))
s = sorted(matches, key=lambda p: parse_pipeline_version(p.version))
return s[-1]
else:
# Find a match with name and version
Expand All @@ -193,7 +211,6 @@ def get_pipeline(name, version=None, searchpath=None):
if p.name == name and parse_version(str(p.version)) == parse_version(str(version)):
return p


if version is None:
msg = f'Pipeline "{name}" not found!'
else:
Expand All @@ -214,4 +231,3 @@ def is_pipeline(path):
def list_pipelines(*dirs):
"""Returns all pipelines found as a list"""
return list(find_pipelines(*dirs))

0 comments on commit 1d13aa3

Please sign in to comment.