Skip to content

Commit 5dbfdb6

Browse files
author
Peter Mounce
committed
Apply automatic fixes
1 parent b6b9815 commit 5dbfdb6

File tree

13 files changed

+364
-208
lines changed

13 files changed

+364
-208
lines changed

.buildkite/local-pipeline.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
---
12
steps:
2-
- label: "Test"
3+
- label: Test
34
command: echo "Hello World"
45
env:
56
BUILDKITE_CLEAN_CHECKOUT: true
@@ -19,4 +20,4 @@ steps:
1920
# p4port: localhost:1666
2021
# p4user: banana
2122
# stream: //stream-depot/main # will checkout to ../../__stream_depot_main
22-
# share_workspace: yes
23+
# share_workspace: yes

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
---
12
language: python
23
# cache: pip # not enough installed via pip to justify
34
python:
4-
- "3.6"
5+
- '3.6'
56
os:
67
- linux
78
before_install:
89
- pip install -U pip
9-
install:
10+
install:
1011
- pip install -r ./ci/requirements.txt
1112
- pip install -r ./python/requirements.txt
1213
- ./ci/install_$TRAVIS_OS_NAME.sh

dev/setup_env_osx.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/bin/bash
22
set -eo pipefail
33

4-
command -v "python3" >/dev/null 2>&1 || { echo >&2 "I require python3 but it's not installed. Officially supported version is 3.7.5"; exit 1; }
4+
command -v "python3" >/dev/null 2>&1 || {
5+
echo >&2 "I require python3 but it's not installed. Officially supported version is 3.7.5"
6+
exit 1
7+
}
58

69
readonly root="${BASH_SOURCE%/*}/.."
710

@@ -13,23 +16,23 @@ python3 -m virtualenv "${venv_dir}"
1316

1417
platform=$(python3 -c "import platform; print(platform.system())")
1518
if [[ "${platform}" == "Windows" ]]; then
16-
venv_bin="${venv_dir}/Scripts"
19+
venv_bin="${venv_dir}/Scripts"
1720
else
18-
venv_bin="${venv_dir}/bin"
21+
venv_bin="${venv_dir}/bin"
1922
fi
2023

2124
"${venv_bin}/python" -m pip install -r "${root}/python/requirements.txt"
2225
"${venv_bin}/python" -m pip install -r "${root}/ci/requirements.txt"
2326

2427
# Install p4d binary if missing
2528
if ! [[ -x "$(command -v p4d)" ]]; then
26-
wget http://www.perforce.com/downloads/perforce/r18.2/bin.macosx1010x86_64/p4d && sudo chmod +x p4d && sudo mv p4d /usr/local/bin/p4d
29+
wget http://www.perforce.com/downloads/perforce/r18.2/bin.macosx1010x86_64/p4d && sudo chmod +x p4d && sudo mv p4d /usr/local/bin/p4d
2730
fi
2831

2932
if ! p4d -V | grep '2018.2'; then
30-
echo "WARNING: Version r18.2 (2018.2) of p4d is recommended for running tests. This version may not be compatible with existing server fixture."
33+
echo "WARNING: Version r18.2 (2018.2) of p4d is recommended for running tests. This version may not be compatible with existing server fixture."
3134
fi
3235

3336
if ! [[ -x "$(command -v bk)" ]]; then
34-
echo "WARNING: `bk` cli is not installed. https://github.com/buildkite/cli"
37+
echo "WARNING: $(bk) cli is not installed. https://github.com/buildkite/cli"
3538
fi

examples/buildkite-trigger.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,38 @@
33
# my-pipeline change-commit //depot/... "python %//depot/scripts/buildkite-trigger.py% <pipeline> %changelist% %user%"
44
import sys
55
import subprocess
6+
67
try:
78
from urllib.request import urlopen, Request
89
except ImportError:
910
from urllib2 import urlopen, Request
1011
import json
1112

1213
__BUILDKITE_TOKEN__ = "<your_token>"
13-
14+
1415
__ORG_SLUG__ = "<your_org>"
1516
pipeline_slug = sys.argv[1]
1617
changelist = sys.argv[2]
1718
user = sys.argv[3]
1819

19-
description = subprocess.check_output(["p4", "-Ztag", "-F", "%desc%", "describe", changelist])
20+
description = subprocess.check_output(
21+
["p4", "-Ztag", "-F", "%desc%", "describe", changelist]
22+
)
2023

