def create_plugin(distribution_repo_dir, plugin, version=None): with safe_open(os.path.join(distribution_repo_dir, plugin, 'setup.py'), 'w') as fp: fp.write(dedent(""" from setuptools import setup setup(name="{plugin}", version="{version}") """).format(plugin=plugin, version=version or '0.0.0')) packager = Packager(source_dir=os.path.join(distribution_repo_dir, plugin), install_dir=distribution_repo_dir) packager.run()
def execute(self): # We drive creation of setup.py distributions from the original target graph, grabbing codegen'd # sources when needed. We ignore PythonDistribution targets. def is_exported_python_target(t): return t.is_original and self.has_provides(t) and not is_local_python_dist(t) exported_python_targets = OrderedSet(t for t in self.context.target_roots if is_exported_python_target(t)) if not exported_python_targets: raise TaskError('setup-py target(s) must provide an artifact.') dist_dir = self.get_options().pants_distdir # NB: We have to create and then run in 2 steps so that we can discover all exported targets # in-play in the creation phase which then allows a tsort of these exported targets in the run # phase to ensure an exported target is, for example (--run="sdist upload"), uploaded before any # exported target that depends on it is uploaded. created = {} def create(exported_python_target): if exported_python_target not in created: self.context.log.info('Creating setup.py project for {}'.format(exported_python_target)) subject = self.derived_by_original.get(exported_python_target, exported_python_target) setup_dir, dependencies = self.create_setup_py(subject, dist_dir) created[exported_python_target] = setup_dir if self._recursive: for dep in dependencies: if is_exported_python_target(dep): create(dep) for exported_python_target in exported_python_targets: create(exported_python_target) interpreter = self.context.products.get_data(PythonInterpreter) python_dists = self.context.products.register_data(self.PYTHON_DISTS_PRODUCT, {}) for exported_python_target in reversed(sort_targets(list(created.keys()))): setup_dir = created.get(exported_python_target) if setup_dir: if not self._run: self.context.log.info('Running packager against {}'.format(setup_dir)) setup_runner = Packager(setup_dir, interpreter=interpreter) tgz_name = os.path.basename(setup_runner.sdist()) sdist_path = os.path.join(dist_dir, tgz_name) self.context.log.info('Writing {}'.format(sdist_path)) shutil.move(setup_runner.sdist(), sdist_path) safe_rmtree(setup_dir) python_dists[exported_python_target] = sdist_path else: self.context.log.info('Running {} against {}'.format(self._run, setup_dir)) split_command = safe_shlex_split(self._run) setup_runner = SetupPyRunner(setup_dir, split_command, interpreter=interpreter) setup_runner.run() python_dists[exported_python_target] = setup_dir
def execute(self): targets = [ target for target in self.context.target_roots if self.has_provides(target) ] if not targets: raise TaskError('setup-py target(s) must provide an artifact.') dist_dir = self.get_options().pants_distdir # NB: We have to create and then run in 2 steps so that we can discover all exported targets # in-play in the creation phase which then allows a tsort of these exported targets in the run # phase to ensure an exported target is, for example (--run="sdist upload"), uploaded before any # exported target that depends on it is uploaded. created = {} def create(target): if target not in created: self.context.log.info( 'Creating setup.py project for {}'.format(target)) setup_dir, dependencies = self.create_setup_py( target, dist_dir) created[target] = setup_dir if self._recursive: for dep in dependencies: if self.has_provides(dep): create(dep) for target in targets: create(target) executed = { } # Collected and returned for tests, processed target -> sdist|setup_dir. for target in reversed(sort_targets(created.keys())): setup_dir = created.get(target) if setup_dir: if not self._run: self.context.log.info( 'Running packager against {}'.format(setup_dir)) setup_runner = Packager(setup_dir) tgz_name = os.path.basename(setup_runner.sdist()) sdist_path = os.path.join(dist_dir, tgz_name) self.context.log.info('Writing {}'.format(sdist_path)) shutil.move(setup_runner.sdist(), sdist_path) safe_rmtree(setup_dir) executed[target] = sdist_path else: self.context.log.info('Running {} against {}'.format( self._run, setup_dir)) setup_runner = SetupPyRunner(setup_dir, self._run) setup_runner.run() executed[target] = setup_dir return executed
def execute(self): # We drive creation of setup.py distributions from the original target graph, grabbing codegen'd # sources when needed. We ignore PythonDistribution targets. def is_exported_python_target(t): return t.is_original and self.has_provides(t) and not is_local_python_dist(t) exported_python_targets = OrderedSet(t for t in self.context.target_roots if is_exported_python_target(t)) if not exported_python_targets: raise TaskError('setup-py target(s) must provide an artifact.') dist_dir = self.get_options().pants_distdir # NB: We have to create and then run in 2 steps so that we can discover all exported targets # in-play in the creation phase which then allows a tsort of these exported targets in the run # phase to ensure an exported target is, for example (--run="sdist upload"), uploaded before any # exported target that depends on it is uploaded. created = {} def create(exported_python_target): if exported_python_target not in created: self.context.log.info('Creating setup.py project for {}'.format(exported_python_target)) subject = self.derived_by_original.get(exported_python_target, exported_python_target) setup_dir, dependencies = self.create_setup_py(subject, dist_dir) created[exported_python_target] = setup_dir if self._recursive: for dep in dependencies: if is_exported_python_target(dep): create(dep) for exported_python_target in exported_python_targets: create(exported_python_target) interpreter = self.context.products.get_data(PythonInterpreter) python_dists = self.context.products.register_data(self.PYTHON_DISTS_PRODUCT, {}) for exported_python_target in reversed(sort_targets(list(created.keys()))): setup_dir = created.get(exported_python_target) if setup_dir: if not self._run: self.context.log.info('Running packager against {}'.format(setup_dir)) setup_runner = Packager(setup_dir, interpreter=interpreter) tgz_name = os.path.basename(setup_runner.sdist()) sdist_path = os.path.join(dist_dir, tgz_name) self.context.log.info('Writing {}'.format(sdist_path)) shutil.move(setup_runner.sdist(), sdist_path) safe_rmtree(setup_dir) python_dists[exported_python_target] = sdist_path else: self.context.log.info('Running {} against {}'.format(self._run, setup_dir)) split_command = safe_shlex_split(self._run) setup_runner = SetupPyRunner(setup_dir, split_command, interpreter=interpreter) setup_runner.run() python_dists[exported_python_target] = setup_dir
def execute(self): targets = [target for target in self.context.target_roots if self.has_provides(target)] if not targets: raise TaskError('setup-py target(s) must provide an artifact.') dist_dir = self.get_options().pants_distdir # NB: We have to create and then run in 2 steps so that we can discover all exported targets # in-play in the creation phase which then allows a tsort of these exported targets in the run # phase to ensure an exported target is, for example (--run="sdist upload"), uploaded before any # exported target that depends on it is uploaded. created = {} def create(target): if target not in created: self.context.log.info('Creating setup.py project for {}'.format(target)) setup_dir, dependencies = self.create_setup_py(target, dist_dir) created[target] = setup_dir if self._recursive: for dep in dependencies: if self.has_provides(dep): create(dep) for target in targets: create(target) executed = {} # Collected and returned for tests, processed target -> sdist|setup_dir. for target in reversed(sort_targets(created.keys())): setup_dir = created.get(target) if setup_dir: if not self._run: self.context.log.info('Running packager against {}'.format(setup_dir)) setup_runner = Packager(setup_dir) tgz_name = os.path.basename(setup_runner.sdist()) sdist_path = os.path.join(dist_dir, tgz_name) self.context.log.info('Writing {}'.format(sdist_path)) shutil.move(setup_runner.sdist(), sdist_path) safe_rmtree(setup_dir) executed[target] = sdist_path else: self.context.log.info('Running {} against {}'.format(self._run, setup_dir)) setup_runner = SetupPyRunner(setup_dir, self._run) setup_runner.run() executed[target] = setup_dir return executed
def run_one(self, target): dist_dir = self._config.getdefault('pants_distdir') chroot = Chroot(dist_dir, name=target.provides.name) self.write_contents(target, chroot) self.write_setup(target, chroot) target_base = '%s-%s' % (target.provides.name, target.provides.version) setup_dir = os.path.join(dist_dir, target_base) safe_rmtree(setup_dir) shutil.move(chroot.path(), setup_dir) if not self.old_options.run: print('Running packager against %s' % setup_dir) setup_runner = Packager(setup_dir) tgz_name = os.path.basename(setup_runner.sdist()) print('Writing %s' % os.path.join(dist_dir, tgz_name)) shutil.move(setup_runner.sdist(), os.path.join(dist_dir, tgz_name)) safe_rmtree(setup_dir) else: print('Running %s against %s' % (self.old_options.run, setup_dir)) setup_runner = SetupPyRunner(setup_dir, self.old_options.run) setup_runner.run()
def run_one(self, target): dist_dir = self._config.getdefault("pants_distdir") chroot = Chroot(dist_dir, name=target.provides.name) self.write_contents(target, chroot) self.write_setup(target, chroot) target_base = "%s-%s" % (target.provides.name, target.provides.version) setup_dir = os.path.join(dist_dir, target_base) safe_rmtree(setup_dir) os.rename(chroot.path(), setup_dir) if not self.options.run: print("Running packager against %s" % setup_dir) setup_runner = Packager(setup_dir) tgz_name = os.path.basename(setup_runner.sdist()) print("Writing %s" % os.path.join(dist_dir, tgz_name)) os.rename(setup_runner.sdist(), os.path.join(dist_dir, tgz_name)) safe_rmtree(setup_dir) else: print("Running %s against %s" % (self.options.run, setup_dir)) setup_runner = SetupPyRunner(setup_dir, self.options.run) setup_runner.run()
def run_one(self, target): dist_dir = self.get_options().pants_distdir chroot = Chroot(dist_dir, name=target.provides.name) self.write_contents(target, chroot) self.write_setup(target, chroot) target_base = '%s-%s' % (target.provides.name, target.provides.version) setup_dir = os.path.join(dist_dir, target_base) safe_rmtree(setup_dir) shutil.move(chroot.path(), setup_dir) if not self._run: self.context.log.info('Running packager against %s' % setup_dir) setup_runner = Packager(setup_dir) tgz_name = os.path.basename(setup_runner.sdist()) self.context.log.info('Writing %s' % os.path.join(dist_dir, tgz_name)) shutil.move(setup_runner.sdist(), os.path.join(dist_dir, tgz_name)) safe_rmtree(setup_dir) else: self.context.log.info('Running %s against %s' % (self._run, setup_dir)) setup_runner = SetupPyRunner(setup_dir, self._run) setup_runner.run()
def execute(self): # We operate on the target roots, except that we replace codegen targets with their # corresponding synthetic targets, since those have the generated sources that actually # get published. Note that the "provides" attributed is copied from the original target # to the synthetic target, so that the latter can be used as a direct stand-in for the # former here. preliminary_targets = set(t for t in self.context.target_roots if self.has_provides(t)) targets = set(preliminary_targets) for t in self.context.targets(): # A non-codegen target has derived_from equal to itself, so we check is_original # to ensure that the synthetic targets take precedence. # We check that the synthetic target has the same "provides" as the original, because # there are other synthetic targets in play (e.g., resources targets) to which this # substitution logic must not apply. if (t.derived_from in preliminary_targets and not t.is_original and self.has_provides(t) and t.provides == t.derived_from.provides): targets.discard(t.derived_from) targets.add(t) if not targets: raise TaskError('setup-py target(s) must provide an artifact.') dist_dir = self.get_options().pants_distdir # NB: We have to create and then run in 2 steps so that we can discover all exported targets # in-play in the creation phase which then allows a tsort of these exported targets in the run # phase to ensure an exported target is, for example (--run="sdist upload"), uploaded before any # exported target that depends on it is uploaded. created = {} def create(target): if target not in created: self.context.log.info( 'Creating setup.py project for {}'.format(target)) setup_dir, dependencies = self.create_setup_py( target, dist_dir) created[target] = setup_dir if self._recursive: for dep in dependencies: if self.has_provides(dep): create(dep) for target in targets: create(target) executed = { } # Collected and returned for tests, processed target -> sdist|setup_dir. for target in reversed(sort_targets(created.keys())): setup_dir = created.get(target) if setup_dir: if not self._run: self.context.log.info( 'Running packager against {}'.format(setup_dir)) setup_runner = Packager(setup_dir) tgz_name = os.path.basename(setup_runner.sdist()) sdist_path = os.path.join(dist_dir, tgz_name) self.context.log.info('Writing {}'.format(sdist_path)) shutil.move(setup_runner.sdist(), sdist_path) safe_rmtree(setup_dir) executed[target] = sdist_path else: self.context.log.info('Running {} against {}'.format( self._run, setup_dir)) setup_runner = SetupPyRunner(setup_dir, self._run) setup_runner.run() executed[target] = setup_dir return executed
def execute(self): # We operate on the target roots, except that we replace codegen targets with their # corresponding synthetic targets, since those have the generated sources that actually # get published. Note that the "provides" attributed is copied from the original target # to the synthetic target, so that the latter can be used as a direct stand-in for the # former here. preliminary_targets = set(t for t in self.context.target_roots if self.has_provides(t)) targets = set(preliminary_targets) for t in self.context.targets(): # A non-codegen target has derived_from equal to itself, so we check is_original # to ensure that the synthetic targets take precedence. # We check that the synthetic target has the same "provides" as the original, because # there are other synthetic targets in play (e.g., resources targets) to which this # substitution logic must not apply. if (t.derived_from in preliminary_targets and not t.is_original and self.has_provides(t) and t.provides == t.derived_from.provides): targets.discard(t.derived_from) targets.add(t) if not targets: raise TaskError('setup-py target(s) must provide an artifact.') dist_dir = self.get_options().pants_distdir # NB: We have to create and then run in 2 steps so that we can discover all exported targets # in-play in the creation phase which then allows a tsort of these exported targets in the run # phase to ensure an exported target is, for example (--run="sdist upload"), uploaded before any # exported target that depends on it is uploaded. created = {} def create(target): if target not in created: self.context.log.info('Creating setup.py project for {}'.format(target)) setup_dir, dependencies = self.create_setup_py(target, dist_dir) created[target] = setup_dir if self._recursive: for dep in dependencies: if self.has_provides(dep): create(dep) for target in targets: create(target) interpreter = self.context.products.get_data(PythonInterpreter) python_dists = self.context.products.register_data(self.PYTHON_DISTS_PRODUCT, {}) for target in reversed(sort_targets(created.keys())): setup_dir = created.get(target) if setup_dir: if not self._run: self.context.log.info('Running packager against {}'.format(setup_dir)) setup_runner = Packager(setup_dir, interpreter=interpreter) tgz_name = os.path.basename(setup_runner.sdist()) sdist_path = os.path.join(dist_dir, tgz_name) self.context.log.info('Writing {}'.format(sdist_path)) shutil.move(setup_runner.sdist(), sdist_path) safe_rmtree(setup_dir) python_dists[target] = sdist_path else: self.context.log.info('Running {} against {}'.format(self._run, setup_dir)) setup_runner = SetupPyRunner(setup_dir, self._run, interpreter=interpreter) setup_runner.run() python_dists[target] = setup_dir