@@ -31,20 +31,43 @@ autopypath
3131 :target: https://github.com/astral-sh/ruff
3232 :alt: Ruff
3333
34+ Table of Contents
35+ -----------------
36+ - `Usage <https://python-autopypath.readthedocs.io/en/latest/usage.html >`_
37+ - `Configuration <https://python-autopypath.readthedocs.io/en/latest/configuration.html >`_
38+ - `Public API <https://python-autopypath.readthedocs.io/en/latest/public_api.html >`_
39+ - `Contributing <https://python-autopypath.readthedocs.io/en/latest/contributing.html >`_
40+ - `Code of Conduct <https://python-autopypath.readthedocs.io/en/latest/code_of_conduct.html >`_
41+
3442What is autopypath?
3543-------------------
3644
3745**autopypath ** is a library that simplifies the management of the Python module
38- search path (`sys.path `) for testing and development environments.
46+ search path (`` sys.path ` `) for testing and development environments.
3947
40- It automatically detects your project root (via `.git `, `pyproject.toml `, etc.)
41- and intelligently adds source directories to `sys.path ` at runtime.
48+ It automatically detects your project root (via `.git <https://git-scm.com/ >`_,
49+ `pyproject.toml <https://python-poetry.org/docs/pyproject/ >`_, etc.)
50+ and intelligently adds source directories to ``sys.path `` at runtime.
51+
52+ It *does not * read ``.env `` files to derive
53+ `PYTHONPATH <https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH >`_ because
54+ the semantics cannot be consistently interpreted across different operating systems.
55+
56+ For example, consider ``PYTHONPATH=src:test;lib ``:
57+
58+ * On POSIX, ``PYTHONPATH `` is separated by ``: `` → ``["src", "test;lib"] ``
59+ * On Windows, ``PYTHONPATH `` is separated by ``; `` → ``["src:test", "lib"] ``
60+ * And the intent may have been ``["src", "test", "lib"] ``
61+
62+ All of those interpretations are "reasonable", so autopypath avoids guessing
63+ what was meant and instead uses ``pyproject.toml `` or ``autopypath.toml `` for configuration.
4264
4365The Problem it Solves
4466~~~~~~~~~~~~~~~~~~~~~
4567
4668In active development, **builds are often broken. **
47- Standard test runners (like `pytest ` or `tox `) often refuse to start if they
69+ Standard test runners (like `pytest <https://docs.pytest.org/en/stable/ >`_ or
70+ `tox <https://tox.wiki/ >`_) often refuse to start if they
4871cannot import the entire package, or if the package hasn't been re-installed
4972into the virtual environment after a structural change.
5073
@@ -55,19 +78,10 @@ into the virtual environment after a structural change.
5578- Other parts of the test suite are failing due to ongoing refactoring.
5679
5780It is not a replacement for `virtual environments <https://docs.python.org/3/library/venv.html >`_,
58- but a resilience tool. It dynamically fixes "Module Not Found" errors on load, allowing you to
59- debug a specific file without needing the entire project ecosystem to be in a perfect,
81+ but a resilience tool. It mitigates path-related `` ModuleNotFoundError `` errors,
82+ allowing you to debug a specific file without needing the entire project ecosystem to be in a perfect,
6083deployable state.
6184
62- Documentation
63- -------------
64-
65- - `Usage <https://python-autopypath.readthedocs.io/en/latest/usage.html >`_
66- - `Configuration <https://python-autopypath.readthedocs.io/en/latest/configuration.html >`_
67- - `Public API <https://python-autopypath.readthedocs.io/en/latest/public_api.html >`_
68- - `Contributing <https://python-autopypath.readthedocs.io/en/latest/contributing.html >`_
69- - `Code of Conduct <https://python-autopypath.readthedocs.io/en/latest/code_of_conduct.html >`_
70-
7185Installation
7286------------
7387
@@ -90,44 +104,47 @@ Installing from Source
90104 Development Installation
91105~~~~~~~~~~~~~~~~~~~~~~~~
92106
93- For development purposes, you can install `autopypath ` in editable mode. To make this easier, a `bootstrap.py ` script is provided.
107+ For development purposes, you can install ``autopypath `` in editable mode.
108+ To make this easier, a ``bootstrap.py `` script is provided.
94109
95110.. code-block :: shell
96111
97112 git clone https://github.com/JerilynFranz/python-autopypath.git
98113 cd python-autopypath
99114 python3 bootstrap.py
100- source .venv/bin/activate # On Windows use ` .venv\Scripts\activate`
115+ source .venv/bin/activate # On Windows use .venv\Scripts\activate
101116
102117 This script will:
103- 1. Set up the development environment (`uv ` sync).
104- 2. Install `autopypath ` in editable mode.
118+
119+ 1. Set up the development environment (``uv sync --all-groups ``).
120+ 2. Install ``autopypath `` in editable mode.
1051213. Install Git hooks for pre-commit checks.
106- 4. Install development tools like `tox ` , `sphinx ` , and `ruff ` .
122+ 4. Install development tools like `tox < https://tox.wiki/ >`_ , `sphinx < https://www.sphinx-doc.org/en/master/ >`_ , and `ruff < https://ruff.rs/ >`_ .
107123
108124Usage
109125-----
110126
111- Simply import `autopypath ` at the top of your test script. It will
112- automatically detect the project root and adjust `sys.path ` accordingly
113- (by default adding `src `, `lib `, `src/tests `, and `tests ` directories if they exist).
127+ Simply import `` autopypath ` ` at the top of your test script. It will
128+ automatically detect the project root and adjust `` sys.path ` ` accordingly
129+ (by default adding `` src `` , `` lib `` , `` src/tests `` , and `` tests ` ` directories if they exist).
114130
115- It does not add '.' to `sys.path ` by default to avoid conflicts with subdirectories
131+ It does not add `` . `` to `` sys.path ` ` by default to avoid conflicts with subdirectories
116132that are NOT intended to be packages, but if you want to include the repo root
117- directory, you can configure it via `pyproject.toml ` or `autopypath.toml `.
133+ directory, you can configure it
134+ via `pyproject.toml <https://python-poetry.org/docs/pyproject/ >`_ or ``autopypath.toml ``.
118135
119- Here is an example ` tests/my_test_script.py ` :
136+ Here is an example:
120137
121138.. code-block :: python
122139
123- import autopypath # <--- This line magics the sys.path
140+ import autopypath # <--- This line adjusts the sys.path
124141 import pytest
125142
126143 # Now these imports work without installing the package
127144 import mypackage.my_module
128145
129146 if __name__ == ' __main__' :
130- pytest.main([__file__ ])
147+ pytest.main([__file__ ])
131148
132149 You can now run this file directly:
133150
@@ -138,33 +155,29 @@ You can now run this file directly:
138155 Configuration
139156-------------
140157
141- autopypath automatically detects `pyproject.toml `. You can configure it
142- by adding a ``[tool.autopypath] `` section.
158+ autopypath automatically detects `pyproject.toml < https://python-poetry.org/docs/pyproject/ >`_.
159+ You can configure it by adding a ``[tool.autopypath] `` section.
143160
144161**Example `pyproject.toml`: **
145162
146163.. code-block :: toml
147164
148- [tool.autopypath]
149- paths = ["lib", "src/tests", ".", "src"]
165+ [tool.autopypath]
166+ paths = ["lib", "src/tests", ".", "src"]
150167
151- If you do not use `pyproject.toml `, you can create an `autopypath.toml ` file
152- either in your root directory or in subdirectories such as `src ` or `tests `
168+ If you do not use `` pyproject.toml `` , you can create an `` autopypath.toml `` file
169+ either in your root directory or in subdirectories such as `` src `` or `` tests ` `
153170and it will be detected automatically. This can be useful for monorepos or
154- multi-package repositories and allows customization of `sys.path ` per sub-project
171+ multi-package repositories and allows customization of `` sys.path ` ` per sub-project
155172or for detection of the project root in non-standard layouts.
156173
157174**Example `autopypath.toml`: **
158175
159176.. code-block :: toml
160177
161- [tool.autopypath]
162- paths = ["src", "src/lib", "tests"]
163- repo_markers = {".git" = "dir"}
164-
178+ [tool.autopypath]
179+ paths = ["src", "src/lib", "tests"]
180+ repo_markers = {".git" = "dir"}
181+
165182 This file can be placed in the root of your project or in any directory
166183that is a parent of your test scripts (but still inside the repo).
167-
168- You can use it to customize which directories are added to `sys.path `, or to
169- specify custom repository markers for detecting the project root as well
170- as other settings affecting path resolution behavior.
0 commit comments