2124
headers = {
2225
'Content-Type': 'application/json',
23-
'Authorization': 'Bearer %s' % __BUILDKITE_TOKEN__
26+
'Authorization': 'Bearer %s' % __BUILDKITE_TOKEN__,
2427
}
2528
payload = {
2629
'commit': '@' + changelist,
2730
'branch': 'master',
2831
'message': description,
29-
'author': {
30-
'name': user
31-
}
32+
'author': {'name': user},
3233
}
33-
url = "https://api.buildkite.com/v2/organizations/%s/pipelines/%s/builds" % (__ORG_SLUG__, pipeline_slug)
34+
url = "https://api.buildkite.com/v2/organizations/%s/pipelines/%s/builds" % (
35+
__ORG_SLUG__,
36+
pipeline_slug,
37+
)
3438

3539
params = json.dumps(payload).encode('utf8')
3640
req = Request(url, data=params, headers=headers)

examples/buildkite-trigger.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
54
# P4 Trigger script that triggers buildkite builds
65
# Usage:
76
# my-pipeline change-commit //depot/... "%//depot/scripts/buildkite-trigger.sh% <organisation> <pipeline> %changelist% %user% %email%"

examples/cleanup-unused-workspaces.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,24 @@
2727

2828
# Filter by basic prefix matching.
2929
# May want to include filtering by user and other fields to avoid false positives.
30-
bk_clients = [client for client in clients
31-
if client.get('client', '').startswith('bk-p4-')]
30+
bk_clients = [
31+
client for client in clients if client.get('client', '').startswith('bk-p4-')
32+
]
3233

3334
now = datetime.now()
3435
n_days_ago = (now - timedelta(days=__days_unused__)).timestamp()
35-
unused_clients = [client for client in bk_clients
36-
if int(client.get('Access')) < n_days_ago]
36+
unused_clients = [
37+
client for client in bk_clients if int(client.get('Access')) < n_days_ago
38+
]
3739

3840
pprint(unused_clients)
39-
proceed = input("Will delete %d/%d Buildkite clients. Continue? (y/n) " % (len(unused_clients),len(bk_clients))).lower() == 'y'
41+
proceed = (
42+
input(
43+
"Will delete %d/%d Buildkite clients. Continue? (y/n) "
44+
% (len(unused_clients), len(bk_clients))
45+
).lower()
46+
== 'y'
47+
)
4048

4149
if proceed:
4250
for client in unused_clients:

hooks/checkout

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ set -eo pipefail
33

44
plugin_root="${BASH_SOURCE%/*}/.."
55

6-
76
# Try to use explicit python3 if its installed
87
python_bin="python3"
98
if ! [[ -x "$(command -v ${python_bin})" ]]; then
10-
python_bin="python"
9+
python_bin="python"
1110
fi
1211

1312
# Ensure some version of virtualenv is installed
1413
# Lazy install avoids races between different jobs wanting different versions
1514
if [[ ! $(${python_bin} -m pip freeze) =~ "virtualenv==" ]]; then
16-
${python_bin} -m pip install "virtualenv==16.7.7"
15+
${python_bin} -m pip install "virtualenv==16.7.7"
1716
fi
1817

1918
# Unique virtualenv for requirements.txt
@@ -22,20 +21,20 @@ venv_dir="${BUILDKITE_BUILD_CHECKOUT_PATH}/../.perforce-plugin-venv-${venv_md5}"
2221

2322
platform=$(${python_bin} -c "import platform; print(platform.system())")
2423
if [[ "${platform}" == "Windows" ]]; then
25-
venv_python_bin="/Scripts/python"
24+
venv_python_bin="/Scripts/python"
2625
else
27-
venv_python_bin="/bin/python"
26+
venv_python_bin="/bin/python"
2827
fi
2928

3029
if ! [[ -d "${venv_dir}" ]]; then
31-
temp_venv_dir=$(mktemp -d -t perforce-plugin-venv-XXXXXX)
32-
trap "rm -rf ${temp_venv_dir}" EXIT
33-
${python_bin} -m virtualenv "${temp_venv_dir}"
34-
${temp_venv_dir}${venv_python_bin} -m pip install -r "${plugin_root}/python/requirements.txt"
35-
if ! [[ -d "${venv_dir}" ]]; then # second check to minimize venv init race
36-
mv "${temp_venv_dir}" "${venv_dir}"
37-
fi
38-
echo "virtualenv created at ${venv_dir}"
30+
temp_venv_dir=$(mktemp -d -t perforce-plugin-venv-XXXXXX)
31+
trap "rm -rf ${temp_venv_dir}" EXIT
32+
${python_bin} -m virtualenv "${temp_venv_dir}"
33+
${temp_venv_dir}${venv_python_bin} -m pip install -r "${plugin_root}/python/requirements.txt"
34+
if ! [[ -d "${venv_dir}" ]]; then # second check to minimize venv init race
35+
mv "${temp_venv_dir}" "${venv_dir}"
36+
fi
37+
echo "virtualenv created at ${venv_dir}"
3938
fi
4039

