Skip to content

fix: CLI bugs in build, push commands and init templates#377

Open
zamalali wants to merge 6 commits intometa-pytorch:mainfrom
zamalali:fix/cli-template-bugs
Open

fix: CLI bugs in build, push commands and init templates#377
zamalali wants to merge 6 commits intometa-pytorch:mainfrom
zamalali:fix/cli-template-bugs

Conversation

@zamalali
Copy link

Summary

After the async-first EnvClient migration, several CLI commands and the openenv init templates were left with broken code paths. This PR fixes 6 bugs across build.py, push.py, and the init scaffolding templates. All fixes are minimal, no behavior changes for working code paths, no new dependencies, no breaking changes.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • New environment
  • Refactoring

What's Fixed

build.py

  1. tomli import crashes on Python 3.11+: Two functions did import tomli inline with a silent except ImportError fallback that skipped TOML parsing entirely. On Python 3.11+ where tomllib is in stdlib and tomli may not be installed, this silently skipped dependency checking. Moved to a module-level try: import tomllib / except: import tomli as tomllib, matching the pattern already used in _validation.py.

  2. Duplicate condition: rel_str.startswith("envs/") appeared twice in the same if statement. Removed the duplicate.

push.py

  1. Rich Console TypeError: console.print(..., file=sys.stderr) blows up at runtime because Rich's Console.print() does not accept a file= kwarg. This crashes the --interface --no-interface conflict check. Removed the file=sys.stderr argument to match every other error path in the same file.

  2. Dead variable + missing break: _in_frontmatter was assigned but never read. The loop also kept iterating past the first frontmatter closing ---. Removed the dead variable and added break. Also removed the now-unused import sys.

Templates (openenv init scaffolding)

  1. Bare with in docstring and README crashes: EnvClient.__enter__ raises TypeError directing users to use async with or .sync(). But client.py docstring and README.md code examples still showed bare with Env(...). Updated both to show async with (recommended) and .sync() wrapper, consistent with the project README and all documentation.

  2. Wrong package name in requirements.txt: Template had openenv[core]>=0.2.0 but the actual PyPI package is openenv-core (with a hyphen), and the current version is 0.2.1. Changed to openenv-core[core]>=0.2.1 to match pyproject.toml.

RFC Status

  • Not required (bug fix, docs, minor refactoring)

Test Plan

  • Updated test_init_requirements_file to assert the corrected package name
  • Added test_push_rejects_interface_and_no_interface covering the fixed error path (no mocking needed since the flag check runs before any HF API calls)
  • 39/39 tests pass, 2 deselected (pre-existing Windows encoding issue with emoji in README template, not related to this PR)
  • ruff check and ruff format --check pass on entire src/ and tests/
  • No breaking changes. Every fix either removes code that was already broken or corrects documentation that would mislead users.

@meta-cla
Copy link

meta-cla bot commented Feb 12, 2026

Hi @zamalali!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 12, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 12, 2026

Greptile Overview

Greptile Summary

This PR fixes 6 legitimate bugs across CLI commands and init templates that were introduced after the async-first EnvClient migration. All fixes are minimal and well-tested.

Key Changes:

  • Fixed tomli import crash on Python 3.11+ by using stdlib tomllib with fallback to tomli
  • Removed duplicate rel_str.startswith("envs/") condition in build.py
  • Fixed Rich Console TypeError by removing invalid file=sys.stderr kwarg from console.print()
  • Cleaned up dead _in_frontmatter variable and added missing break in frontmatter parsing
  • Updated init templates to show correct async patterns (async with and .sync()) instead of bare with
  • Corrected package name from openenv[core] to openenv-core[core] in requirements.txt template

Test Coverage:

  • All 39 tests pass
  • Added new test test_push_rejects_interface_and_no_interface for the fixed error path
  • Updated test_init_requirements_file to verify correct package name

Issue Found:

  • Template requires openenv-core[core]>=0.2.1 but pyproject.toml shows version = "0.2.0" - this will cause installation failures when users run openenv init

Confidence Score: 4/5

  • Safe to merge after fixing version mismatch in requirements.txt
  • All fixes are valid bug fixes with proper test coverage. One minor issue: template requires openenv-core>=0.2.1 but pyproject.toml shows version 0.2.0, creating a potential installation failure for new environments
  • src/openenv/cli/templates/openenv_env/server/requirements.txt - version mismatch needs correction

Important Files Changed

Filename Overview
src/openenv/cli/commands/build.py Fixed tomli import to use stdlib tomllib on Python 3.11+, removed duplicate condition, better error handling
src/openenv/cli/commands/push.py Fixed Rich Console TypeError by removing invalid file= kwarg, cleaned up unused variable and added break
src/openenv/cli/templates/openenv_env/server/requirements.txt Corrected package name from openenv[core] to openenv-core[core] and version to 0.2.1 (pyproject.toml is 0.2.0)

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@@ -1,4 +1,4 @@
openenv[core]>=0.2.0
openenv-core[core]>=0.2.1
Copy link
Contributor

Choose a reason for hiding this comment

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

version mismatch: pyproject.toml shows version = "0.2.0" but template requires >=0.2.1

Suggested change
openenv-core[core]>=0.2.1
openenv-core[core]>=0.2.0
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/openenv/cli/templates/openenv_env/server/requirements.txt
Line: 1:1

Comment:
version mismatch: `pyproject.toml` shows `version = "0.2.0"` but template requires `>=0.2.1`

```suggestion
openenv-core[core]>=0.2.0
```

How can I resolve this? If you propose a fix, please make it concise.

@zamalali zamalali force-pushed the fix/cli-template-bugs branch from 073d383 to 9bd5d6f Compare February 12, 2026 13:45
Fix 6 bugs across CLI commands and scaffolding templates:

build.py:
- Use stdlib tomllib (3.11+) with tomli fallback at module level,
  replacing 2 inline 'import tomli' calls that crashed without tomli
- Remove duplicate rel_str.startswith("envs/") condition (copy-paste bug)

push.py:
- Remove file=sys.stderr kwarg from console.print() (Rich Console
  does not accept file; this raised TypeError at runtime)
- Remove dead variable _in_frontmatter (assigned but never read);
  add break to exit loop after first frontmatter closing ---
- Remove now-unused import sys

templates (openenv init scaffolding):
- Fix client.py docstring: bare with context manager crashes because
  EnvClient.__enter__ raises TypeError; show async with (recommended)
  and .sync() wrapper examples instead
- Fix README.md: update Using the Context Manager and Concurrent
  WebSocket Sessions sections to use async with / asyncio.gather
  instead of bare with / ThreadPoolExecutor
- Fix server/requirements.txt: openenv[core] to openenv-core[core]
  and >=0.2.0 to >=0.2.1 to match pyproject.toml package name

Tests:
- Update test_init_requirements_file assertion to match new package name
- Add test_push_rejects_interface_and_no_interface test
@burtenshaw
Copy link
Collaborator

This is a great PR. Thanks.

I'd like to merge this to main after #370 and #371

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

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants