Skip to content

Commit e72508a

Browse files
authored
Fix bug in metaflow version when public=True (#2539)
`metaflow_version.get_version(public=True)` doesn't return the public version if executed within a metaflow step. This is because, we return the version in the `INFO` file directly without any parsing. This PR addresses that. Flow to reproduce the issue: ```python from metaflow import FlowSpec, step, conda class HelloFlow(FlowSpec): @conda() @step def start(self): from metaflow import metaflow_version version = metaflow_version.get_version(public=True) print(f"Metaflow version: {version}") self.next(self.end) @step def end(self): print("HelloFlow is all done.") if __name__ == "__main__": HelloFlow() ```
1 parent 4c54ab4 commit e72508a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

metaflow/metaflow_version.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ def read_info_version():
133133
return None
134134

135135

136+
def make_public_version(version_string):
137+
"""
138+
Takes a complex version string and returns a public, PEP 440-compliant version.
139+
It removes local version identifiers (+...) and development markers (-...).
140+
"""
141+
base_version = version_string.split("+", 1)[0]
142+
public_version = base_version.split("-", 1)[0]
143+
return public_version
144+
145+
136146
def get_version(public=False):
137147
"""Tracks the version number.
138148
@@ -170,6 +180,11 @@ def get_version(public=False):
170180
) # Version info is cached in INFO file; includes extension info
171181

172182
if version:
183+
# If we have a version from the INFO file, use it directly.
184+
# However, if we are asked for a public version, we parse it to make sure
185+
# that no local information is included.
186+
if public:
187+
version = make_public_version(version)
173188
_version_cache[public] = version
174189
return version
175190

0 commit comments

Comments
 (0)