]> jfr.im git - yt-dlp.git/blobdiff - devscripts/make_issue_template.py
[cleanup] Consistent style for file heads
[yt-dlp.git] / devscripts / make_issue_template.py
index 37cb0d4ee11987ae690b5f61306b5de1517f0a02..54043ef4ee797c3b3d92da91d49ad11ba303110b 100644 (file)
@@ -1,10 +1,26 @@
-#!/usr/bin/env python
-from __future__ import unicode_literals
+#!/usr/bin/env python3
+
+# Allow direct execution
+import os
+import sys
+
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
 
-import io
 import optparse
 
 
+def read(fname):
+    with open(fname, encoding='utf-8') as f:
+        return f.read()
+
+
+# Get the version without importing the package
+def read_version(fname):
+    exec(compile(read(fname), fname, 'exec'))
+    return locals()['__version__']
+
+
 def main():
     parser = optparse.OptionParser(usage='%prog INFILE OUTFILE')
     options, args = parser.parse_args()
@@ -12,18 +28,10 @@ def main():
         parser.error('Expected an input and an output filename')
 
     infile, outfile = args
+    with open(outfile, 'w', encoding='utf-8') as outf:
+        outf.write(
+            read(infile) % {'version': read_version('yt_dlp/version.py')})
 
-    with io.open(infile, encoding='utf-8') as inf:
-        issue_template_tmpl = inf.read()
-
-    # Get the version from youtube_dlc/version.py without importing the package
-    exec(compile(open('youtube_dlc/version.py').read(),
-                 'youtube_dlc/version.py', 'exec'))
-
-    out = issue_template_tmpl % {'version': locals()['__version__']}
-
-    with io.open(outfile, 'w', encoding='utf-8') as outf:
-        outf.write(out)
 
 if __name__ == '__main__':
     main()