def setUp(self): self.d = TemporaryDirectory() fname = os.path.join(self.d.name, 'pubspec.yaml') with open(fname, 'wt') as f: f.write(VALID_PUBSPEC_CONTENT) self.pubspec = PubspecFile.from_path(fname) self.pub_package = PubPackage(self.pubspec)
def run(self, message): ''' @message The message that will be displayed to the user when collecting their input. ''' v = self.window.active_view() project = PubPackage.from_path(v.file_name()) if not project: _logger.debug('no pubspec.yaml found - aborting') info = ErrorPanel() info.write('Could not locate pubspec.yaml file for: {}\n' .format(v.file_name())) info.write('Cannot run Polymer command.') info.show() return if not project.has_dependency('polymer'): _logger.debug('no polymer dep found - aborting') info = ErrorPanel() info.write("Polymer isn't a dependency in this project.") info.write('Cannot run Polymer command.') info.show() return if not project.path_to_web: _logger.debug('creating web directory') project.make_top_level_dir('web') self.window.show_input_panel(message, '', self.on_done, None, None)
def dart_pub_get(self, path_to_pubspec): path_to_pubspec = path_to_pubspec or self.window.active_view( ).file_name() if not path_to_pubspec: _logger.error('no pubspec specified for "pub get"') return package = PubPackage.from_path(path_to_pubspec) if not package: _logger.info( "can't 'pub get' if project hasn't a pubspec.yaml file") return path_to_pubspec = package.pubspec.path sdk = SDK() if not sdk.path_to_pub: _logger.debug("`sdk.path_to_pub` missing; aborting pub") return self.execute( **{ 'working_dir': os.path.dirname(path_to_pubspec), 'cmd': [sdk.path_to_pub, 'get'], 'preamble': 'Running pub get...\n', })
def dart_pub_get(self, path_to_pubspec): path_to_pubspec = path_to_pubspec or self.window.active_view().file_name() if not path_to_pubspec: _logger.error('no pubspec specified for "pub get"') return package = PubPackage.from_path(path_to_pubspec) if not package: _logger.info("can't 'pub get' if project hasn't a pubspec.yaml file") return path_to_pubspec = package.pubspec.path sdk = SDK() if not sdk.path_to_pub: _logger.debug("`sdk.path_to_pub` missing; aborting pub") return self.execute( **{ "working_dir": os.path.dirname(path_to_pubspec), "cmd": [sdk.path_to_pub, "get"], "preamble": "Running pub get...\n", } )
def on_done(self, name): view = self.window.active_view() project = PubPackage.from_path(view.file_name()) cmd = "pub run polymer:new_entry {}".format(name) # TODO(guillermooo): we cannot access the ouput panel used by exec. # This means we cannot print friendlier status output. Replace exec # with our own async process execution so that we can control its # output panel. self.execute(cmd, project.pubspec.parent)
def get_target_path(self, view): '''Returns the path in which the generated files belong. ''' project = PubPackage.from_path(view.file_name()) target_path = project.path_to_web if project.is_prefix(prefix=project.path_to_web, path=view.file_name()): target_path = os.path.dirname(view.file_name()) return target_path
class Test_PubPackage(unittest.TestCase): def setUp(self): self.d = TemporaryDirectory() fname = os.path.join(self.d.name, 'pubspec.yaml') with open(fname, 'wt') as f: f.write(VALID_PUBSPEC_CONTENT) self.pubspec = PubspecFile.from_path(fname) self.pub_package = PubPackage(self.pubspec) def tearDown(self): self.d.cleanup() def testInitCanFail(self): p = PubPackage.from_path('???') self.assertEqual(p, None) def testInitCanSucceed(self): p = PubPackage.from_path(self.d.name) self.assertEqual(self.d.name, p.pubspec.parent) def testCanMakeTopLevelDir(self): self.assertFalse(os.path.exists(os.path.join(self.d.name, 'web'))) self.pub_package.make_top_level_dir('web') self.assertTrue(os.path.exists(os.path.join(self.d.name, 'web'))) def test_is_prefix_RaisesExceptionIfPrefixIsNone(self): self.assertRaises(AssertionError, self.pub_package.is_prefix, None, 'bar') def test_is_prefix_RaisesExceptionIfPathIsNone(self): self.assertRaises(AssertionError, self.pub_package.is_prefix, 'foo', None) def test_is_prefix_RaisesExceptionIfPathAndPrefixAreNone(self): self.assertRaises(AssertionError, self.pub_package.is_prefix, None, None) def test_is_prefix_ReturnsFalseIfPathIsNotPrefixed(self): self.assertFalse(self.pub_package.is_prefix('foo', 'bar')) def test_is_prefix_ReturnsTrueIfPathIsPrefixed(self): # TODO(guillermooo): Perhaps this should return false; we probably want to know # whether 'path' is a subdir of 'prefix', not just a suffix. self.assertTrue(self.pub_package.is_prefix('foo', 'foobar')) def test_is_prefix_ReturnsTrueIfPathIsSubdirOfPrefix(self): # TODO(guillermooo): Perhaps this should return false; we probably want to know # whether 'path' is a subdir of 'prefix', not just a suffix. prefix = os.path.join('foo', 'bar') path = os.path.join('foo', 'bar', 'baz') self.assertTrue(self.pub_package.is_prefix(prefix, path)) def test__get_top_level_dir_ReturnsNoneIfPathDoesNotExist(self): self.assertEqual(self.pub_package._get_top_level_dir('web'), None) def test__get_top_level_dir_CanSucceed(self): self.pub_package.make_top_level_dir('web') self.assertTrue(os.path.exists(os.path.join(self.pub_package.pubspec.parent, 'web'))) def testKnowsAboutWellKnownPaths(self): self.pub_package.make_top_level_dir('web') self.pub_package.make_top_level_dir('bin') self.pub_package.make_top_level_dir('test') self.pub_package.make_top_level_dir('tool') self.pub_package.make_top_level_dir('benchmark') self.pub_package.make_top_level_dir('doc') self.pub_package.make_top_level_dir('example') self.pub_package.make_top_level_dir('lib') self.assertTrue(os.path.exists(self.pub_package.path_to_web)) self.assertTrue(os.path.exists(self.pub_package.path_to_bin)) self.assertTrue(os.path.exists(self.pub_package.path_to_test)) self.assertTrue(os.path.exists(self.pub_package.path_to_tool)) self.assertTrue(os.path.exists(self.pub_package.path_to_benchmark)) self.assertTrue(os.path.exists(self.pub_package.path_to_doc)) self.assertTrue(os.path.exists(self.pub_package.path_to_example)) self.assertTrue(os.path.exists(self.pub_package.path_to_lib))
def testInitCanSucceed(self): p = PubPackage.from_path(self.d.name) self.assertEqual(self.d.name, p.pubspec.parent)
def testInitCanFail(self): p = PubPackage.from_path('???') self.assertEqual(p, None)