Skip to content

Commit 61cb550

Browse files
authored
Filter editable commands out of read requirements (#2414)
* Do not consider lines with editable commands as part of the read requirements output
1 parent a433ddd commit 61cb550

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/requirements/requirements.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func CurrentRequirements(tmpDir string) (string, error) {
4343
}
4444

4545
func ReadRequirements(path string) ([]string, error) {
46+
re := regexp.MustCompile(`(?m)^\s*-e\s+\.\s*$`)
47+
4648
fh, err := os.Open(path)
4749
if err != nil {
4850
return nil, err
@@ -63,6 +65,10 @@ func ReadRequirements(path string) ([]string, error) {
6365
continue
6466
}
6567

68+
if re.MatchString(line) {
69+
continue
70+
}
71+
6672
// Remove any trailing comments
6773
if idx := strings.Index(line, "#"); idx >= 0 {
6874
line = line[:idx]

pkg/requirements/requirements_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,17 @@ func TestSplitPinnedPythonRequirement(t *testing.T) {
423423
}
424424
}
425425

426+
func TestReadRequirementsWithEditable(t *testing.T) {
427+
srcDir := t.TempDir()
428+
reqFile := path.Join(srcDir, "requirements.txt")
429+
err := os.WriteFile(reqFile, []byte("-e .\ntorch==2.5.1"), 0o644)
430+
require.NoError(t, err)
431+
432+
requirements, err := ReadRequirements(reqFile)
433+
require.NoError(t, err)
434+
require.Equal(t, []string{"torch==2.5.1"}, requirements)
435+
}
436+
426437
func checkRequirements(t *testing.T, expected []string, actual []string) {
427438
t.Helper()
428439
for n, expectLine := range expected {

0 commit comments

Comments
 (0)