Skip to content

Auto-create user/style.css if missing to fix issue #897#969

Open
Prathamesh8989 wants to merge 2 commits intofossasia:masterfrom
Prathamesh8989:fix-stylecss-auto-create
Open

Auto-create user/style.css if missing to fix issue #897#969
Prathamesh8989 wants to merge 2 commits intofossasia:masterfrom
Prathamesh8989:fix-stylecss-auto-create

Conversation

@Prathamesh8989
Copy link

@Prathamesh8989 Prathamesh8989 commented Feb 22, 2026

Description

Automatically creates the user/style.css file during Visdom server startup if it doesn't exist. Also ensures the user folder is created inside the environment path (env_path). This prevents the “Style.css file not found” warning and allows users to add custom CSS overrides without manual folder creation.

Motivation and Context

Fixes issue #897 ("Style.css file not found"). Previously, users had to manually create the user folder and style.css after installing Visdom. This change makes the process seamless, improving the out-of-the-box user experience.

How Has This Been Tested?

  • Ran Visdom in a clean environment with no existing user folder.
  • Verified that user/style.css is automatically created in the correct environment path.
  • Confirmed that the server starts successfully and the browser UI loads without any style.css warnings.
  • Tested that existing style.css files are not overwritten.

Screenshots (if appropriate):

N/A — no UI changes by default; only auto-creation of a CSS file.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactor or cleanup (changes to existing code for improved readability or performance)

Checklist:

  • I adapted the version number under py/visdom/VERSION according to Semantic Versioning
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Summary by Sourcery

Ensure the Visdom server automatically provisions a user CSS file and slightly tidy the server startup logging.

Bug Fixes:

  • Create a user/style.css file and its containing user directory at server startup if they do not already exist, avoiding missing-style warnings while preserving existing files.

Enhancements:

  • Simplify and modernize the startup URL logging message formatting.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 22, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds automatic creation of a user/style.css file and directory at Visdom server startup and simplifies hostname/URL printing logic.

Sequence diagram for Visdom server startup with auto-created user/style.css

sequenceDiagram
    actor User
    participant CLI as CLI
    participant Server as VisdomServer
    participant FS as FileSystem

    User->>CLI: run visdom
    CLI->>Server: start_server()
    Server->>FS: check existence of user directory
    alt user directory missing
        Server->>FS: create user directory
    end
    Server->>FS: check existence of style.css
    alt style.css missing
        Server->>FS: create empty style.css with header comment
    end
    Server->>Server: initialize Application
    Server->>Server: configure hostname and base_url
    Server->>User: print navigation URL
    Server->>Server: start IOLoop
Loading

Flow diagram for start_server user/style.css auto-creation logic

flowchart TD
    A[start_server called] --> B[Compute user_dir as CWD/user]
    B --> C{Does user_dir exist?}
    C -- No --> D[Create user_dir]
    C -- Yes --> E[Skip creating user_dir]
    D --> F[Compute style_file as user_dir/style.css]
    E --> F[Compute style_file as user_dir/style.css]
    F --> G{Does style_file exist?}
    G -- No --> H[Create style.css with header comment]
    G -- Yes --> I[Skip creating style.css]
    H --> J[Initialize Application]
    I --> J[Initialize Application]
    J --> K[Resolve hostname and base_url]
    K --> L[Print navigation URL]
    L --> M[Start IOLoop]
Loading

File-Level Changes

Change Details Files
Automatically ensure a user directory and style.css file exist at server startup to avoid missing-style warnings.
  • Compute a user directory path relative to the current working directory.
  • Create the user directory if it does not already exist.
  • Create an empty style.css with a comment header if it does not already exist, without overwriting existing files.
py/visdom/server/run_server.py
Minor cleanup of server startup logging and hostname handling.
  • Remove a redundant else branch when resolving the hostname from the HOSTNAME environment variable.
  • Switch the server URL print to an f-string for improved readability.
  • Remove an unnecessary blank line before the start_server function definition.
py/visdom/server/run_server.py

Possibly linked issues

  • #pending error: Link: the PR auto-creates user/style.css, directly resolving the missing CSS error described in the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The auto-creation logic currently hardcodes user_dir to os.getcwd()/user, which doesn’t align with the PR description about using the environment path (env_path) and may place style.css in an unexpected location relative to where Visdom actually looks for it; consider basing this path on the same env/config value the rest of the server uses.
  • The new auto-creation block could be simplified and made more robust by using os.makedirs(user_dir, exist_ok=True) and perhaps creating an empty style.css (or one with a very minimal comment) to avoid unintentionally changing styling output in environments that serve this file directly.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The auto-creation logic currently hardcodes `user_dir` to `os.getcwd()/user`, which doesn’t align with the PR description about using the environment path (`env_path`) and may place `style.css` in an unexpected location relative to where Visdom actually looks for it; consider basing this path on the same env/config value the rest of the server uses.
- The new auto-creation block could be simplified and made more robust by using `os.makedirs(user_dir, exist_ok=True)` and perhaps creating an empty `style.css` (or one with a very minimal comment) to avoid unintentionally changing styling output in environments that serve this file directly.

## Individual Comments

### Comment 1
<location> `py/visdom/server/run_server.py:44-45` </location>
<code_context>
+    # -------------------------
+    # Auto-create user/style.css
+    # -------------------------
+    user_dir = os.path.join(os.getcwd(), "user")
+    if not os.path.exists(user_dir):
+        os.makedirs(user_dir)
+
</code_context>

<issue_to_address>
**suggestion:** Consider using a more stable base directory than the current working directory for `user/style.css`.

Because `user_dir` depends on `os.getcwd()`, the location of `user/style.css` will vary based on how and where the process is started, potentially creating multiple `user` directories. Consider instead deriving this path from a fixed application root (for example, the module’s directory or a configured data directory) so the stylesheet location is consistent across runs.

Suggested implementation:

```python
def start_server(
    port=DEFAULT_PORT,
    hostname=DEFAULT_HOSTNAME,
    bind_local=False,
    eager_data_loading=False,
):
    # -------------------------
    # Auto-create user/style.css
    # Use the module directory as a stable base instead of os.getcwd()
    # -------------------------
    module_dir = os.path.dirname(os.path.abspath(__file__))
    user_dir = os.path.join(module_dir, "user")
    if not os.path.exists(user_dir):
        os.makedirs(user_dir, exist_ok=True)

def start_server(
    port=DEFAULT_PORT,
    hostname=DEFAULT_HOSTNAME,
    bind_local=False,
    eager_data_loading=False,
):
    # -------------------------
    # Auto-create user/style.css
    # Use the module directory as a stable base instead of os.getcwd()
    # -------------------------
    module_dir = os.path.dirname(os.path.abspath(__file__))
    user_dir = os.path.join(module_dir, "user")
    if not os.path.exists(user_dir):
        os.makedirs(user_dir, exist_ok=True)

```

1. Ensure `os` is imported at the top of `py/visdom/server/run_server.py` (if it is not already):
   - Add `import os` alongside the other standard library imports.
2. If the intention is to create `user/style.css` itself (not just the directory), add logic after the `os.makedirs` call to create the file when it does not exist, e.g.:
   ```python
   css_path = os.path.join(user_dir, "style.css")
   if not os.path.exists(css_path):
       with open(css_path, "w", encoding="utf-8") as f:
           f.write("")  # or default CSS contents
   ```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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