Comments (6)
I was able to resolve only by setting PYTHONPATH: PYTHONPATH=$PWD mkdocs build
Without setting it, I'll get ModuleNotFoundError: No module named 'app'
I've been able to replicate on a new python project:
.
├── app.py
├── docs
│ └── index.md
└── mkdocs.yml
mkdocs.yml:
site_name: My Docs
markdown_extensions:
- mkdocs-click
app.py
import click
@click.group()
def cli():
"""Main entrypoint."""
pass
@cli.command()
@click.option("-d", "--debug", help="Include debug output.")
def build(debug):
"""Build production assets."""
pass
docs\index.md
::: mkdocs-click
:module: app
:command: cli
from mkdocs-click.
I have the same error and I can't even get the example to run properly with fresh environments containing only the needed libraries.
I have tried it on Windows, and Ubuntu with Python 3.8 and 3.9.
Some strange behavior occurs if I paste in the examples to new Scripts I will get a page with no information beyond the Markdown references:
INFO - Building documentation...
INFO - [10:54:08] Reloading browsers
INFO - [10:54:08] Browser connected: http://127.0.0.1:8000/cli/
INFO - [10:54:08] Browser connected: http://127.0.0.1:8000/cli/
INFO - [10:54:08] Browser connected: http://127.0.0.1:8000/cli/
INFO - [10:55:38] Browser connected: http://127.0.0.1:8000/cli/
WARNING - [10:55:40] "GET / HTTP/1.1" code 404
INFO - [10:55:41] Browser connected: http://127.0.0.1:8000/cli/
But, if I hit return and save the cli.md
it will crash and give the No module named 'app'
error:
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'app'
from mkdocs-click.
SOLVED! 🎉
Tricky one. I was passing the group
name as the command
value, so it didn't recognized it.
After changing it to the [name].command()
it worked.
To illustrate:
@click.group(name="dataset") ==> I was using "dataset" on :command:
@click.pass_context
def cli_dataset(ctx):
pass
@cli_dataset.command(name="init", help="...") ==> But I actually needed to pass "cli_dataset"
@click.argument("dataset_id")
@click.option(
"--replace",
is_flag=True,
help="Whether to replace current metadata files",
)
.md
# Linha de comando (CLI)
::: mkdocs_click
:module: basedosdados.cli.cli ==> I also removed the `python-package`path here and put it on the .yml
:command: cli_dataset
:depth: 1
PS: I also changed mkdocs-click
to mkdocs_click
on mkdocs.yml
and requirements.txt
All the changes made are here: https://github.com/basedosdados/mais/pull/1134/files
from mkdocs-click.
Hi! Same issue here, from project basedosdados:
project structure:
python-package:
- basedosdados
- cli
- cli.py
docs:
- reference_api_cli.md
reference_api_cli.md
# Linha de comando (CLI)
::: mkdocs-click
:module: python-package.basedosdados.cli.cli
:command: dataset
$ mkdocs serve
:
ERROR - Error reading page 'reference_api_cli.md': No module named 'python-package'
Traceback (most recent call last):
File "/Users/fernandascovino/Projects/mais/.mais/bin/mkdocs", line 8, in <module>
sys.exit(cli())
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs/__main__.py", line 177, in serve_command
serve.serve(dev_addr=dev_addr, livereload=livereload, **kwargs)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 54, in serve
config = builder()
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 49, in builder
build(config, live_server=live_server, dirty=dirty)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs/commands/build.py", line 292, in build
_populate_page(file.page, config, files, dirty)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs/commands/build.py", line 174, in _populate_page
page.render(config, files)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs/structure/pages.py", line 174, in render
self.content = md.convert(self.markdown)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/markdown/core.py", line 261, in convert
self.lines = prep.run(self.lines)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs_click/_extension.py", line 48, in run
return list(
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs_click/_processing.py", line 35, in replace_blocks
yield from replace(**options)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs_click/_extension.py", line 52, in <lambda>
replace=lambda **options: replace_command_docs(has_attr_list=self._has_attr_list, **options),
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs_click/_extension.py", line 28, in replace_command_docs
command_obj = load_command(module, command)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs_click/_loader.py", line 15, in load_command
command = _load_obj(module, attribute)
File "/Users/fernandascovino/Projects/mais/.mais/lib/python3.9/site-packages/mkdocs_click/_loader.py", line 25, in _load_obj
mod = importlib.import_module(module)
File "/usr/local/Cellar/[email protected]/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'python-package'
Additionally, when I tried #37 solution (change from mkdocs-click
to mkdocs_click
) it doesn't give any error but also nothing shows up.
from mkdocs-click.
Hello! Have you both installed your package into the same environment as mkdocs
?
from mkdocs-click.
Setting PYTHONPATH
helps, but if I don't use relative import then it will cause ModuleNotFoundError
as well.
For example:
Structure
.
├── app.py
├── config.py
│ └── docs
│ └── index.md
└── mkdocs.yml
app.py
import click
from config import Config
@click.group()
def cli():
"""Main entrypoint."""
Config.get_env()
pass
@cli.command()
@click.option("-d", "--debug", help="Include debug output.")
def build(debug):
"""Build production assets."""
pass
If I do from .config import Config
then it will be okay. Is there any way to fix this?
from mkdocs-click.
Related Issues (20)
- Support asyncclick?
- Add to mkdocs wiki plugin overview HOT 1
- Multi-command modules not display correctly
- Is it possible to disable the repetition of --help option for every command? HOT 1
- Context/Options not being picked up with multi-commands
- Documentation only renders when there are at least two spaces at the end of .md file HOT 5
- Add option to exclude `hidden` commands, options and groups HOT 3
- Specify subcommands HOT 2
- Support for language-agnostic documentation HOT 2
- `remove_ascii_art` option doesn't work HOT 1
- Escape markdown special characters
- Respect clicks docstring `\b` and `\f` markers
- Generate the CLI documentation without first having to install the Python package
- Can't set up - getting `ModuleNotFoundError` HOT 1
- No output generated at all HOT 2
- Project Status HOT 7
- Indented ::: mkdocs-click blocks are not picked up
- Conflicts with front matter HOT 2
- Option to remove the top level header for the root command
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mkdocs-click.