Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: tools/publish_pkg.py

Issue 11280238: Add ability to publish package without a pubspec. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a 4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file. 5 # BSD-style license that can be found in the LICENSE file.
6 # 6 #
7 # Script to push a package to pub. 7 # Script to push a package to pub.
8 # 8 #
9 # Usage: publish_pkg.py pkg_dir 9 # Usage: publish_pkg.py pkg_dir
10 #
11 # "pub" must be in PATH.
10 12
11 13
12 import os 14 import os
13 import os.path 15 import os.path
14 import re 16 import re
15 import shutil 17 import shutil
16 import sys 18 import sys
17 import subprocess 19 import subprocess
18 import tempfile 20 import tempfile
19 21
(...skipping 18 matching lines...) Expand all
38 40
39 def Main(argv): 41 def Main(argv):
40 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) 42 HOME = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
41 43
42 versionFile = os.path.join(HOME, 'tools', 'VERSION') 44 versionFile = os.path.join(HOME, 'tools', 'VERSION')
43 major = ReadVersion(versionFile, 'MAJOR') 45 major = ReadVersion(versionFile, 'MAJOR')
44 minor = ReadVersion(versionFile, 'MINOR') 46 minor = ReadVersion(versionFile, 'MINOR')
45 build = ReadVersion(versionFile, 'BUILD') 47 build = ReadVersion(versionFile, 'BUILD')
46 patch = ReadVersion(versionFile, 'PATCH') 48 patch = ReadVersion(versionFile, 'PATCH')
47 49
50 # bleeding_edge has a fixed version number of 0.1.x.y . Don't allow users
51 # to publish packages from bleeding_edge.
48 if major == 0 and minor <= 1: 52 if major == 0 and minor <= 1:
49 print 'Error: Do not run this script from a bleeding_edge checkout.' 53 print 'Error: Do not run this script from a bleeding_edge checkout.'
50 return -1 54 return -1
51 55
52 version = '%d.%d.%d+%d' % (major, minor, build, patch) 56 version = '%d.%d.%d+%d' % (major, minor, build, patch)
53 57
54 tmpDir = tempfile.mkdtemp() 58 tmpDir = tempfile.mkdtemp()
55 pkgName = argv[1].split('/').pop() 59 pkgName = argv[1].split('/').pop()
56 shutil.copytree(os.path.join(HOME, argv[1]),
57 os.path.join(tmpDir, pkgName))
58 60
59 # Add version to pubspec file.
60 pubspec = os.path.join(tmpDir, pkgName, 'pubspec.yaml') 61 pubspec = os.path.join(tmpDir, pkgName, 'pubspec.yaml')
61 pubspecFile = open(pubspec) 62
62 lines = pubspecFile.readlines() 63 if os.path.exists(os.path.join(HOME, argv[1], 'pubspec.yaml')):
63 pubspecFile.close() 64 #
64 pubspecFile = open(pubspec, 'w') 65 # If pubspec.yaml exists, add the SDK's version number if
65 foundVersion = False 66 # no version number is present.
66 for line in lines: 67 #
67 if line.startswith('version:'): 68 shutil.copytree(os.path.join(HOME, argv[1]),
68 foundVersion = True 69 os.path.join(tmpDir, pkgName))
69 if line.startswith('description:') and not foundVersion: 70 with open(pubspec) as pubspecFile:
71 lines = pubspecFile.readlines()
72 with open(pubspec, 'w') as pubspecFile:
73 foundVersion = False
74 inDependencies = False
75 for line in lines:
76 if line.startswith('dependencies:'):
77 inDependencies = True
78 elif line[0].isalpha():
79 inDependencies = False
80 if line.startswith('version:'):
81 foundVersion = True
82 if inDependencies:
83 #
84 # Within dependencies, don't print line that start with " sdk:"
85 # and strip out "{ sdk: package_name }".
86 #
87 if not line.startswith(' sdk:'):
88 line = re.sub(r'{(\s*)sdk:(\s+)([a-z0-9_]+)(\s*)}', '', line)
89 pubspecFile.write(line)
90 else:
91 pubspecFile.write(line)
92 if not foundVersion:
93 pubspecFile.write('\nversion: ' + version + '\n')
94 else:
95 #
96 # If there's a lib/ directory in the package, copy the package.
97 # Otherwise, move the package's contents to lib/.
98 #
99 if os.path.exists(os.path.join(HOME, argv[1], 'lib')):
100 shutil.copytree(os.path.join(HOME, argv[1]),
101 os.path.join(tmpDir, pkgName))
102 else:
103 os.makedirs(os.path.join(tmpDir, pkgName))
104 shutil.copytree(os.path.join(HOME, argv[1]),
105 os.path.join(tmpDir, pkgName, 'lib'))
106
107 # Create pubspec.yaml .
108 with open(pubspec, 'w') as pubspecFile:
109 pubspecFile.write('name: ' + pkgName + '_unsupported\n')
70 pubspecFile.write('version: ' + version + '\n') 110 pubspecFile.write('version: ' + version + '\n')
71 if not line.startswith(' sdk:'): 111 pubspecFile.write("description: >\n")
72 pubspecFile.write(line) 112 pubspecFile.write(' A completely unsupported clone of Dart SDK library\n' )
73 pubspecFile.close() 113 pubspecFile.write(' ' + argv[1] + ' . This package will change in\n')
74 114 pubspecFile.write(' unpredictable/incompatible ways without warning.\n')
115 pubspecFile.write('dependencies:\n')
116
75 # Replace '../*/pkg' imports and parts. 117 # Replace '../*/pkg' imports and parts.
76 for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)): 118 for root, dirs, files in os.walk(os.path.join(tmpDir, pkgName)):
77 for name in files: 119 for name in files:
78 if name.endswith('.dart'): 120 if name.endswith('.dart'):
79 ReplaceInFiles([os.path.join(root, name)], 121 ReplaceInFiles([os.path.join(root, name)],
80 [(r'(import|part)(\s+)(\'|")(\.\./)+pkg/', r'\1\2\3package:')]) 122 [(r'(import|part)(\s+)(\'|")(\.\./)+pkg/', r'\1\2\3package:')])
81 123
82 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub\n' 124 print 'publishing version ' + version + ' of ' + argv[1] + ' to pub.\n'
83 print tmpDir
84 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName)) 125 subprocess.call(['pub', 'publish'], cwd=os.path.join(tmpDir, pkgName))
85 shutil.rmtree(tmpDir) 126 shutil.rmtree(tmpDir)
86 127
87 if __name__ == '__main__': 128 if __name__ == '__main__':
88 sys.exit(Main(sys.argv)) 129 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698