8000 Lazy_doc installed as dep it breaks by pxp9 · Pull Request #33 · pxp9/lazy_doc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Lazy_doc installed as dep it breaks #33

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 9 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

< 10000 /details-menu>
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"test/support/**/*.ex"}
]
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,23 @@ provider which is a tuple of three elements `{GithubAi, :codestral, options}`.
``` elixir
def deps do
[
{:lazy_doc, "~> 0.5.5"}
{:lazy_doc, "~> 0.6.0"}
]
end
```

or install it as a single binary

``` bash
mix escript.install hex lazy_doc 0.5.5
mix escript.install hex lazy_doc 0.6.0
```

## Configuration

Configuration is the same if you are using the binary or the dep.

`config/config.exs`
`config/lazy_doc.exs` It is expected to be in this file with Elixir config
syntax.

``` elixir
import Config
Expand Down Expand Up @@ -58,21 +59,49 @@ config :lazy_doc,
## This is the default value, no need to configure.
custom_module_prompt:
~s(You should describe what this module does based on the code given.\n\n Please do it in the following format given as an example, important do not return the code of the module, your output must be only the docs in the following format.\n\n@moduledoc """\n\nThe module GithubAi provides a way of communicating with Github AI API \(describes the main functionality of the module\).\n\n## Description\n\nIt implements the behavior Provider a standard way to use a provider in LazyDoc.\(gives a detailed description of what the module does\)\n"""\n\nModule to document:\n)

```

`config/runtime.exs`
> Note If installed as a dep you need to do this.

`config/config.exs`

``` elixir
## Required to be configured
config :lazy_doc, :token, System.get_env("API_TOKEN")
import_conf("lazy_doc.exs")
```

### API token conf

`.env`

``` bash
API_TOKEN="YOUR AWESOME TOKEN"
```

if installed as dep

`config/runtime.exs`

``` elixir
## Required to be configured
config :lazy_doc, :token, System.get_env("API_TOKEN")
```

if installed as binary

``` bash
export API_TOKEN="YOUR AWESOME TOKEN"
```

or

``` bash
export $(cat .env | xargs)
```

By default `lazy_doc` will try to get the token from the env var `API_TOKEN`

### Available Providers implemented by LazyDoc

You can check Providers implemented in LazyDoc
Expand Down
22 changes: 1 addition & 21 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
import Config
alias LazyDoc.Providers.GithubAi

_ = """
:codestral -> "Codestral-2501"
:gpt_4o -> "gpt-4o"
:gpt_4o_mini -> "gpt-4o-mini"

"""

