Skip to content

It's easier to manage vars through dotenv#5

Open
Dimlock wants to merge 1 commit intosealad886:masterfrom
Dimlock:dotenv
Open

It's easier to manage vars through dotenv#5
Dimlock wants to merge 1 commit intosealad886:masterfrom
Dimlock:dotenv

Conversation

@Dimlock
Copy link

@Dimlock Dimlock commented Dec 1, 2025

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @Dimlock, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the application's configuration management by introducing python-dotenv. This change allows critical directory paths to be defined in .env files, enhancing flexibility and simplifying setup for different environments. It also adds robust validation to ensure these essential configuration variables are always present, improving application stability.

Highlights

  • Environment Variable Management: Integrated the python-dotenv library to allow for easier management of environment variables, such as OLLAMAUTIL_INTERNAL_DIR and OLLAMAUTIL_EXTERNAL_DIR, through .env files.
  • Configuration Validation: Added explicit checks to ensure that OLLAMAUTIL_INTERNAL_DIR and OLLAMAUTIL_EXTERNAL_DIR environment variables are set, raising an exception if they are missing to prevent runtime errors.
  • Dependency Update: Added python-dotenv to the requirements.txt file, making it a required dependency for the project.
  • Minor Bug Fix/Clarification: Addressed a minor logic flow in ollamautil.py to ensure the overwrite variable is correctly set to False under specific conditions during file copy operations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces python-dotenv for managing environment variables, which is a great step towards better configuration management. The changes correctly add the dependency and load variables from a .env file. My review focuses on improving code quality by addressing some code duplication and redundant logic that was introduced. Specifically, the environment variable loading and validation logic is duplicated in ollamautil.py and src/ollamautil/cli.py. I've provided suggestions to consolidate these checks and make them more robust. I also included a minor suggestion to improve code style for variable initialization.

Comment on lines +759 to +760
if ollama_int_dir is None or ollama_ext_dir is None:
raise Exception("Ollamautil internal and external directories not set.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This check is a good addition, but it can be improved. The check is None will not catch empty strings which are also likely invalid for directory paths. Also, there is a redundant check on lines 773-779. Consider using a single, more robust check and a more specific exception type like ValueError.

Furthermore, the same logic for loading and checking environment variables is duplicated in src/ollamautil/cli.py. This logic could be extracted into a shared utility function to follow the DRY (Don't Repeat Yourself) principle.

I'd suggest replacing this check with the one below, and removing the redundant one at lines 773-779.

Suggested change
if ollama_int_dir is None or ollama_ext_dir is None:
raise Exception("Ollamautil internal and external directories not set.")
if not ollama_int_dir or not ollama_ext_dir:
raise ValueError("Ollamautil internal and external directories not set. Please set OLLAMAUTIL_INTERNAL_DIR and OLLAMAUTIL_EXTERNAL_DIR in your environment or .env file.")

Comment on lines +50 to +51
if ollama_int_dir is None or ollama_ext_dir is None:
raise Exception("Ollamautil internal and external directories not set.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This new check is redundant with the existing check on lines 58-62. The existing check is more robust as it also handles empty strings and provides a more informative error message before exiting with SystemExit, which is suitable for a CLI tool. It's best to consolidate these into a single check.

This logic is also duplicated in ollamautil.py. Consider creating a shared function for loading and validating environment variables to keep your code DRY.

I recommend removing this new if block and relying on the more comprehensive check on lines 58-62.

Comment on lines +395 to +396
else:
overwrite = False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This else block correctly fixes a potential UnboundLocalError for the overwrite variable. A more common and arguably cleaner pattern is to initialize variables with a default value. Consider initializing overwrite = False before the if existing_files: block on line 388 and removing this else block. This makes the default value explicit and improves readability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant