@@ -24,17 +24,17 @@ type Freeze struct {
2424func (cmd * Freeze ) getPrintFunc () (func (), error ) {
2525 if cmd .printMode == "human" {
2626 return cmd .printStyleHuman , nil
27+ } else if cmd .printMode == "pip" {
28+ return cmd .printStylePIP , nil
2729 } else {
2830 return nil , & ferror.UnexpectedMode {Mode : cmd .printMode }
2931 }
3032}
3133
32- // printStyleHuman prints a list of packages in a human-readable style, including
33- // general info about the number of packages and their weight.
34+ // printStyleHuman outputs a list of packages in a human-readable style,
35+ // including general info about the number of packages and their weight.
3436//
35- // Function ignores packages with an error, which means the error will never be
36- // returned. Packages that failed to load will be displayed at the end as a
37- // warning line.
37+ // Packages that failed to load will be displayed at the end as a warning line.
3838func (cmd * Freeze ) printStyleHuman () {
3939 var brokenPackages []string
4040 var count int
@@ -66,6 +66,24 @@ func (cmd *Freeze) printStyleHuman() {
6666 }
6767}
6868
69+ // printStylePIP outputs a list of packages in PIP style, but with comments.
70+ // Packages that failed to load will be commented out.
71+ func (cmd * Freeze ) printStylePIP () {
72+ fmt .Printf (
73+ "# This file generated by Fext (%s)\n # Broken packages are commented out\n \n " ,
74+ config .Version ,
75+ )
76+
77+ for _ , metaDir := range cmd .metaDirectories {
78+ p , err := pkg .LoadFromMetaDir (metaDir )
79+ if err == nil {
80+ fmt .Printf ("%s==%s\n " , p .Name , p .Version )
81+ } else {
82+ fmt .Printf ("# %s\n " , metaDir )
83+ }
84+ }
85+ }
86+
6987// scanMetaDirectories goes through the directory with python modules and
7088// packages, selects the meta-directories and appends them to the metaDirectories
7189// attribute. Returns an error if the folder could not be read.
0 commit comments