config :lazy_doc,
external_docs: true,
patterns: [
~r"^lib(?:/[a-zA-Z_\.]+)*/[a-zA-Z_\.]+\.ex$"
],
max_retries: 3,
receive_timeout: 30_000,
file_formatter: ".formatter.exs",
provider: {GithubAi, :gpt_4o_mini, [max_tokens: 2048, top_p: 1, temperature: 1]},
custom_function_prompt:
~s(You should describe the parameters based on the spec given and give a small description of the following function.\n\nPlease do it in the following format given as an example, important do not return the header of the function, do not return a explanation of the function, your output must be only the docs in the following format:\n\nReturns the Transaction corresponding to transaction_id\(Initial sentence indicating what returns the function\)\n\n## Parameters\n\n- transaction_id - foreign key of the Transactions table.\n## Description\n Performs a search in the database\n\nFunction to document:\n),
custom_module_prompt:
~s(You should describe what this module does based on the code given.\n\n Please do it in the following format given as an example, important do not return the code of the module, your output must be only the docs in the following format.\n\n@moduledoc """\n\nThe module GithubAi provides a way of communicating with Github AI API \(describes the main functionality of the module\).\n\n## Description\n\nIt implements the behavior Provider a standard way to use a provider in LazyDoc.\(gives a detailed description of what the module does\)\n"""\n\nModule to document:\n)
import_config("lazy_doc.exs")
23 changes: 23 additions & 0 deletions config/lazy_doc.exs
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Config
alias LazyDoc.Providers.GithubAi

_ = """
:codestral -> "Codestral-2501"
:gpt_4o -> "gpt-4o"
:gpt_4o_mini -> "gpt-4o-mini"

"""

config :lazy_doc,
external_docs: true,
patterns: [
~r"^lib(?:/[a-zA-Z_\.]+)*/[a-zA-Z_\.]+\.ex$"
],
max_retries: 3,
receive_timeout: 30_000,
file_formatter: ".formatter.exs",
provider: {GithubAi, :gpt_4o_mini, [max_tokens: 2048, top_p: 1, temperature: 1]},
custom_function_prompt:
~s(You should describe the parameters based on the spec given and give a small description of the following function.\n\nPlease do it in the following format given as an example, important do not return the header of the function, do not return a explanation of the function, your output must be only the docs in the following format:\n\nReturns the Transaction corresponding to transaction_id\(Initial sentence indicating what returns the function\)\n\n## Parameters\n\n- transaction_id - foreign key of the Transactions table.\n## Description\n Performs a search in the database\n\nFunction to document:\n),
custom_module_prompt:
~s(You should describe what this module does based on the code given.\n\n Please do it in the following format given as an example, important do not return the code of the module, your output must be only the docs in the following format.\n\n@moduledoc """\n\nThe module GithubAi provides a way of communicating with Github AI API \(describes the main functionality of the module\).\n\n## Description\n\nIt implements the behavior Provider a standard way to use a provider in LazyDoc.\(gives a detailed description of what the module does\)\n"""\n\nModule to document:\n)
16 changes: 16 additions & 0 deletions lib/lazy_doc/application.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule LazyDoc.Application do
@moduledoc """

The module LazyDoc.Application is responsible for managing the application startup.

## Description

It implements the behavior of an Application, specifically defining the start function which is called when the application starts. The start function currently returns the process identifier of the calling process, indicating successful initialization of the application.
"""
use Application

@doc File.read!("priv/lazy_doc/lazy_doc/application/start.md")
def start(_start_type, _start_args) do
{:ok, self()}
end
end
38 changes: 19 additions & 19 deletions lib/lazy_doc/cli.ex
9E12
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ defmodule LazyDoc.CLI do

It serves as the entry point for running various tasks related to LazyDoc, such as generating documentation, checking documentation status, and cleaning up generated files. It also handles the inclusion of necessary ebin paths for modules and processes command-line arguments to determine which task to execute.
"""
require Logger
@doc File.read!("priv/lazy_doc/lazy_doc/cli/main.md")
def main(args) do
Application.ensure_all_started([:lazy_doc, :logger, :req])

Path.wildcard("_build/dev/lib/**/ebin/")
|> Enum.each(fn path ->
:code.add_path(String.to_charlist(path))
end)
LazyDoc.Util.load_modules_and_conf()

if File.exists?("config/config.exs") do
Config.Reader.read!("config/config.exs")[:lazy_doc]
|> Enum.each(fn {k, v} -> Application.put_env(:lazy_doc, k, v) end)
end
cond do
Enum.empty?(args) ->
Mix.Tasks.LazyDoc.main(args)

if File.exists?("config/runtime.exs") do
Config.Reader.read!("config/runtime.exs")[:lazy_doc]
|> Enum.each(fn {k, v} -> Application.put_env(:lazy_doc, k, v) end)
end
args == ["--check"] or args == ["-c"] ->
Mix.Tasks.LazyDoc.Check.main(args)

case args do
[] ->
Mix.Tasks.LazyDoc.run(args)
args == ["--clean"] or args == ["-r"] ->
Mix.Tasks.LazyDoc.Clean.main(args)

["--check"] ->
Mix.Tasks.LazyDoc.Check.run(args)
args == ["--help"] or args == ["-h"] ->
help_message()

["--clean"] ->
Mix.Tasks.LazyDoc.Clean.run(args)
true ->
help_message()
end
end

defp help_message() do
Logger.info(
"There are 3 options: \nuse it without any argument\n it will document\n--check or -c\n it will check if something is left to document\n--clean or -r\n it will remove all the functions documentation"
)
end
end
37 changes: 37 additions & 0 deletions lib/lazy_doc/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ defmodule LazyDoc.Util do

It implements functionality to scan Elixir source files within a specified path, extract module and function definitions, group related functions by name (taking arity into account), and filter undocumented or documented functions and modules. The primary purpose of LazyDoc is to facilitate the automation of generating documentation by analyzing source code, managing documentation for function overloads, and providing insights into which parts of the codebase are lacking documentation.
"""
require Logger
@global_path "lib/**/*.ex"

@doc File.read!("priv/lazy_doc/lazy_doc/extract_data_from_files.md")
Expand Down Expand Up @@ -331,4 +332,40 @@ defmodule LazyDoc.Util do
fn {{:function, _name, _arity}, _line, _signature, docs, %{}} -> docs end
)
end

@doc File.read!("priv/lazy_doc/lazy_doc/util/load_modules_and_conf.md")
def load_modules_and_conf() do
mix_env = System.get_env("MIX_ENV", "dev")
search_target = Path.wildcard("_build/#{mix_env}/lib/**/ebin/")

if Enum.empty?(search_target) do
raise(
LazyDoc.Util.NotCompiledError,
message: "Your project must be compiled in dev mode in order to LazyDoc execute"
)
end

search_target
|> Enum.each(fn path ->
Logger.debug("Loading #{path}")
:code.add_path(String.to_charlist(path))
end)

if File.exists?("config/lazy_doc.exs") do
Config.Reader.read!("config/lazy_doc.exs")[:lazy_doc]
|> Enum.each(fn {k, v} -> Application.put_env(:lazy_doc, k, v) end)
end
end

defmodule NotCompiledError do
@moduledoc """

The module NotCompiledError defines a custom exception that can be raised when a compilation error occurs in a program.

## Description

It provides a standard way to create an exception with a customizable message, which can be used to indicate that a piece of code could not be compiled. This exception can be helpful in error handling scenarios, allowing developers to signify specific issues related to code compilation.
"""
defexception [:message]
end
end
11 changes: 10 additions & 1 deletion lib/mix/tasks/lazy_doc.check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ defmodule Mix.Tasks.LazyDoc.Check do
use Mix.Task

@doc File.read!("priv/lazy_doc/mix/tasks/lazy_doc.check/run.md")
def run(_command_line_args) do
def run(args) do
Mix.Task.run("app.config")
main(args)
exit({:shutdown, 0})
end

@doc false
def main(_args) do
values =
LazyDoc.Util.extract_data_from_files()
|> Enum.map(fn entry ->
Logger.info("Checking #{entry.file}")

get_undocumented_functions(entry.functions, entry.file) != [] or
get_undocumented_modules(entry.modules, entry.file)
end)
Expand Down
11 changes: 10 additions & 1 deletion lib/mix/tasks/lazy_doc.clean.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ defmodule Mix.Tasks.LazyDoc.Clean do
use Mix.Task

@doc File.read!("priv/lazy_doc/mix/tasks/lazy_doc.clean/run.md")
def run(_command_line_args) do
def run(args) do
Mix.Task.run("app.config")
main(args)
exit({:shutdown, 0})
end

@doc false
def main(_args) do
if not clean_tree?() do
IO.puts("Uncommitted changes detected.\nPlease stash your changes before running this task")
exit({:shutdown, 1})
end

LazyDoc.Util.extract_data_from_files()
|> Enum.each(fn entry ->
Logger.info("Cleaning #{entry.file}")

ast =
Enum.reduce(entry.functions_documented, entry.ast, fn {_mod, mod_ast, functions}, acc ->
delete_function_docs_from_ast(acc, functions, mod_ast)
Expand Down
11 changes: 9 additions & 2 deletions lib/mix/tasks/lazy_doc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ defmodule Mix.Tasks.LazyDoc do
@default_module_prompt ~s(You should describe what this module does based on the code given.\n\n Please do it in the following format given as an example, important do not return the code of the module, your output must be only the docs in the following format.\n\n@moduledoc """\n\nThe module GithubAi provides a way of communicating with Github AI API \(describes the main functionality of the module\).\n\n## Description\n\nIt implements the behavior Provider a standard way to use a provider in LazyDoc.\(gives a detailed description of what the module does\)\n"""\n\nModule to document:\n)

@doc File.read!("priv/lazy_doc/mix/tasks/lazy_doc/run.md")
def run(_command_line_args) do
## Start req
def run(args) do
Mix.Task.run("app.config")
main(args)
exit({:shutdown, 0})
end

@doc false
def main(_args) do
_result = Application.ensure_all_started([:req, :telemetry])

LazyDoc.Util.extract_data_from_files()
Expand Down Expand Up @@ -162,6 +167,8 @@ defmodule Mix.Tasks.LazyDoc do
end

Enum.each(entries, fn entry ->
Logger.info("Documenting #{entry.file}")

acc =
Enum.reduce(entry.modules, entry.ast, fn {_mod, mod_ast, code_mod}, acc_ast ->
function_prompt = final_module_prompt <> code_mod
Expand Down
3 changes: 1 addition & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LazyDoc.MixProject do
use Mix.Project

@version "0.5.5"
@version "0.6.0"

def project do
[
Expand All @@ -27,7 +27,6 @@ defmodule LazyDoc.MixProject do
],
dialyzer: [
check_plt: true,
plt_file: {:no_warn, "priv/plts/dialyzer.plt"},
plt_add_apps: [:ex_unit, :mix]
]
]
Expand Down
8 changes: 8 additions & 0 deletions priv/lazy_doc/lazy_doc/util/load_modules_and_conf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Returns a list of paths to load module files and configurations, raising an error if the project is not compiled in development mode.

## Parameters

- None

## Description
Loads all module paths and relevant configuration settings from the project's configuration files if they exist.
0