4140
${venv_dir}${venv_python_bin} "${plugin_root}/python/checkout.py"

hooks/pre-checkout

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
set -eo pipefail
33

44
# Allow sharing of perforce client workspaces for the same stream between pipelines
5-
if [[ "${BUILDKITE_PLUGIN_PERFORCE_SHARE_WORKSPACE}" == true ]] ; then
6-
echo "Workspace sharing enabled"
5+
if [[ "${BUILDKITE_PLUGIN_PERFORCE_SHARE_WORKSPACE}" == true ]]; then
6+
echo "Workspace sharing enabled"
77

8-
STREAM="${BUILDKITE_PLUGIN_PERFORCE_STREAM}"
9-
if [[ -z "${STREAM}" ]] ; then
10-
echo "Error: You must use stream workspaces to enable shared workspaces" >&2
11-
exit 1
12-
fi
13-
if [[ "${BUILDKITE_AGENT_META_DATA_AGENT_COUNT}" -gt 1 ]] ; then
14-
echo "Error: You cannot share stream workspaces when running more than one agent" >&2
15-
exit 1
16-
fi
17-
if [[ "${BUILDKITE_PLUGIN_PERFORCE_STREAM_SWITCHING}" == true ]] ; then
18-
echo "Stream switching enabled"
19-
# Sanitize '//depot/stream-name' to 'depot'
20-
SANITIZED_STREAM=$(echo $STREAM | python -c "import sys; print(sys.stdin.read().split('/')[2]);")
21-
else # Create a directory per-stream
22-
# Sanitize '//depot/stream-name' to '__depot_stream-name'
23-
SANITIZED_STREAM=$(echo $STREAM | python -c "import sys; print(sys.stdin.read().replace('/', '_'));")
24-
fi
25-
# Instead of builds/<agent_number>/<pipeline>, checkout to builds/<stream_name>
26-
PERFORCE_CHECKOUT_PATH="${BUILDKITE_BUILD_CHECKOUT_PATH}/../../${SANITIZED_STREAM}"
27-
export BUILDKITE_BUILD_CHECKOUT_PATH="${PERFORCE_CHECKOUT_PATH}"
28-
echo "Changed BUILDKITE_BUILD_CHECKOUT_PATH to ${PERFORCE_CHECKOUT_PATH}"
29-
fi
8+
STREAM="${BUILDKITE_PLUGIN_PERFORCE_STREAM}"
9+
if [[ -z "${STREAM}" ]]; then
10+
echo "Error: You must use stream workspaces to enable shared workspaces" >&2
11+
exit 1
12+
fi
13+
if [[ "${BUILDKITE_AGENT_META_DATA_AGENT_COUNT}" -gt 1 ]]; then
14+
echo "Error: You cannot share stream workspaces when running more than one agent" >&2
15+
exit 1
16+
fi
17+
if [[ "${BUILDKITE_PLUGIN_PERFORCE_STREAM_SWITCHING}" == true ]]; then
18+
echo "Stream switching enabled"
19+
# Sanitize '//depot/stream-name' to 'depot'
20+
SANITIZED_STREAM=$(echo $STREAM | python -c "import sys; print(sys.stdin.read().split('/')[2]);")
21+
else # Create a directory per-stream
22+
# Sanitize '//depot/stream-name' to '__depot_stream-name'
23+
SANITIZED_STREAM=$(echo $STREAM | python -c "import sys; print(sys.stdin.read().replace('/', '_'));")
24+
fi
25+
# Instead of builds/<agent_number>/<pipeline>, checkout to builds/<stream_name>
26+
PERFORCE_CHECKOUT_PATH="${BUILDKITE_BUILD_CHECKOUT_PATH}/../../${SANITIZED_STREAM}"
27+
export BUILDKITE_BUILD_CHECKOUT_PATH="${PERFORCE_CHECKOUT_PATH}"
28+
echo "Changed BUILDKITE_BUILD_CHECKOUT_PATH to ${PERFORCE_CHECKOUT_PATH}"
29+
fi

plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: Perforce
23
description: Checks out a perforce repository instead of git.
34
author: https://github.com/ca-johnson

0 commit comments

Comments
 (0)