cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
613
Views
0
Helpful
3
Replies

Bundle resolver should support PEP440-compliant "version" fields

vadigreg
Cisco Employee
Cisco Employee

I just realised I can only set major.minor.patch into the JSON "version" field. I need one more number to be able to push autogenerated packages on my pypi instance. Bundle resolver should support PEP440-compliant "version" fields. Any chance to get this into the todo list?

 

Thanks,

Val

3 Replies 3

saalvare
Cisco Employee
Cisco Employee

What's the specific version string you're having issues with?  We've been creating and posting post releases for a long time w/o any issues.

 

https://pypi.org/project/ydk-models-ietf/#history

 

user@host:bundles(master %=)$ ls -1 *post*
cisco-ios-xe_16_6_1_post1.json
cisco-ios-xe_16_8_1_post1.json
cisco-ios-xr_6_5_1_post1.json
cisco-ios-xr_6_6_3_post1.json
ietf_0_1_5_post1.json
ietf_0_1_5_post2.json
openconfig_0_1_6_post1.json
user@host:bundles(master %=)$ pwd
/home/user/src/github.com/CiscoDevNet/ydk-gen/profiles/bundles
user@host:bundles(master %=)$

We also frequently generate private alpha releases with alpha version strings w/o any issues. 

With 0.8.4 I get this:

./generate.py -v --python --bundle /tmp/tmpc6kf25w3/ydk-models-wireless.json
YDKGEN_HOME not set. Assuming current directory is working directory.
Bundle Translator: Cloning from https://github.com/YangModels/yang.git --> /tmp/tmpaqaxfqew.yang
Bundle Translator: Removing folder /tmp/tmpaqaxfqew.yang
Resolving file tmp3f57l_6d.bundle --> /nobackup/pyats/projects/ydk-gen/gen-api/.cache/bundles
Traceback (most recent call last):
  File "./generate.py", line 492, in <module>
    output_directory = (generator.generate(options.bundle))
  File "/nobackup/pyats/projects/ydk-gen/ydkgen/__init__.py", line 93, in generate
    return self._generate_bundle(description_file)
  File "/nobackup/pyats/projects/ydk-gen/ydkgen/__init__.py", line 123, in _generate_bundle
    curr_bundle, all_bundles = resolver.resolve(tmp_file)
  File "/nobackup/pyats/projects/ydk-gen/ydkgen/resolver/bundle_resolver.py", line 304, in resolve
    root = Bundle(bundle_file, self.cached_models_dir, self.iskeyword)
  File "/nobackup/pyats/projects/ydk-gen/ydkgen/resolver/bundle_resolver.py", line 232, in __init__
    super().__init__(data['bundle'])
  File "/nobackup/pyats/projects/ydk-gen/ydkgen/resolver/bundle_resolver.py", line 84, in __init__
    self._version = Version(*tuple(data['version'].split('.')))
TypeError: __new__() takes 4 positional arguments but 5 were given

Version field in JSON file was:

17.4.0.20200702092331

I tested this with pep440.is_canonical() and it tells me it's well formed. Same error with the followings:

17.4.0.dev20200702092331
17.4.0.post20200702092331
0.1.5.post1

So looking at PEP 440 format should be:

[N!]N(.N)*[{a|b|rc}N][.postN][.devN]

and I believe there's an error on how the release segment "N(.N)*" is parsed.

 

Thanks,

Val

This apparently fixed my issue:

diff --git a/ydkgen/resolver/bundle_resolver.py b/ydkgen/resolver/bundle_resolver.py
index e3ad196e..05a8d18c 100644
--- a/ydkgen/resolver/bundle_resolver.py
+++ b/ydkgen/resolver/bundle_resolver.py
@@ -28,6 +28,7 @@ from shutil import rmtree, copy
 from collections import namedtuple, defaultdict
 from .bundle_translator import translate
 from ..common import YdkGenException
+from packaging.version import Version
 
 
 logger = logging.getLogger('ydkgen')
@@ -38,7 +39,6 @@ Local = namedtuple('Local', ['url'])
 Remote = namedtuple('Remote', ['url', 'commitid', 'path'])
 RepoDir = namedtuple('RepoDir', ['repo', 'dir'])
 Bundles = namedtuple('Bundles', ['curr_bundle', 'bundles'])
-Version = namedtuple('Version', ['major', 'minor', 'patch'])
 
 
 def nested_defaultdict():
@@ -81,8 +81,8 @@ class BundleDefinition(object):
 
     def __init__(self, data):
         self._name = data['name'].replace('-', '_')
-        self._version = Version(*tuple(data['version'].split('.')))
-        self._core_version = Version(*tuple(data['core-version'].split('.')))
+        self._version = Version(data['version'])
+        self._core_version = Version(data['core-version'])
         self._description = data['description'] if 'description' in data else str()
         self._long_description = data['long-description'] if 'long-description' in data else str()
 
@@ -108,12 +108,12 @@ class BundleDefinition(object):
     @property
     def str_version(self):
         """ Return string representation of version."""
-        return "%s.%s.%s" % self.version
+        return str(self.version)
 
     @property
     def str_core_version(self):
         """ Return string representation of ydk version."""
-        return "%s.%s.%s" % self.core_version
+        return str(self.core_version)
 
     @property
     def description(self):
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: