Skip to content

Commit

Permalink
Support lockfile generation for python project
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
  • Loading branch information
keshav-space committed Jun 20, 2024
1 parent b025d00 commit 05ac73e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Supported Ecosystems
- **yarn**: https://yarnpkg.com/
- **swift**: https://www.swift.org/documentation/package-manager/
- **cocoapods**: https://cocoapods.org/
- **pypi**: https://pypi.org/


Installation
Expand Down
45 changes: 45 additions & 0 deletions cmd/pypi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright (c) nexB Inc. and others. All rights reserved.
ScanCode is a trademark of nexB Inc.
SPDX-License-Identifier: Apache-2.0
See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
See https://github.com/nexB/dependency-inspector for support or download.
See https://aboutcode.org for more information about nexB OSS projects.
*/

package cmd

import (
"github.com/nexB/dependency-inspector/internal"
"github.com/spf13/cobra"
)

func pypiCmd() *cobra.Command {
pipFreezeFile := "requirements.deplock"
lockFiles := []string{"Pipfile.lock", pipFreezeFile}
lockGenCommand := []string{"pip", "freeze"}
forced := false

pypiCmd := &cobra.Command{
Use: "pypi [path]",
Short: "Generate lockfile for Python project",
Long: `Create lockfile for Python project if it doesn't exist in the specified [path].
If no path is provided, the command defaults to the current directory.`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
internal.CreateLockFile(
lockFiles,
args,
lockGenCommand,
pipFreezeFile,
forced,
)
},
}

pypiCmd.Flags().BoolVarP(&forced, "force", "f", false, "Generate lockfile forcibly, ignoring existing lockfiles")

return pypiCmd
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var ecosystems = []func() *cobra.Command{
yarnCmd,
swiftCmd,
cocoapodsCmd,
pypiCmd,
}

func NewRootCmd() *cobra.Command {
Expand Down

0 comments on commit 05ac73e

Please sign in to comment.