Repository: mitmproxy/pdoc

Issue:
pdoc does not work if "." is specified while specifying the directory
#### Problem Description
When I specify . while running the pdoc command like `python -m pdoc .` it throws an error `ValueError: No modules found matching spec: .` I want to run pdoc from this directory because my `pyproject.toml` resides in there and I want to specify the command for generating the docs in there. I found a turnaround for this by specifying it like `python -m pdoc ..\folder-name`. It works but if my folder name has a `-` in the name it fails with the same error.

#### Steps to reproduce the behavior:
1. Create a project with `pyproject.toml` file.
2. Add the pdoc command using poetry poe extension

```
[tool.poe.tasks.generate-docs-localhost]
cmd = "python -m pdoc .
```

3. Observe the error `ValueError: No modules found matching spec: .`

#### System Information
Paste the output of "pdoc --version" here.
15.0.1

Discussion:
@mhils: What does your directory structure look like? 
Typically your pyproject.toml directory does not have a `__init__.py` and is not a module.@anshuman-goel: My folder directory closely follows [Azure function directory structure](https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=get-started%2Casgi%2Capplication-level&pivots=python-mode-decorators#folder-structure). It is like below:

```
<project.root>/
 | - .venv/
 | - .vscode/
 | - function_app.py
 | - additional_functions.py
 | - __init__.py
 | - additional_folder/
 | | - __init__.py
 | | - other_files.py
 | - tests/
 | | - test_my_function.py
 | - .funcignore
 | - host.json
 | - local.settings.json
 | - requirements.txt
 | - pyproject.toml
```@mhils: `pdoc .` should work now in line with how the rest of pdoc works. :)@anshuman-goel: Hi @mhils, it looks like the issue still persists.

There appears to be a problem in [walk_specs](https://github.com/mhils/pdoc/blob/75863d3abac0843a4ca0f3d562db2bc21d6ba6dc/pdoc/extract.py#L110). Additionally, the current PR test case doesn’t seem to account for cases where the folder name contains a `.`.

For reference, I’m testing this on Windows with version 15.0.4.
@mhils: > There appears to be a problem in [walk_specs](https://github.com/mhils/pdoc/blob/75863d3abac0843a4ca0f3d562db2bc21d6ba6dc/pdoc/extract.py#L110). Additionally, the current PR test case doesn’t seem to account for cases where the folder name contains a `.`.

By putting a `__init__.py` file in your root directory, you declare it to be a module. Module names in Python are lowercase ASCII + underscores. Don't put dots in your module name.

Solution patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3337d33..8cb2e50 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@
 
 - Include included HTML headers in the ToC by default by enabling markdown2's `mixed=True` option of the `header-ids` extra
   (#806, @mrossinek)
+- Make `pdoc .` work to document the module in the current directory.
+  ([#813](https://github.com/mitmproxy/pdoc/pull/813), @mhils)
 
 ## 2025-04-21: pdoc 15.0.3
 
diff --git a/pdoc/extract.py b/pdoc/extract.py
index 255f6ec..62952ff 100644
--- a/pdoc/extract.py
+++ b/pdoc/extract.py
@@ -112,7 +112,7 @@ def parse_spec(spec: Path | str) -> str:
                     raise ModuleNotFoundError
         except pdoc.docstrings.AnyException:
             # Module does not exist, use local file.
-            spec = pspec
+            spec = pspec.resolve()
         else:
             # Module does exist. We now check if the local file/directory is the same (e.g. after pip install -e),
             # and emit a warning if that's not the case.


Test patch:
diff --git a/test/test_extract.py b/test/test_extract.py
index 639b3ab..4571265 100644
--- a/test/test_extract.py
+++ b/test/test_extract.py
@@ -100,6 +100,10 @@ def test_parse_spec(monkeypatch):
     assert str(here / "testdata") in sys.path
     sys.path = p
 
+    monkeypatch.chdir(here / "testdata" / "demopackage" / "subpackage")
+    assert parse_spec(".") == "demopackage.subpackage"
+    assert parse_spec("..") == "demopackage"
+
 
 def test_parse_spec_mod_and_dir(tmp_path, monkeypatch):
     """Test that we display a warning when both a module and a local directory exist with the provided name."""