Skip to content

docs: removes code link backticks #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .codegen/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ prompts/
jupyter/
.venv/
codegen-system-prompt.txt
*.txt
*.pyc

# Python cache files
__pycache__/
Expand Down
43 changes: 43 additions & 0 deletions .codegen/codemods/no_link_backticks/no_link_backticks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import codegen
from codegen import Codebase


@codegen.function("no-link-backticks")
def run(codebase: Codebase):
import re

# Define the pattern for Markdown links with backticks in the link text
link_pattern = re.compile(r"\[([^\]]*`[^\]]*`[^\]]*)\]\(([^)]+)\)")

# Iterate over all .mdx files in the codebase
for file in codebase.files(extensions=["mdx"]):
if file.extension == ".mdx":
new_content = file.content

# Find all markdown links with backticks in link text
matches = link_pattern.finditer(new_content)

for match in matches:
# Original link text with backticks
original_text = match.group(1)

# Remove backticks from the link text
new_text = original_text.replace("`", "")

# Replace the link in content
new_content = new_content.replace(match.group(0), f"[{new_text}]({match.group(2)})")

# Update file content if changes were made
if new_content != file.content:
file.edit(new_content)

# Commit all changes
codebase.commit()


if __name__ == "__main__":
print("Parsing codebase...")
codebase = Codebase("./")

print("Running function...")
codegen.run(run)
2 changes: 1 addition & 1 deletion docs/blog/fixing-import-loops.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Not all import cycles are problematic! Some cycles using dynamic imports can wor

PyTorch prevents most circular import issues through dynamic imports which can be seen through the `import_symbol.is_dynamic` property. If any edge in a strongly connected component is dynamic, runtime conflicts are typically resolved.

