Skip to contentSkip to conversation

python: Adds instructions to the manifest file

PATCH New Alejandro Enedino Hernandez Samaniego 1 participant 2 messages Nov 17, 2018 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/2 python3: Adds instructions to the manifest file

While there is a bit of documentation regarding building a new manifest file for python, it seems that users usually only read the manifest file.

The manifest file is in JSON format which doesn't allow comments, hence why instructions were initially put elsewhere.

This patch hacks the call to open the JSON manifest file by using a marker to trick it into reading only part of the file as the manifest itself, and keep the other part as comments, which contain instructions for the user to run the create_manifest task after an upgrade or when adding a new package.

---
 .../python/python3-native_3.5.6.bb                 |  6 +-
 .../python/python3/create_manifest3.py             | 20 ++++-
 .../python/python3/python3-manifest.json           | 94 +++++++++++++++++++++-
 meta/recipes-devtools/python/python3_3.5.6.bb      |  6 +-
 4 files changed, 119 insertions(+), 7 deletions(-)
meta/recipes-devtools/python/python3-native_3.5.6.bb +5 -1
index d5953cf..e6ae2d3 100644
@@ -84,7 +84,11 @@ python(){
     import json
     pythondir = d.getVar('THISDIR',True)
     with open(pythondir+'/python3/python3-manifest.json') as manifest_file:
-        python_manifest=json.load(manifest_file)
+        manifest_str =  manifest_file.read()
+        json_start = manifest_str.find('# EOC') + 6
+        manifest_file.seek(json_start)
+        manifest_str = manifest_file.read()
+        python_manifest = json.loads(manifest_str)
 
     rprovides = d.getVar('RPROVIDES').split()
 
meta/recipes-devtools/python/python3/create_manifest3.py +17 -3
index fddb23cd..f7d4587 100644
@@ -22,7 +22,7 @@
 #
 #
 # This way we will create a new manifest from the data structure that was built during
-# this process, ont this new manifest each package will contain specifically only
+# this process, on this new manifest each package will contain specifically only
 # what it needs to run.
 #
 # There are some caveats which we try to deal with, such as repeated files on different
@@ -36,7 +36,7 @@
 # Tha method to handle cached files does not work when a module includes a folder which
 # itself contains the pycache folder, gladly this is almost never the case.
 #
-# Author: Alejandro Enedino Hernandez Samaniego "aehs29" <[email protected]>
+# Author: Alejandro Enedino Hernandez Samaniego "aehs29" <aehs29 at gmail dot com>
 
 
 import sys
@@ -78,9 +78,21 @@ def isCached(item):
     else:
         return False
 
+def prepend_comments(comments, json_manifest):
+    with open(json_manifest, 'r+') as manifest:
+        json_contents = manifest.read()
+        manifest.seek(0, 0)
+        manifest.write(comments + json_contents)
+
 # Read existing JSON manifest
 with open('python3-manifest.json') as manifest:
-    old_manifest = json.load(manifest, object_pairs_hook=collections.OrderedDict)
+    # The JSON format doesn't allow comments so we hack the call to keep the comments using a marker
+    manifest_str =  manifest.read()
+    json_start = manifest_str.find('# EOC') + 6 # EOC + \n
+    manifest.seek(0)
+    comments = manifest.read(json_start)
+    manifest_str = manifest.read()
+    old_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
 
 #
 # First pass to get core-package functionality, because we base everything on the fact that core is actually working
@@ -402,6 +414,8 @@ with open('python3-manifest.json.new','w') as outfile:
     json.dump(new_manifest,outfile, indent=4)
     outfile.write('\n')
 
+prepend_comments(comments,'python3-manifest.json.new')
+
 if (repeated):
     error_msg = '\n\nERROR:\n'
     error_msg += 'The following files are repeated (contained in more than one package),\n'
meta/recipes-devtools/python/python3/python3-manifest.json +92 -2

103 lines not on this page · raw message

meta/recipes-devtools/python/python3_3.5.6.bb +5 -1
index 31f8ead..1e6ca0e 100644
@@ -264,7 +264,11 @@ python(){
     bb.parse.mark_dependency(d, filename)
 
     with open(filename) as manifest_file:
-        python_manifest=json.load(manifest_file, object_pairs_hook=collections.OrderedDict)
+        manifest_str =  manifest_file.read()
+        json_start = manifest_str.find('# EOC') + 6
+        manifest_file.seek(json_start)
+        manifest_str = manifest_file.read()
+        python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
 
     include_pycs = d.getVar('INCLUDE_PYCS')
 
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/2 python: Adds instructions to the manifest file

In reply to a message not in the archive

While there is a bit of documentation regarding building a new manifest file for python, it seems that users usually only read the manifest file.

The manifest file is in JSON format which doesn't allow comments, hence why instructions were initially put elsewhere.

This patch hacks the call to open the JSON manifest file by using a marker to trick it into reading only part of the file as the manifest itself, and keep the other part as comments, which contain instructions for the user to run the create_manifest task after an upgrade or when adding a new package.

---
 .../python/python-native_2.7.15.bb                 |  6 +-
 .../python/python/create_manifest2.py              | 21 ++++-
 .../python/python/python2-manifest.json            | 92 +++++++++++++++++++++-
 meta/recipes-devtools/python/python_2.7.15.bb      |  6 +-
 4 files changed, 118 insertions(+), 7 deletions(-)
meta/recipes-devtools/python/python-native_2.7.15.bb +5 -1
index 7c491fa..de35104 100644
@@ -69,7 +69,11 @@ python(){
     import json
     pythondir = d.getVar('THISDIR',True)
     with open(pythondir+'/python/python2-manifest.json') as manifest_file:
-        python_manifest=json.load(manifest_file)
+        manifest_str =  manifest_file.read()
+        json_start = manifest_str.find('# EOC') + 6
+        manifest_file.seek(json_start)
+        manifest_str = manifest_file.read()
+        python_manifest = json.loads(manifest_str)
 
     rprovides = d.getVar('RPROVIDES').split()
 
meta/recipes-devtools/python/python/create_manifest2.py +17 -4
index 8799999..b674865 100644
@@ -22,7 +22,7 @@
 #
 #
 # This way we will create a new manifest from the data structure that was built during
-# this process, ont this new manifest each package will contain specifically only
+# this process, on this new manifest each package will contain specifically only
 # what it needs to run.
 #
 # There are some caveats which we try to deal with, such as repeated files on different
@@ -30,7 +30,7 @@
 # Its also important to note that this method only works for python files, and shared
 # libraries. Static libraries, header files and binaries need to be dealt with manually.
 #
-# Author: Alejandro Enedino Hernandez Samaniego "aehs29" <[email protected]>
+# Author: Alejandro Enedino Hernandez Samaniego "aehs29" <aehs29 at gmail dot com>
 
 
 import sys
@@ -62,10 +62,21 @@ def isFolder(value):
   else:
     return False
 
+def prepend_comments(comments, json_manifest):
+    with open(json_manifest, 'r+') as manifest:
+        json_contents = manifest.read()
+        manifest.seek(0, 0)
+        manifest.write(comments + json_contents)
+
 # Read existing JSON manifest
 with open('python2-manifest.json') as manifest:
-  old_manifest = json.load(manifest, object_pairs_hook=collections.OrderedDict)
-
+    # The JSON format doesn't allow comments so we hack the call to keep the comments using a marker
+    manifest_str =  manifest.read()
+    json_start = manifest_str.find('# EOC') + 6 # EOC + \n
+    manifest.seek(0)
+    comments = manifest.read(json_start)
+    manifest_str = manifest.read()
+    old_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
 
 # First pass to get core-package functionality, because we base everything on the fact that core is actually working
 # Not exactly the same so it should not be a function
@@ -277,3 +288,5 @@ for key in new_manifest:
 # Create the manifest from the data structure that was built
 with open('python2-manifest.json.new','w') as outfile:
     json.dump(new_manifest,outfile, indent=4)
+
+prepend_comments(comments,'python2-manifest.json.new')
meta/recipes-devtools/python/python/python2-manifest.json +91 -1

99 lines not on this page · raw message

meta/recipes-devtools/python/python_2.7.15.bb +5 -1
index dd969d8..c22c762 100644
@@ -198,7 +198,11 @@ python(){
     bb.parse.mark_dependency(d, filename)
 
     with open(filename) as manifest_file:
-        python_manifest=json.load(manifest_file, object_pairs_hook=collections.OrderedDict)
+        manifest_str =  manifest_file.read()
+        json_start = manifest_str.find('# EOC') + 6
+        manifest_file.seek(json_start)
+        manifest_str = manifest_file.read()
+        python_manifest = json.loads(manifest_str, object_pairs_hook=collections.OrderedDict)
 
     include_pycs = d.getVar('INCLUDE_PYCS')
 
Signature · 1 line
2.7.4