title: How can I override a setuptools command from a setup_require dependancy?
body: <h3>Context:</h3>
  
  <p>In order to be able to translate GNU gettext po files into mo ones at build time in setuptools, I have created a subclass of <code>setuptools.command.build_py</code> that compiles them (through a copy of pymsgfmt) before calling its base class:</p>
  
  <pre><code>from setuptools.command.build_py import build_py as _build_py
  
  class build_py(_build_py):
      parent = _build_py
      def run(self):
          self.compile_po_files()  # internal implementation
          self.parent.run(self)
  
      def get_outputs(self):  # overriden to produce a correct list of installed files
          build_mo = self.get_finalized_command("build_mo")
          return _build_py.get_outputs(self) + self.outputs
  </code></pre>
  
  <p>Then I have only to declare it in the <code>cmdclass</code> parameter of <code>setup</code>: </p>
  
  <pre><code>setup(
      ...
      cmdclass = {"build_py", mypgk.build_py},
  )
  </code></pre>
  
  <p>So far, so good, when my module is installed and imported in the <code>setup.py</code> script, the build phase of setuptools correctly process my po files.</p>
  
  <h3>Problem:</h3>
  
  <p>The goal would be to allow a simple installation of a source distribution with pip. Things look nice, because pip takes care of any dependency provided they are declared in a <code>install_requires</code>, or <code>setup_requires</code> parameter. And this is where the chicken and egg problem lies: the dependancy are installed when <code>setup.py</code> is runned, but it cannot run without <code>mypkg</code> being first installed.</p>
  
  <h3>Current research:</h3>
  
  <p>I have tried to use the magic <code>entry_points</code> to declare the <code>build_py</code> override in <code>mypkg</code> <code>setup.py</code> script:</p>
  
  <pre><code>...
  entry_points = {
      "distutils.commands": [
          "build_py = mypkg:build_py",
          ],
  }
  </code></pre>
  
  <p>but it has no effects, while I can declare a working new <code>build_mo</code> command that way:</p>
  
  <pre><code>entry_points = {
      "distutils.commands": [
          "build_mo = mypkg:build_py",
          ],
  }
  </code></pre>
  
  <p>Long story short, <code>python setup.py build_mo</code> calls my override, while <code>python setup.py build_py</code> calls setuptools version.</p>
  
  <h3>Question:</h3>
  
  <p>Why does my attempt of overriding the <code>build_py</code> command with an <code>entry_points</code> declaration not work, and how could I do it?</p>