<commit_before>package python

import (
	"path/filepath"

	"github.com/kr/fs"
	"sourcegraph.com/sourcegraph/srcgraph/config"
	"sourcegraph.com/sourcegraph/srcgraph/scan"
	"sourcegraph.com/sourcegraph/srcgraph/unit"
)

func init() {
	scan.Register("python", &fauxScanner{})
	unit.Register("python", &FauxPackage{})
}

type fauxScanner struct{}

func (p *fauxScanner) Scan(dir string, c *config.Repository) ([]unit.SourceUnit, error) {
	var files []string
	walker := fs.Walk(dir)
	for walker.Step() {
		if err := walker.Err(); err == nil && !walker.Stat().IsDir() && filepath.Ext(walker.Path()) == ".py" {
			file, _ := filepath.Rel(dir, walker.Path())
			files = append(files, file)
		}
	}

	if len(files) > 0 {
		return []unit.SourceUnit{&FauxPackage{Files: files}}, nil
	} else {
		return nil, nil
	}
}<commit_msg>require python source units to have a setup.py file (fixes #766)<commit_after>package python

import (
	"path/filepath"

	"github.com/kr/fs"
	"sourcegraph.com/sourcegraph/srcgraph/config"
	"sourcegraph.com/sourcegraph/srcgraph/scan"
	"sourcegraph.com/sourcegraph/srcgraph/unit"
)

func init() {
	scan.Register("python", &fauxScanner{})
	unit.Register("python", &FauxPackage{})
}

type fauxScanner struct{}

func (p *fauxScanner) Scan(dir string, c *config.Repository) ([]unit.SourceUnit, error) {
	var files []string
	walker := fs.Walk(dir)
	var foundSetupPy bool
	for walker.Step() {
		if err := walker.Err(); err == nil && !walker.Stat().IsDir() && filepath.Ext(walker.Path()) == ".py" {
			// pydep will fail if there's no setup.py file.
			if filepath.Base(walker.Path()) == "setup.py" {
				foundSetupPy = true
			}

			file, _ := filepath.Rel(dir, walker.Path())
			files = append(files, file)
		}
	}

	if len(files) > 0 && foundSetupPy {
		return []unit.SourceUnit{&FauxPackage{Files: files}}, nil
	} else {
		return nil, nil
	}
}
{'fraction_non_alphanumeric': 0.1722462203023758, 'fraction_numerical': 0.0026997840172786176, 'mean_word_length': 4.30945558739255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3678262', 'n_tokens_mistral': 717, 'n_tokens_neox': 671, 'n_words': 143}