Skip to content

Commit 6449b19

Browse files
committed
Added a CLI flag for __init__.py generation and improved package imports
1 parent 1f948ef commit 6449b19

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ Or use one of the scripts below:
109109

110110
Refer to the [documentation](https://nbrefactor.readthedocs.io/en/latest/) for the comprehensive commands' reference. Some basic usages are provided below.
111111

112+
Sample basic usage:
113+
```bash
114+
jupyter nbrefactor notebook.ipynb output_dir/
115+
```
116+
112117
## Command Line Interface
113118

114119
`nbrefactor` provides a CLI to easily refactor notebooks into a structured project hierarchy.
@@ -121,6 +126,13 @@ To use the CLI, run the following command:
121126
jupyter nbrefactor <notebook_path> <output_path> [OPTIONS]
122127
```
123128

129+
| Options | Description |
130+
|---------|----------------------------------------------------|
131+
| -i | Generate __init__.py files in package directories. |
132+
| -rp | Name of the root package (defaults to ".") |
133+
| -gp | Generate a plot of the module dependency tree |
134+
| -pf | Format of the plot (e.g., "pdf", "png") |
135+
124136
- `<notebook_path>`: Path to the Jupyter notebook file you want to refactor.
125137
- `<output_path>`: Directory where the refactored Python modules will be saved.
126138

@@ -129,8 +141,8 @@ jupyter nbrefactor <notebook_path> <output_path> [OPTIONS]
129141

130142
The following table lists the currently implemented Markdown commands and their functions.
131143

132-
| Command | Description |
133-
|---------------------------------|-----------------------------------------------------------------------------------------------------------|
144+
| Command | Description |
145+
|---------------------------------|------------------------------------------------------------------------------------------------------------|
134146
| `$ignore-package` | Ignores all modules/packages until a header with a depth less than or equal to the current one is reached. |
135147
| `$ignore-module` | Ignores a single module (may consist of multiple code cells). |
136148
| `$ignore-cell` | Ignores the next code cell regardless of type. |

docs/source/usage.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ CLI Arguments
3939
``-rp``, ``--root-package`` `str` ``"."``
4040
``-gp``, ``--generate-plot`` `flag` ``False``
4141
``-pf``, ``--plot-format`` `str` ``"pdf"``
42+
``-i``, ``--init-files`` `flag` ``False``
4243
================================== ========================================== ===============
4344

4445
Example Usages
@@ -67,3 +68,11 @@ Example Usages
6768
.. code-block:: bash
6869
6970
jupyter nbrefactor notebook.ipynb output_dir --generate-plot --plot-format png
71+
72+
5. **Generate __init__.py Files**: Refactor and generate __init__.py files in package directories:
73+
74+
.. code-block:: bash
75+
76+
jupyter nbrefactor notebook.ipynb output_dir --init-files
77+
78+
This is particularly useful when your refactored code uses relative imports between modules. The generated __init__.py files properly expose the modules, making Python's import system work correctly.

0 commit comments

Comments
 (0)