@@ -399,3 +399,100 @@ def test_initialize_project_config_ssh_remote(tmp_path, monkeypatch):
399399 assert urls ["Bug Tracker" ] == "https://github.com/user/ComfyUI-TestNode/issues"
400400 assert data ["project" ]["name" ] == "testnode"
401401 assert data ["tool" ]["comfy" ]["DisplayName" ] == "ComfyUI-TestNode"
402+
403+
404+ # Issue #431: requirements.txt → pyproject.toml migration must produce
405+ # valid PEP 508 dependency specifiers. Inline comments, full-line comments,
406+ # and pip-specific options (-r, -e, --index-url, ...) are not valid deps.
407+
408+
409+ def _init_git_repo_with_reqs (tmp_path , requirements_content : str ) -> None :
410+ subprocess .run (["git" , "init" ], cwd = tmp_path , check = True , capture_output = True )
411+ subprocess .run (
412+ ["git" , "remote" , "add" , "origin" , "https://github.com/user/ComfyUI-TestNode.git" ],
413+ cwd = tmp_path ,
414+ check = True ,
415+ capture_output = True ,
416+ )
417+ (tmp_path / "requirements.txt" ).write_text (requirements_content )
418+
419+
420+ def test_initialize_project_config_strips_inline_comments (tmp_path , monkeypatch ):
421+ monkeypatch .chdir (tmp_path )
422+ _init_git_repo_with_reqs (
423+ tmp_path ,
424+ "matplotlib>=3.3.0 # For visualization\n numpy>=1.0 # trailing\n " ,
425+ )
426+ initialize_project_config ()
427+ with open (tmp_path / "pyproject.toml" ) as f :
428+ data = tomlkit .parse (f .read ())
429+ deps = [str (d ) for d in data ["project" ]["dependencies" ]]
430+ assert deps == ["matplotlib>=3.3.0" , "numpy>=1.0" ]
431+
432+
433+ def test_initialize_project_config_skips_full_line_comments (tmp_path , monkeypatch ):
434+ monkeypatch .chdir (tmp_path )
435+ _init_git_repo_with_reqs (
436+ tmp_path ,
437+ "# heading comment\n foo>=1.0\n # indented comment\n bar\n " ,
438+ )
439+ initialize_project_config ()
440+ with open (tmp_path / "pyproject.toml" ) as f :
441+ data = tomlkit .parse (f .read ())
442+ deps = [str (d ) for d in data ["project" ]["dependencies" ]]
443+ assert deps == ["foo>=1.0" , "bar" ]
444+
445+
446+ def test_initialize_project_config_skips_pip_options (tmp_path , monkeypatch , capsys ):
447+ # `-r`, `-e`, `-c`, `--index-url`, `--extra-index-url`, `--find-links`
448+ # are pip-requirements-file syntax, not PEP 508 dep specifiers. They must
449+ # not land in [project.dependencies] where downstream build tools will
450+ # error trying to parse them. Each skipped line must also produce a
451+ # visible warning so silent data loss is avoided.
452+ monkeypatch .chdir (tmp_path )
453+ _init_git_repo_with_reqs (
454+ tmp_path ,
455+ "-r other.txt\n "
456+ "-e .\n "
457+ "--index-url https://pypi.org/simple\n "
458+ "--extra-index-url https://example.com/simple\n "
459+ "--find-links ./local-wheels\n "
460+ "foo>=1.0\n " ,
461+ )
462+ initialize_project_config ()
463+ with open (tmp_path / "pyproject.toml" ) as f :
464+ data = tomlkit .parse (f .read ())
465+ deps = [str (d ) for d in data ["project" ]["dependencies" ]]
466+ assert deps == ["foo>=1.0" ]
467+ out = capsys .readouterr ().out
468+ for dropped in ["-r other.txt" , "-e ." , "--index-url" , "--extra-index-url" , "--find-links" ]:
469+ assert dropped in out , f"missing skip warning for { dropped !r} "
470+
471+
472+ def test_initialize_project_config_preserves_vcs_subdirectory_fragment (tmp_path , monkeypatch ):
473+ # Regression guard against a naive `split("#")[0]` fix — VCS fragments
474+ # must survive because `#` is only a comment marker when preceded by
475+ # whitespace (pip's rule).
476+ monkeypatch .chdir (tmp_path )
477+ _init_git_repo_with_reqs (
478+ tmp_path ,
479+ "git+https://github.com/org/mono.git#subdirectory=pkg\n " ,
480+ )
481+ initialize_project_config ()
482+ with open (tmp_path / "pyproject.toml" ) as f :
483+ data = tomlkit .parse (f .read ())
484+ deps = [str (d ) for d in data ["project" ]["dependencies" ]]
485+ assert deps == ["git+https://github.com/org/mono.git#subdirectory=pkg" ]
486+
487+
488+ def test_initialize_project_config_vcs_with_inline_comment (tmp_path , monkeypatch ):
489+ monkeypatch .chdir (tmp_path )
490+ _init_git_repo_with_reqs (
491+ tmp_path ,
492+ "git+https://github.com/org/mono.git#subdirectory=pkg # monorepo dep\n " ,
493+ )
494+ initialize_project_config ()
495+ with open (tmp_path / "pyproject.toml" ) as f :
496+ data = tomlkit .parse (f .read ())
497+ deps = [str (d ) for d in data ["project" ]["dependencies" ]]
498+ assert deps == ["git+https://github.com/org/mono.git#subdirectory=pkg" ]
0 commit comments