However, we discovered an import loop worth investigating between [`flex_decoding.py`](https://github.com/pytorch/pytorch/blob/main/torch/_inductor/kernel/flex_decoding.py) and [`flex_attention.py`](https://github.com/pytorch/pytorch/blob/main/torch/_inductor/kernel/flex_attention.py):
However, we discovered an import loop worth investigating between [flex_decoding.py](https://github.com/pytorch/pytorch/blob/main/torch/_inductor/kernel/flex_decoding.py) and [flex_attention.py](https://github.com/pytorch/pytorch/blob/main/torch/_inductor/kernel/flex_attention.py):

<img src="/images/problematic-import-loop.png" alt="Invalid import loop example" />

Expand Down
4 changes: 2 additions & 2 deletions docs/building-with-codegen/dependencies-and-usages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Codegen pre-computes dependencies and usages for all symbols in the codebase, en

Codegen provides two main ways to track relationships between symbols:

- [`.dependencies`](/api-reference/core/Symbol#dependencies) / [`.get_dependencies(...)`](/api-reference/core/Symbol#get-dependencies) - What symbols does this symbol depend on?
- [`.usages`](/api-reference/core/Symbol#usages) / [`.usages(...)`](/api-reference/core/Symbol#usages) - Where is this symbol used?
- [.dependencies](/api-reference/core/Symbol#dependencies) / [.get_dependencies(...)](/api-reference/core/Symbol#get-dependencies) - What symbols does this symbol depend on?
- [.usages](/api-reference/core/Symbol#usages) / [.usages(...)](/api-reference/core/Symbol#usages) - Where is this symbol used?

Dependencies and usages are inverses of each other. For example, given the following input code:

Expand Down
14 changes: 7 additions & 7 deletions docs/building-with-codegen/editables-and-behaviors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ This guide explains the key behaviors and how to use them effectively.

## Core Behaviors

- [`HasName`](/api-reference/core/HasName): For elements with names (functions, classes, variables)
- [`HasValue`](/api-reference/core/HasValue): For elements with values (variables, parameters)
- [`HasBlock`](/api-reference/core/HasBlock): For elements containing code blocks (functions, classes)
- [`Editable`](/api-reference/core/Editable): For elements that can be safely modified ([learn more](/building-with-codegen/the-editable-api))
- [HasName](/api-reference/core/HasName): For elements with names (functions, classes, variables)
- [HasValue](/api-reference/core/HasValue): For elements with values (variables, parameters)
- [HasBlock](/api-reference/core/HasBlock): For elements containing code blocks (functions, classes)
- [Editable](/api-reference/core/Editable): For elements that can be safely modified ([learn more](/building-with-codegen/the-editable-api))

## Working with Names

The [`HasName`](/api-reference/core/HasName) behavior provides APIs for working with named elements:
The [HasName](/api-reference/core/HasName) behavior provides APIs for working with named elements:

```python
# Access the name
Expand All @@ -35,7 +35,7 @@ name_node = function.get_name()

## Working with Values

The [`HasValue`](/api-reference/core/HasValue) behavior provides APIs for elements that have values:
The [HasValue](/api-reference/core/HasValue) behavior provides APIs for elements that have values:

```python
# Access the value
Expand All @@ -52,7 +52,7 @@ if variable.value is not None:

## Working with Code Blocks

The [`HasBlock`](/api-reference/core/HasBlock) behavior provides APIs for elements containing code:
The [HasBlock](/api-reference/core/HasBlock) behavior provides APIs for elements containing code:

```python
# Access the code block
Expand Down
20 changes: 10 additions & 10 deletions docs/building-with-codegen/files-and-directories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,20 @@ parent = dir.parent # Parent directory

## Editing Files Directly

Files themselves are [`Editable`](/api-reference/core/Editable.mdx) objects, just like Functions and Classes.
Files themselves are [Editable](/api-reference/core/Editable.mdx) objects, just like Functions and Classes.

<Tip>
Learn more about the [Editable API](/building-with-codegen/the-editable-api).
</Tip>

This means they expose many useful operations, including:

- [`File.search`](/api-reference/core/File#search) - Search for all functions named "main"
- [`File.edit`](/api-reference/core/File#edit) - Edit the file
- [`File.replace`](/api-reference/core/File#replace) - Replace all instances of a string with another string
- [`File.insert_before`](/api-reference/core/File#insert-before) - Insert text before a specific string
- [`File.insert_after`](/api-reference/core/File#insert-after) - Insert text after a specific string
- [`File.remove`](/api-reference/core/File#remove) - Remove a specific string
- [File.search](/api-reference/core/File#search) - Search for all functions named "main"
- [File.edit](/api-reference/core/File#edit) - Edit the file
- [File.replace](/api-reference/core/File#replace) - Replace all instances of a string with another string
- [File.insert_before](/api-reference/core/File#insert-before) - Insert text before a specific string
- [File.insert_after](/api-reference/core/File#insert-after) - Insert text after a specific string
- [File.remove](/api-reference/core/File#remove) - Remove a specific string

```python
# Get a file
Expand All @@ -230,7 +230,7 @@ file.insert_after("def end():\npass")
file.remove()
```

You can frequently do bulk modifictions via the [`.edit(...)`](/api-reference/core/Editable#edit) method or [`.replace(...)`](/api-reference/core/File#replace) method.
You can frequently do bulk modifictions via the [.edit(...)](/api-reference/core/Editable#edit) method or [.replace(...)](/api-reference/core/File#replace) method.

<Note>
Most useful operations will have bespoke APIs that handle edge cases, update
Expand All @@ -239,7 +239,7 @@ You can frequently do bulk modifictions via the [`.edit(...)`](/api-reference/co

## Moving and Renaming Files

Files can be manipulated through methods like [`File.update_filepath()`](/api-reference/core/File#update-filepath), [`File.rename()`](/api-reference/core/File#rename), and [`File.remove()`](/api-reference/core/File#remove):
Files can be manipulated through methods like [File.update_filepath()](/api-reference/core/File#update-filepath), [File.rename()](/api-reference/core/File#rename), and [File.remove()](/api-reference/core/File#remove):

```python
# Move/rename a file
Expand All @@ -263,7 +263,7 @@ for file in codebase.files:

## Directories

[`Directories`](/api-reference/core/Directory) expose a similar API to the [File](/api-reference/core/File.mdx) class, with the addition of the `subdirectories` property.
[Directories](/api-reference/core/Directory) expose a similar API to the [File](/api-reference/core/File.mdx) class, with the addition of the `subdirectories` property.

```python
# Get a directory
Expand Down
14 changes: 7 additions & 7 deletions docs/building-with-codegen/git-operations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ sidebarTitle: "Git Operations"
icon: "code-branch"
---

Many workflows require Git operations. Codegen provides a high-level API for common Git operations through the [`Codebase`](/api-reference/core/Codebase) class, including:
Many workflows require Git operations. Codegen provides a high-level API for common Git operations through the [Codebase](/api-reference/core/Codebase) class, including:

- [`Codebase.git_commit(...)`](/api-reference/core/Codebase#git_commit)
- [`Codebase.checkout(...)`](/api-reference/core/Codebase#checkout)
- [Codebase.git_commit(...)](/api-reference/core/Codebase#git_commit)
- [Codebase.checkout(...)](/api-reference/core/Codebase#checkout)

## Committing Changes to Git

You can commit changes to Git using the [`Codebase.git_commit(...)`](/api-reference/core/Codebase#git_commit):
You can commit changes to Git using the [Codebase.git_commit(...)](/api-reference/core/Codebase#git_commit):

```python
# Make some changes and call `commit()` to sync them to disk
Expand All @@ -31,8 +31,8 @@ if commit:

<Note>
`git_commit` will only commit changes that have been synced to the filesystem
by calling [`Codebase.commit()`](/api-reference/core/Codebase#commit). See
[`Commit and Reset`](/building-with-codegen/commit-and-reset) for more
by calling [Codebase.commit()](/api-reference/core/Codebase#commit). See
[Commit and Reset](/building-with-codegen/commit-and-reset) for more
details.
</Note>

Expand All @@ -53,7 +53,7 @@ if current:

## Checking Out Branches and Commits

The [`Codebase.checkout(...)`](/api-reference/core/Codebase#checkout) method allows you to switch between branches and commits.
The [Codebase.checkout(...)](/api-reference/core/Codebase#checkout) method allows you to switch between branches and commits.

This will automatically re-parse the codebase to reflect the new state.

Expand Down
22 changes: 11 additions & 11 deletions docs/building-with-codegen/language-support.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ TSCodebaseType = Codebase[

Every code element has both a Python and TypeScript implementation that inherits from a common base class. For example:

- [`Function`](/api-reference/core/Function)
- [`PyFunction`](/api-reference/python/PyFunction)
- [`TSFunction`](/api-reference/typescript/TSFunction)
- [`Class`](/api-reference/core/Class)
- [`PyClass`](/api-reference/python/PyClass)
- [`TSClass`](/api-reference/typescript/TSClass)
- [`Import`](/api-reference/core/Import)
- [`PyImport`](/api-reference/python/PyImport)
- [`TSImport`](/api-reference/typescript/TSImport)
- [Function](/api-reference/core/Function)
- [PyFunction](/api-reference/python/PyFunction)
- [TSFunction](/api-reference/typescript/TSFunction)
- [Class](/api-reference/core/Class)
- [PyClass](/api-reference/python/PyClass)
- [TSClass](/api-reference/typescript/TSClass)
- [Import](/api-reference/core/Import)
- [PyImport](/api-reference/python/PyImport)
- [TSImport](/api-reference/typescript/TSImport)

...

Expand Down Expand Up @@ -91,8 +91,8 @@ for function in codebase.functions:

Some features are only available in TypeScript codebases:

- **Types and Interfaces**: TypeScript's rich type system ([`TSTypeAlias`](/api-reference/typescript/TSTypeAlias), [`TSInterface`](/api-reference/typescript/TSInterface))
- **Exports**: Module exports and re-exports ([`TSExport`](/api-reference/typescript/TSExport))
- **Types and Interfaces**: TypeScript's rich type system ([TSTypeAlias](/api-reference/typescript/TSTypeAlias), [TSInterface](/api-reference/typescript/TSInterface))
- **Exports**: Module exports and re-exports ([TSExport](/api-reference/typescript/TSExport))
- **JSX/TSX**: React component handling (see [React and JSX](/building-with-codegen/react-and-jsx))

Example of TypeScript-specific features:
Expand Down
8 changes: 4 additions & 4 deletions docs/building-with-codegen/moving-symbols.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ iconType: "solid"

Codegen provides fast, configurable and safe APIs for moving symbols (functions, classes, variables) between files while automatically handling imports and dependencies.

The key API is [`Symbol.move_to_file(...)`](/api-reference/core/Symbol#move-to-file).
The key API is [Symbol.move_to_file(...)](/api-reference/core/Symbol#move-to-file).

## Basic Symbol Movement

Simply call [`Symbol.move_to_file(...)`](/api-reference/core/Symbol#move-to-file) to move a symbol to a new file.
Simply call [Symbol.move_to_file(...)](/api-reference/core/Symbol#move-to-file) to move a symbol to a new file.

```python
# Manipulation code:
Expand All @@ -35,7 +35,7 @@ helper_func.move_to_file(file2)

## Moving Strategies

The [`Symbol.move_to_file(...)`](/api-reference/core/Symbol#move-to-file) method accepts a `strategy` parameter, which can be used to control how imports are updated.
The [Symbol.move_to_file(...)](/api-reference/core/Symbol#move-to-file) method accepts a `strategy` parameter, which can be used to control how imports are updated.

Your options are:

Expand All @@ -51,7 +51,7 @@ Your options are:

## Moving Symbols in Bulk

Make sure to call [`Codebase.commit(...)`](/api-reference/core/Codebase#commit) _after_ moving symbols in bulk for performant symbol movement.
Make sure to call [Codebase.commit(...)](/api-reference/core/Codebase#commit) _after_ moving symbols in bulk for performant symbol movement.

```python
# Move all functions with a specific prefix
Expand Down
2 changes: 1 addition & 1 deletion docs/building-with-codegen/type-annotations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function.set_return_type("List[str]")

### Type Resolution

Type resolution uses [`Type.resolved_value`](/api-reference/core/Type#resolved-value) to get the actual symbols that a type refers to:
Type resolution uses [Type.resolved_value](/api-reference/core/Type#resolved-value) to get the actual symbols that a type refers to:

```python
# Get the actual symbols for a type
Expand Down
6 changes: 3 additions & 3 deletions docs/introduction/work-with-ai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {

The [Codegen CLI](/cli/about) provides commands to generate `.md` files that can be fed to any AI assistant for more accurate and contextual help.

When you create a new codemod via [`codegen create`](/cli/create):
When you create a new codemod via [codegen create](/cli/create):

```bash
codegen create delete-dead-imports --description "Delete unused imports"
Expand All @@ -41,7 +41,7 @@ You can find this generated prompt in the `.codegen/prompts/<codemod-name>-syste

<Note>
All contents of the `.codegen/prompts` directory are by default ignored the
`.gitignore` file. after running [`codegen init`](/cli/init)
`.gitignore` file. after running [codegen init](/cli/init)
</Note>

This `.md` file can be used with any AI assistant (Claude, GPT-4, etc.) to get more accurate and contextual help.
Expand All @@ -50,7 +50,7 @@ This `.md` file can be used with any AI assistant (Claude, GPT-4, etc.) to get m

<Steps>
<Step title="Create a codemod with description">
Use the [`create` command](/cli/create) with a detailed description of what you want to accomplish:
Use the [create command](/cli/create) with a detailed description of what you want to accomplish:
```bash
codegen create modernize-components --description "Convert class components to functional components with hooks"
```
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/creating-documentation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ iconType: "solid"
This guide demonstrates how to determine docs coverage and create documentation for your codebase.

This primarily leverages two APIs:
- [`codebase.ai(...)`](/api-reference/core/Codebase#ai) for generating docstrings
- [`function.set_docstring(...)`](/api-reference/core/HasBlock#set-docstring) for modifying them
- [codebase.ai(...)](/api-reference/core/Codebase#ai) for generating docstrings
- [function.set_docstring(...)](/api-reference/core/HasBlock#set-docstring) for modifying them

## Determining Documentation Coverage

Expand Down Expand Up @@ -74,7 +74,7 @@ Which provides the following output:

To identify areas of low documentation coverage, you can iterate through all directories and count the number of functions with docstrings.

<Note>Learn more about [`Directories` here](/building-with-codegen/files-and-directories).</Note>
<Note>Learn more about [Directories here](/building-with-codegen/files-and-directories).</Note>

```python python
# Track directory stats
Expand Down
2 changes: 2 additions & 0 deletions src/codegen/cli/workspace/initialize_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Tuple of (codegen_folder, docs_folder, examples_folder)
"""
repo = get_git_repo()
REPO_PATH = Path(repo.workdir)

Check failure on line 39 in src/codegen/cli/workspace/initialize_workspace.py

View workflow job for this annotation

GitHub Actions / mypy

error: Item "None" of "Repository | None" has no attribute "workdir" [union-attr]
CODEGEN_FOLDER = REPO_PATH / CODEGEN_DIR
PROMPTS_FOLDER = REPO_PATH / PROMPTS_DIR
DOCS_FOLDER = REPO_PATH / DOCS_DIR
Expand All @@ -59,7 +59,7 @@
CODEMODS_DIR.mkdir(parents=True, exist_ok=True)

# Initialize virtual environment
status_obj.update(f" {'Creating' if isinstance(status, str) else 'Checking'} virtual environment...")

Check failure on line 62 in src/codegen/cli/workspace/initialize_workspace.py

View workflow job for this annotation

GitHub Actions / mypy

error: Item "None" of "Status | None" has no attribute "update" [union-attr]
venv = VenvManager()
if not venv.is_initialized():
venv.create_venv()
Expand All @@ -78,7 +78,7 @@
if not repo:
rich.print("No git repository found. Please run this command in a git repository.")
else:
status_obj.update(f" {'Updating' if isinstance(status, Status) else status} .gitignore...")

Check failure on line 81 in src/codegen/cli/workspace/initialize_workspace.py

View workflow job for this annotation

GitHub Actions / mypy

error: Item "None" of "Status | None" has no attribute "update" [union-attr]
modify_gitignore(CODEGEN_FOLDER)

# Create or update config.toml with basic repo info
Expand All @@ -100,22 +100,22 @@

# Only fetch docs and examples if requested and session is provided
if fetch_docs and session:
status_obj.update("Fetching latest docs & examples...")

Check failure on line 103 in src/codegen/cli/workspace/initialize_workspace.py

View workflow job for this annotation

GitHub Actions / mypy

error: Item "None" of "Status | None" has no attribute "update" [union-attr]
shutil.rmtree(DOCS_FOLDER, ignore_errors=True)
shutil.rmtree(EXAMPLES_FOLDER, ignore_errors=True)

DOCS_FOLDER.mkdir(parents=True, exist_ok=True)
EXAMPLES_FOLDER.mkdir(parents=True, exist_ok=True)

response = RestAPI(session.token).get_docs()

Check failure on line 110 in src/codegen/cli/workspace/initialize_workspace.py

View workflow job for this annotation

GitHub Actions / mypy

error: Incompatible types in assignment (expression has type "dict[Any, Any]", variable has type "Response") [assignment]
populate_api_docs(DOCS_FOLDER, response.docs, status_obj)

Check failure on line 111 in src/codegen/cli/workspace/initialize_workspace.py

View workflow job for this annotation

GitHub Actions / mypy

error: "Response" has no attribute "docs" [attr-defined]

Check failure on line 111 in src/codegen/cli/workspace/initialize_workspace.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 3 to "populate_api_docs" has incompatible type "Status | None"; expected "Status" [arg-type]
populate_examples(session, EXAMPLES_FOLDER, response.examples, status_obj)

Check failure on line 112 in src/codegen/cli/workspace/initialize_workspace.py

View workflow job for this annotation

GitHub Actions / mypy

error: "Response" has no attribute "examples" [attr-defined]

Check failure on line 112 in src/codegen/cli/workspace/initialize_workspace.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 4 to "populate_examples" has incompatible type "Status | None"; expected "Status" [arg-type]

# Set programming language
if programming_language:
session.config.programming_language = programming_language
else:
session.config.programming_language = str(response.language)

Check failure on line 118 in src/codegen/cli/workspace/initialize_workspace.py

View workflow job for this annotation

GitHub Actions / mypy

error: "Response" has no attribute "language" [attr-defined]

session.write_config()

Expand Down Expand Up @@ -147,6 +147,8 @@
"__pycache__/",
"*.py[cod]",
"*$py.class",
"*.txt",
"*.pyc",
"",
"# Keep config.toml and codemods",
"!config.toml",
Expand Down