github.com/google/osv-scalibr@v0.4.1/guidedremediation/internal/lockfile/python/requirements.go (about)

     1  // Copyright 2025 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package python provides the lockfile parsing and writing for requirements.txt.
    16  package python
    17  
    18  import (
    19  	"errors"
    20  
    21  	"deps.dev/util/resolve"
    22  	"github.com/google/osv-scalibr/fs"
    23  	"github.com/google/osv-scalibr/guidedremediation/internal/lockfile"
    24  	"github.com/google/osv-scalibr/guidedremediation/result"
    25  	"github.com/google/osv-scalibr/guidedremediation/strategy"
    26  )
    27  
    28  type readWriter struct{}
    29  
    30  // GetReadWriter returns a dummy ReadWriter for requirements.txt as lockfiles.
    31  func GetReadWriter() (lockfile.ReadWriter, error) { return readWriter{}, nil }
    32  
    33  // System returns the ecosystem of this ReadWriter.
    34  func (r readWriter) System() resolve.System { return resolve.PyPI }
    35  
    36  // SupportedStrategies returns the remediation strategies supported for this lockfile.
    37  // We currently don't support any strategies for requirements.txt.
    38  func (r readWriter) SupportedStrategies() []strategy.Strategy {
    39  	return []strategy.Strategy{}
    40  }
    41  
    42  // Read is not supported as intended for requirements.txt.
    43  // It's tricky to read the dependency graph from the requirements.txt, so we rely on pip-compile
    44  // to re-generate requirements.txt if there is manifest (e.g. requirements.in).
    45  func (r readWriter) Read(path string, fsys fs.FS) (*resolve.Graph, error) {
    46  	return nil, errors.New("not supported")
    47  }
    48  
    49  // Write is not supported as intended for requirements.txt.
    50  func (r readWriter) Write(path string, fsys fs.FS, patches []result.Patch, outputPath string) error {
    51  	return errors.New("not supported")
    52  }