Skip to content
Open
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: 1 addition & 1 deletion examples/simple.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from dotenv import dotenv_values, load_dotenv
from os import getenv


fn main() raises:
def main():
print("=" * 60)
print("mojo-dotenv Example")
print("=" * 60)
Expand Down
2 changes: 1 addition & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[project]
[workspace]
authors = ["Michael Booth <michael@databooth.com.au>"]
channels = ["conda-forge", "https://conda.modular.com/max"]
name = "mojo-dotenv"
Expand Down
2 changes: 1 addition & 1 deletion src/dotenv/__init__.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from .loader import load_dotenv
from .finder import find_dotenv


fn dotenv_values(dotenv_path: String, verbose: Bool = False) raises -> Dict[String, String]:
def dotenv_values(dotenv_path: String, verbose: Bool = False) -> Dict[String, String]:
"""Parse a .env file and return its content as a dictionary.

This function reads a .env file and returns a dictionary mapping
Expand Down
2 changes: 1 addition & 1 deletion src/dotenv/finder.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path


fn find_dotenv(filename: String = ".env", raise_error_if_not_found: Bool = False, usecwd: Bool = False) raises -> String:
def find_dotenv(filename: String = ".env", raise_error_if_not_found: Bool = False, usecwd: Bool = False) -> String:
"""Search in increasingly higher folders for the given file.

Searches upward from the current directory (or working directory if usecwd=True)
Expand Down
2 changes: 1 addition & 1 deletion src/dotenv/loader.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from pathlib import Path
from .parser import parse_dotenv


fn load_dotenv(dotenv_path: String, override: Bool = False, verbose: Bool = False) raises -> Bool:
def load_dotenv(dotenv_path: String, override: Bool = False, verbose: Bool = False) -> Bool:
"""Load variables from a .env file into the environment.

Reads a .env file and sets all found variables as environment variables.
Expand Down
20 changes: 10 additions & 10 deletions src/dotenv/parser.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ from collections import Dict, Optional, List
from os import getenv


fn to_chars(text: String) -> List[String]:
def to_chars(text: String) -> List[String]:
"""Convert a String into a list of single-codepoint Strings."""
var chars = List[String]()
for slice in text.codepoint_slices():
chars.append(String(slice))
return chars^


fn join_chars(chars: List[String], start: Int, end: Int) -> String:
def join_chars(chars: List[String], start: Int, end: Int) -> String:
"""Join a slice of character list [start, end) into a String."""
var result = String("")
var i = start
Expand All @@ -25,7 +25,7 @@ fn join_chars(chars: List[String], start: Int, end: Int) -> String:
return result


fn count_trailing_backslashes(text: String, end_pos: Int) -> Int:
def count_trailing_backslashes(text: String, end_pos: Int) -> Int:
"""Count consecutive backslashes before the given character position.

Args:
Expand All @@ -44,7 +44,7 @@ fn count_trailing_backslashes(text: String, end_pos: Int) -> Int:
return count


fn lookup_variable(var_name: String, env_dict: Dict[String, String], fallback_literal: String) raises -> String:
def lookup_variable(var_name: String, env_dict: Dict[String, String], fallback_literal: String) -> String:
"""Look up a variable in env_dict, then system environment, else return literal.

Args:
Expand All @@ -65,7 +65,7 @@ fn lookup_variable(var_name: String, env_dict: Dict[String, String], fallback_li
return fallback_literal


fn strip_inline_comment(line: String) -> String:
def strip_inline_comment(line: String) -> String:
"""Strip inline comments from a line.

Handles # comments after values, but not within quotes.
Expand Down Expand Up @@ -109,7 +109,7 @@ fn strip_inline_comment(line: String) -> String:
return line


fn expand_variables(value: String, env_dict: Dict[String, String]) raises -> String:
def expand_variables(value: String, env_dict: Dict[String, String]) -> String:
"""Expand variable references in a value.

Supports:
Expand Down Expand Up @@ -182,7 +182,7 @@ fn expand_variables(value: String, env_dict: Dict[String, String]) raises -> Str
return result


fn process_escapes(value: String) -> String:
def process_escapes(value: String) -> String:
"""Process escape sequences in a string.

Handles:
Expand Down Expand Up @@ -233,7 +233,7 @@ fn process_escapes(value: String) -> String:
return result


fn strip_quotes(value: String) -> String:
def strip_quotes(value: String) -> String:
"""Strip outer quotes (single or double) from a value and process escapes.

Args:
Expand Down Expand Up @@ -261,7 +261,7 @@ fn strip_quotes(value: String) -> String:
return v_str


fn parse_line(line: String, verbose: Bool = False) -> Optional[Tuple[String, String]]:
def parse_line(line: String, verbose: Bool = False) -> Optional[Tuple[String, String]]:
"""Parse a single line from a .env file.

Handles:
Expand Down Expand Up @@ -324,7 +324,7 @@ fn parse_line(line: String, verbose: Bool = False) -> Optional[Tuple[String, Str
return (key, value)


fn parse_dotenv(content: String, verbose: Bool = False) raises -> Dict[String, String]:
def parse_dotenv(content: String, verbose: Bool = False) -> Dict[String, String]:
"""Parse the entire content of a .env file.

Performs two passes:
Expand Down
2 changes: 1 addition & 1 deletion test_package.mojo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dotenv import dotenv_values, load_dotenv, find_dotenv

fn main() raises:
def main():
# Basic smoke test: ensure we can import and call the public API without error.
var path = find_dotenv()
# We do not assert on specific values here; we just ensure calls succeed.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_python_compat.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from dotenv import dotenv_values
from python import Python, PythonObject


fn test_fixture_against_python(fixture_path: String) raises:
def test_fixture_against_python(fixture_path: String):
"""Test a fixture matches python-dotenv results."""
var mojo_result = dotenv_values(fixture_path)
var py = Python.import_module("dotenv")
Expand Down