Skip to content

Commit ef2ad47

Browse files
committed
add helpful comments
1 parent 0662051 commit ef2ad47

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

py.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Requirement struct {
1212
Version string
1313
}
1414

15+
// Parse requirements from a raw string in the requirements format expected by pip (e.g., in requirements.txt)
1516
func ParseRequirements(rawReqs string) ([]*Requirement, error) {
1617
rawReqs = strings.TrimSpace(rawReqs)
1718

@@ -33,6 +34,7 @@ func ParseRequirements(rawReqs string) ([]*Requirement, error) {
3334
return reqs, nil
3435
}
3536

37+
// Parse a single raw requirement, e.g., from "flask=1.0.1"
3638
func ParseRequirement(reqStr string) (*Requirement, error) {
3739
reqStr = strings.TrimSpace(reqStr)
3840
match := requirementRegexp.FindStringSubmatch(reqStr)
@@ -48,6 +50,7 @@ func ParseRequirement(reqStr string) (*Requirement, error) {
4850
}, nil
4951
}
5052

53+
// Normalizes package names so they are comparable
5154
func NormalizedPkgName(pkg string) string {
5255
return strings.ToLower(pkg)
5356
}

pypi.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package cheerio
22

33
import (
44
"fmt"
5-
"github.com/beyang/cheerio/util"
6-
"github.com/beyang/go-version"
75
"io/ioutil"
86
"net/http"
97
"path/filepath"
108
"regexp"
119
"strings"
10+
11+
"github.com/beyang/cheerio/util"
12+
"github.com/beyang/go-version"
1213
)
1314

1415
var DefaultPyPI = &PackageIndex{URI: "https://pypi.python.org"}
@@ -17,6 +18,7 @@ type PackageIndex struct {
1718
URI string
1819
}
1920

21+
// Get names of all packages served by a PyPI server.
2022
func (p *PackageIndex) AllPackages() ([]string, error) {
2123
pkgs := make([]string, 0)
2224

repo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ var repoPatterns = []*regexp.Regexp{
1414

1515
var pkgInfoPattern = regexp.MustCompile(`(?:[^/]+/)*PKG\-INFO`)
1616

17+
// Returns the source repository URL for a given PyPI package. This information is not explicitly specified anywhere in PyPI metadata, so try to infer
18+
// it by doing the following: First, check if it is hardcoded below. If not, then fetch the metadata from the PyPI server and check if the website
19+
// (specified in the metdata) pattern matches a repository URL.
1720
func (p *PackageIndex) FetchSourceRepoURL(pkg string) (string, error) {
1821
b, err := p.FetchRawMetadata(pkg, pkgInfoPattern, pkgInfoPattern, pkgInfoPattern)
1922
if err != nil {

req.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ func init() {
2828
}
2929
}
3030

31+
// Dependency graph over repositories in a given Python Package Index.
3132
type PyPIGraph struct {
3233
Req map[string][]string
3334
ReqBy map[string][]string
3435
}
3536

37+
// Deserializes a PyPIGraph stored in a file
3638
func NewPyPIGraph(file string) (*PyPIGraph, error) {
3739
var graph *PyPIGraph
3840

toplevel.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77

88
var topLevelTxtPattern = regexp.MustCompile(`(?:[^/]+/)*(?:[^/]*\.egg\-info/top_level\.txt)`)
99

10+
// Returns the top-level modules for a given PyPI package. This information is typically stored in the PyPI metadata, which is fetched from the remote
11+
// PyPI server. In some cases where the information is unavailable in the metadata, it has been hard-coded below.
1012
func (p *PackageIndex) FetchSourceTopLevelModules(pkg string) ([]string, error) {
1113
b, err := p.FetchRawMetadata(pkg, topLevelTxtPattern, topLevelTxtPattern, topLevelTxtPattern)
1214
if err != nil {

0 commit comments

Comments
 (0)