ryneeverett / mkcodes

A command-line utility for pulling code blocks out of markdown files.
Apache License 2.0
15 stars 7 forks source link

Python API #2

Open sebastian-philipp opened 5 years ago

sebastian-philipp commented 5 years ago

I ended up using something like

import distutils
import subprocess

from setuptools import setup

class MkCodesCommand(distutils.cmd.Command):
  """A custom command to run MkCodes."""

  description = 'run mkcodes'
  user_options:list = []

  def initialize_options(self):
      pass

  def finalize_options(self):
      pass

  def run(self):
    """Run command."""
    subprocess.check_call('mkcodes --github --output rook_ceph_client/tests/test_{name}.py README.md'.split())

setup(
    ...
    cmdclass={
        'mkcodes': MkCodesCommand,
    },
)

would be nice to have a better recipe / integration provided as an example

ryneeverett commented 4 years ago

I've modified the tests to use click's CliRunner class rather than subprocess, which should work for your use case as well. Perhaps we should expose a thin wrapper around CliRunner.