Skip to content

Commit 6bcec2c

Browse files
committed
Initial import.
1 parent c841944 commit 6bcec2c

File tree

305 files changed

+37984
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+37984
-0
lines changed

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.aux
2+
*.bbl
3+
*.blg
4+
*.log
5+
*.out
6+
*.pdf
7+
*.ps
8+
*.dvi
9+
*.synctex.gz
10+
*~
11+
*.egg-info/
12+
clients/python/build/*
13+
__pycache__
14+
*.py[cod]

.golangci.yml

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Copyright 2023 DeepMind Technologies Limited
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+
linters-settings:
16+
depguard:
17+
list-type: denylist
18+
packages:
19+
# logging is allowed only by logutils.Log, logrus
20+
# is allowed to use only in logutils package
21+
- github.com/sirupsen/logrus
22+
packages-with-error-message:
23+
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
24+
dupl:
25+
threshold: 100
26+
funlen:
27+
lines: 100
28+
statements: 50
29+
goconst:
30+
min-len: 2
31+
min-occurrences: 3
32+
gocritic:
33+
enabled-tags:
34+
- diagnostic
35+
- experimental
36+
- opinionated
37+
- performance
38+
- style
39+
disabled-checks:
40+
- dupImport # https://github.com/go-critic/go-critic/issues/845
41+
- ifElseChain
42+
- octalLiteral
43+
- typeUnparen
44+
- unnamedResult
45+
- whyNoLint
46+
gocyclo:
47+
min-complexity: 15
48+
goimports:
49+
local-prefixes: github.com/golangci/golangci-lint
50+
gomnd:
51+
# don't include the "operation" and "assign"
52+
checks:
53+
- argument
54+
- case
55+
- condition
56+
- return
57+
ignored-numbers:
58+
- '0'
59+
- '1'
60+
- '2'
61+
- '3'
62+
ignored-functions:
63+
- strings.SplitN
64+
65+
govet:
66+
check-shadowing: false
67+
settings:
68+
printf:
69+
funcs:
70+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
71+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
72+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
73+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
74+
lll:
75+
line-length: 300
76+
misspell:
77+
locale: US
78+
nolintlint:
79+
allow-unused: false # report any unused nolint directives
80+
require-explanation: false # don't require an explanation for nolint directives
81+
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
82+
revive:
83+
rules:
84+
- name: exported
85+
staticcheck:
86+
checks:
87+
- '-SA1019' # disable package being imported more than once because of protos imported as pb and pbgrpc.
88+
stylecheck:
89+
checks:
90+
- '-SA1019' # disable package being imported more than once because of protos imported as pb and pbgrpc.
91+
92+
linters:
93+
disable-all: true
94+
enable:
95+
- depguard
96+
- dogsled
97+
- errcheck
98+
- exportloopref
99+
- funlen
100+
- goconst
101+
- godot
102+
- gofmt
103+
- goimports
104+
- goprintffuncname
105+
- ineffassign
106+
- misspell
107+
- nakedret
108+
- nolintlint
109+
- revive
110+
- staticcheck
111+
- stylecheck
112+
- typecheck
113+
- unconvert
114+
- whitespace
115+
116+
# don't enable:
117+
# - bodyclose
118+
# - asciicheck
119+
# - noctx
120+
# - dupl
121+
# - lll
122+
# - scopelint
123+
# - gochecknoinits
124+
# - gochecknoglobals
125+
# - gocognit
126+
# - gocritic #super slow
127+
# - gocyclo #false positive
128+
# - godox
129+
# - goerr113
130+
# - gomnd
131+
# - gosec
132+
# - gosimple #super slow
133+
# - govet #super slow
134+
# - interfacer
135+
# - maligned
136+
# - nestif
137+
# - prealloc
138+
# - testpackage
139+
# - wsl
140+
# - unparam
141+
# - unused #has false positive (ans is slow)
142+
143+
issues:
144+
include:
145+
- EXC0012 # EXC0012 revive: Annoying issue about not having a comment. The rare codebase has such comments
146+
- EXC0014 # EXC0014 revive: Annoying issue about not having a comment. The rare codebase has such comments
147+
148+
# Excluding configuration per-path, per-linter, per-text and per-source
149+
exclude-rules:
150+
- path: _test\.go
151+
linters:
152+
- gomnd
153+
154+
- path: pkg/golinters/errcheck.go
155+
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
156+
- path: pkg/commands/run.go
157+
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
158+
- path: pkg/commands/run.go
159+
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used."
160+
161+
- path: pkg/golinters/gofumpt.go
162+
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
163+
- path: pkg/golinters/staticcheck_common.go
164+
text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead."
165+
- path: pkg/lint/lintersdb/manager.go
166+
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."
167+
168+
run:
169+
timeout: 5m
170+
skip-dirs:
171+
- test/testdata_etc # test files
172+
- internal/cache # extracted from Go code
173+
- internal/renameio # extracted from Go code
174+
- internal/robustio # extracted from Go code
175+

.pre-commit.git

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/bin/zsh
2+
3+
autoload -U colors
4+
colors
5+
6+
GOFMT=`which gofmt`
7+
8+
if [[ ! -x "$GOFMT" ]]; then
9+
printf "\t\033[41mPlease install gofmt.\033[0m"
10+
exit 1
11+
fi
12+
13+
find . \( -name "*.go" ! -name "*.pb.go" \) -exec $GOFMT -w {} \;
14+
15+
REVIVE=`which revive`
16+
17+
if [[ ! -x "$REVIVE" ]]; then
18+
printf "\t\033[41mPlease install revive (https://github.com/mgechev/revive).\033[0m"
19+
exit 1
20+
fi
21+
22+
PIPENV=`which pipenv`
23+
24+
if [[ ! -x "$PIPENV" ]]; then
25+
printf "\t\033[41mPlease install pipenv (https://pipenv.pypa.io/en/latest/install/).\033[0m"
26+
exit 1
27+
fi
28+
29+
30+
FOLDERS=`find . -type f -name "*.go" -exec dirname "{}" \; | awk -F "/" '{print $2}' | awk 'NF' | sort -u`
31+
32+
PASS=true
33+
34+
for FOLDER in $(echo $FOLDERS)
35+
do
36+
ENV="GOOS= GOARCH="
37+
# Formatting Go code.
38+
CMD="$ENV $GOFMT -s -w $FOLDER"
39+
echo $CMD
40+
zsh -c "$CMD"
41+
if [[ $? == 0 ]]; then
42+
printf "\033[32m$GOFMT $FOLDER\033[0m \033[0;30m\033[42mPASS\033[0m\n"
43+
else
44+
printf "\033[31m$GOFMT $FOLDER\033[0m \033[0;30m\033[41mFAILURE!\033[0m\n"
45+
PASS=false
46+
fi
47+
48+
# Running the linter.
49+
if [[ $FOLDER == 'wasm' ]]; then
50+
ENV="GOOS=js GOARCH=wasm"
51+
else
52+
EMV="GOOS= GOARCH="
53+
fi
54+
CMD="$ENV $REVIVE --config .revive.toml $FOLDER/..."
55+
echo $CMD
56+
zsh -c "$CMD"
57+
if [[ $? == 0 ]]; then
58+
printf "\033[32m$REVIVE $FOLDER\033[0m \033[0;30m\033[42mPASS\033[0m\n"
59+
else
60+
printf "\033[31m$REVIVE $FOLDER\033[0m \033[0;30m\033[41mFAILURE!\033[0m\n"
61+
PASS=false
62+
fi
63+
64+
# Running the tests.
65+
CMD="$ENV go test -vet=all ./$FOLDER/..."
66+
echo $CMD
67+
zsh -c "$CMD"
68+
if [[ $? == 0 ]]; then
69+
printf "\033[32mTests $FOLDER\033[0m \033[0;30m\033[42mPASS\033[0m\n"
70+
else
71+
printf "\033[31mTests $FOLDER\033[0m \033[0;30m\033[41mFAILURE!\033[0m\n"
72+
PASS=false
73+
fi
74+
done
75+
76+
# Check the python client for formatting and run the fast tests.
77+
# This all needs to happen inside the pipenv shell (managed environment).
78+
79+
# Step: Find the base directory (where this script is).
80+
BASE=$( dirname -- "$( readlink -f -- "$0"; )"; )
81+
cd "$BASE"
82+
83+
# Step: Fetch the python virtual environment used for development.
84+
cd clients/python
85+
source $(pipenv --venv)/bin/activate
86+
87+
# Step: use the formatter to check all files are correctly formatted.
88+
yapf -i --recursive multiscope examples
89+
90+
if [[ $? == 0 ]]; then
91+
printf "\033[32mPython yapf formatter.\033[0m \033[0;30m\033[42mPASS\033[0m\n"
92+
else
93+
printf "\033[31mPython yapf formatter.\033[0m \033[0;30m\033[41mFAILURE!\033[0m\n"
94+
PASS=false
95+
fi
96+
97+
# Step: check with google pytype compiler.
98+
pytype
99+
if [[ $? == 0 ]]; then
100+
printf "\033[32mPytype static analyzer.\033[0m \033[0;30m\033[42mPASS\033[0m\n"
101+
else
102+
printf "\033[31mPython static analyzer.\033[0m \033[0;30m\033[41mFAILURE!\033[0m\n"
103+
PASS=false
104+
fi
105+
106+
# Disable python test because python seems unreliable on MacOS.
107+
if [[ -z "$ENABLE_PYTHON_CHECKS" ]]; then
108+
# Cleanup python:
109+
deactivate
110+
111+
printf "$fg[yellow]"
112+
printf "**********************************\n"
113+
printf "* WARNING PYTHON CHECKS DISABLED *\n"
114+
printf "**********************************\n"
115+
printf "$fg[default]"
116+
if ! $PASS; then
117+
printf "$fg[red]PRE-COMMIT HOOK FAILED$fg[default]\n"
118+
exit 1
119+
else
120+
printf "$fg[green]PRE-COMMIT HOOK SUCCEEDED$fg[default]\n"
121+
exit 0
122+
fi
123+
fi
124+
125+
126+
# Step: run the tests.
127+
python multiscope/run_tests.py --only_fast_tests=True
128+
129+
if [[ $? == 0 ]]; then
130+
printf "\033[32mPython tests.\033[0m \033[0;30m\033[42mPASS\033[0m\n"
131+
else
132+
printf "\033[31mPython tests.\033[0m \033[0;30m\033[41mFAILURE!\033[0m\n"
133+
PASS=false
134+
fi
135+
136+
# Step Final: cleanup.
137+
deactivate
138+
139+
if ! $PASS; then
140+
printf "\033[0;30m\033[41mPRE-COMMIT HOOK FAILED\033[0m\n"
141+
exit 1
142+
else
143+
printf "\033[0;30m\033[42mPRE-COMMIT HOOK SUCCEEDED\033[0m\n"
144+
fi
145+
146+
exit 0

.revive.toml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ignoreGeneratedHeader = false
2+
severity = "warning"
3+
confidence = 0.8
4+
errorCode = 0
5+
warningCode = 0
6+
7+
[rule.blank-imports]
8+
[rule.context-as-argument]
9+
[rule.context-keys-type]
10+
[rule.dot-imports]
11+
[rule.error-return]
12+
[rule.error-strings]
13+
[rule.error-naming]
14+
[rule.exported]
15+
[rule.if-return]
16+
[rule.increment-decrement]
17+
[rule.var-naming]
18+
[rule.var-declaration]
19+
[rule.package-comments]
20+
[rule.range]
21+
[rule.receiver-naming]
22+
[rule.time-naming]
23+
[rule.unexported-return]
24+
[rule.indent-error-flow]
25+
[rule.errorf]
26+
[rule.empty-block]
27+
[rule.superfluous-else]
28+
# [rule.unused-parameter]
29+
[rule.unreachable-code]
30+
[rule.redefines-builtin-id]
31+
[rule.use-any]

0 commit comments

Comments
 (0)