adamtheturtle / doccmd

Run commands against code blocks in Markdown or reStructuredText documentation
MIT License
3 stars 0 forks source link

Running doccmd over a directory #128

Closed my1e5 closed 3 weeks ago

my1e5 commented 1 month ago

Found your tool from your comment on the "Apply ruff to markdown code blocks" issue. It's really nice! Very interested in adopting it into my workflow.

One feature which would be nice is the ability run doccmd over a folder. For example, I have a docs/ folder.

$ doccmd --language=python --command="mypy" docs/
Usage: doccmd [OPTIONS] [FILE_PATHS]...
Try 'doccmd --help' for help.

Error: Invalid value for '[FILE_PATHS]...': File 'docs/' is a directory.

In fact, do you know how I could run doccmd over a directory currently? Without specifying all the files individually?

adamtheturtle commented 1 month ago

Thank you @my1e5 for giving doccmd a go and for making an issue! You are the first known user who is not myself, and I don't have this use case, so all help figuring out what to do is welcome.

What I do is equivalent to:

$ doccmd --language=python --command="mypy" docs/**/*.rst

or

$ doccmd --language=python --command="mypy" docs/**/*.md

Does that solve your use case?

If not, or if you still think that it is best to have doccmd take a directory - do you think that doccmd should recursively search for files? With which extensions? (.md, .rst, configurable? if, configurable, how would you like to configure that set of file extensions?).

my1e5 commented 1 month ago

Happy to provide feedback ☺️

So my use case is I have a docs/ folder in my project which I would like to run ruff check over. Ultimately I'd like to set up a "check-docs" command which I can then run locally and in my CI.

I guess coming to this as a ruff/mypy user, I'm used to these tools taking a list of files or directories as an argument.

$ ruff check --help
Run Ruff on the given files or directories (default)

Usage: ruff check [OPTIONS] [FILES]...

Arguments:
  [FILES]...  List of files or directories to check [default: .]
$ mypy --help
usage: mypy [-h] [-v] [-V] [more options; see below]
            [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]

Mypy is a program that will type check your Python code.

Pass in any files or folders you want to type check. Mypy will
recursively traverse any provided folders to find .py files:

    $ mypy my_program.py my_src_folder

So I think it would feel very natural if doccmd could be used in a similar fashion.

I don't know much about .rst files, my docs folder is exclusively .md files. But I suppose recursively looking for both .rst and .md files would be fine? As mypy does - "Mypy will recursively traverse any provided folders to find .py files:".

I like how mypy and ruff both have an exclude setting you can configure in your pyproject.toml file. (see https://docs.astral.sh/ruff/settings/#exclude)

 [tool.mypy]
 exclude = ["tests"]

Maybe doccmd could have a table for configuring settings in a doccmd.toml file (I know this is not a Python-exclusive tool), which falls back to pyproject.toml if that file is not present?

 [tool.doccmd]
 exclude = ["docs/foo"]

Also I tried

$ doccmd --language=python --command="ruff check" docs/**/*.md

And it seems to only run on the first folder within my docs directory and then the first file within that folder.

EDIT -> Oh, it might be because the ruff check commnad errors out and then doesn't run on any more files?

adamtheturtle commented 1 month ago

Thank you @my1e5 for your comment and your edit. Have you figured out the answer to the question in your edit? If so, is your use case problem resolved (even if the interface is not ideal)?

my1e5 commented 1 month ago

I found this method which works

$ find docs/  -type f -name "*.md" -exec doccmd --language=python --command="ruff check"  {} \;
adamtheturtle commented 1 month ago

Some open questions:

adamtheturtle commented 3 weeks ago

A potential plan for this:

adamtheturtle commented 3 weeks ago

@my1e5 doccmd 2024.11.06.1 is now available. This allows you to pass in directories, and has options documented in https://doccmd.readthedocs.io/en/latest/commands.html#doccmd or in doccmd --help such as --myst-extension, --exclude and --max-depth to configure the recursion.

Please give this a go and leave a comment / create issues.