Skip to content

Commit 9a2ed84

Browse files
author
Chris Elion
authored
add pre-commit hook for dotnet-format (#4362)
1 parent 9df821d commit 9a2ed84

File tree

88 files changed

+377
-311
lines changed

Some content is hidden

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

88 files changed

+377
-311
lines changed

.circleci/config.yml

+18
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,23 @@ jobs:
113113
# Need ruby for search-and-replace
114114
sudo apt-get update
115115
sudo apt-get install ruby-full
116+
117+
# install dotnet and the formatter - see https://docs.microsoft.com/en-us/dotnet/core/install/linux-debian#debian-9-
118+
pushd ~
119+
wget -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
120+
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
121+
wget https://packages.microsoft.com/config/debian/9/prod.list
122+
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
123+
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
124+
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
125+
popd
126+
127+
sudo apt-get install -y apt-transport-https && \
128+
sudo apt-get update && \
129+
sudo apt-get install -y dotnet-sdk-3.1 && \
130+
dotnet tool install -g dotnet-format --version 4.1.131201
131+
132+
echo "Setting up venv"
116133
python3 -m venv venv
117134
. venv/bin/activate
118135
pip install --upgrade pip
@@ -131,6 +148,7 @@ jobs:
131148
name: Check Code Style using pre-commit
132149
command: |
133150
. venv/bin/activate
151+
export PATH="$PATH:~/.dotnet/tools"
134152
pre-commit run --show-diff-on-failure --all-files
135153
136154
markdown_link_check:
File renamed without changes.

.pre-commit-config.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,9 @@ repos:
132132
name: validate release links
133133
language: script
134134
entry: utils/validate_release_links.py
135-
135+
- id: dotnet-format
136+
name: dotnet-format
137+
language: script
138+
entry: utils/run_dotnet_format.py
139+
types: [c#]
136140

DevProject/Assets/ML-Agents/Scripts/Tests/Performance/SensorPerformanceTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void TestCollectObservationsAgentMarkers()
161161
{
162162
using (Measure.ProfilerMarkers(s_Markers))
163163
{
164-
for(var i=0; i<k_MarkerTestSteps; i++)
164+
for (var i = 0; i < k_MarkerTestSteps; i++)
165165
{
166166
RunAgent<CollectObservationsAgent>(k_NumAgentSteps, 7, ObservableAttributeOptions.Ignore);
167167
}

Project/Assets/ML-Agents/Editor/DisableBurstFromMenu.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if UNITY_CLOUD_BUILD
1+
#if UNITY_CLOUD_BUILD
22
using UnityEditor;
33

44
public class DisableBurstFromMenu

Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class CrawlerAgent : Agent
1313
Vector3 m_WalkDir; //Direction to the target
1414
Quaternion m_WalkDirLookRot; //Will hold the rotation to our target
1515

16-
[Header("Target To Walk Towards")] [Space(10)]
16+
[Header("Target To Walk Towards")]
17+
[Space(10)]
1718
public TargetController target; //Target the agent will walk towards.
1819

1920
[Header("Body Parts")] [Space(10)] public Transform body;
@@ -27,20 +28,23 @@ public class CrawlerAgent : Agent
2728
public Transform leg3Lower;
2829

2930

30-
[Header("Orientation")] [Space(10)]
31+
[Header("Orientation")]
32+
[Space(10)]
3133
//This will be used as a stabilized model space reference point for observations
3234
//Because ragdolls can move erratically during training, using a stabilized reference transform improves learning
3335
public OrientationCubeController orientationCube;
3436

3537
JointDriveController m_JdController;
3638

37-
[Header("Reward Functions To Use")] [Space(10)]
39+
[Header("Reward Functions To Use")]
40+
[Space(10)]
3841
public bool rewardMovingTowardsTarget; // Agent should move towards target
3942

4043
public bool rewardFacingTarget; // Agent should face the target
4144
public bool rewardUseTimePenalty; // Hurry up
4245

43-
[Header("Foot Grounded Visualization")] [Space(10)]
46+
[Header("Foot Grounded Visualization")]
47+
[Space(10)]
4448
public bool useFootGroundedVisualization;
4549

4650
public MeshRenderer foot0;
@@ -208,8 +212,8 @@ void RewardFunctionMovingTowards()
208212
{
209213
throw new ArgumentException(
210214
"NaN in movingTowardsDot.\n" +
211-
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+
212-
$" body.velocity: {m_JdController.bodyPartsDict[body].rb.velocity}\n"+
215+
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n" +
216+
$" body.velocity: {m_JdController.bodyPartsDict[body].rb.velocity}\n" +
213217
$" maximumWalkingSpeed: {maximumWalkingSpeed}"
214218
);
215219
}
@@ -226,7 +230,7 @@ void RewardFunctionFacingTarget()
226230
{
227231
throw new ArgumentException(
228232
"NaN in movingTowardsDot.\n" +
229-
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n"+
233+
$" orientationCube.transform.forward: {orientationCube.transform.forward}\n" +
230234
$" body.forward: {body.forward}"
231235
);
232236
}

Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void Update()
5050
// Send stats via SideChannel so that they'll appear in TensorBoard.
5151
// These values get averaged every summary_frequency steps, so we don't
5252
// need to send every Update() call.
53-
if ((Time.frameCount % 100)== 0)
53+
if ((Time.frameCount % 100) == 0)
5454
{
5555
m_Recorder.Add("TotalScore", totalScore);
5656
}

Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,29 @@ public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
4040
// Mask the necessary actions if selected by the user.
4141
if (maskActions)
4242
{
43-
// Prevents the agent from picking an action that would make it collide with a wall
43+
// Prevents the agent from picking an action that would make it collide with a wall
4444
var positionX = (int)transform.position.x;
4545
var positionZ = (int)transform.position.z;
4646
var maxPosition = (int)m_ResetParams.GetWithDefault("gridSize", 5f) - 1;
4747

4848
if (positionX == 0)
4949
{
50-
actionMask.WriteMask(0, new []{ k_Left});
50+
actionMask.WriteMask(0, new[] { k_Left });
5151
}
5252

5353
if (positionX == maxPosition)
5454
{
55-
actionMask.WriteMask(0, new []{k_Right});
55+
actionMask.WriteMask(0, new[] { k_Right });
5656
}
5757

5858
if (positionZ == 0)
5959
{
60-
actionMask.WriteMask(0, new []{k_Down});
60+
actionMask.WriteMask(0, new[] { k_Down });
6161
}
6262

6363
if (positionZ == maxPosition)
6464
{
65-
actionMask.WriteMask(0, new []{k_Up});
65+
actionMask.WriteMask(0, new[] { k_Up });
6666
}
6767
}
6868
}

Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AdjustTrainingTimescale.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
using UnityEngine;
44

5-
namespace MLAgentsExamples
5+
namespace MLAgentsExamples
66
{
77
public class AdjustTrainingTimescale : MonoBehaviour
88
{

Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/DirectionIndicator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using UnityEngine;
1+
using UnityEngine;
22

33
namespace Unity.MLAgentsExamples
44
{
55
public class DirectionIndicator : MonoBehaviour
66
{
7-
7+
88
public bool updatedByAgent; //should this be updated by the agent? If not, it will use local settings
99
public Transform transformToFollow; //ex: hips or body
1010
public Transform targetToLookAt; //target in the scene the indicator will point to

Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/JointDriveController.cs

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,31 @@ namespace Unity.MLAgentsExamples
1111
[System.Serializable]
1212
public class BodyPart
1313
{
14-
[Header("Body Part Info")][Space(10)] public ConfigurableJoint joint;
14+
[Header("Body Part Info")] [Space(10)] public ConfigurableJoint joint;
1515
public Rigidbody rb;
1616
[HideInInspector] public Vector3 startingPos;
1717
[HideInInspector] public Quaternion startingRot;
1818

19-
[Header("Ground & Target Contact")][Space(10)]
19+
[Header("Ground & Target Contact")]
20+
[Space(10)]
2021
public GroundContact groundContact;
2122

2223
public TargetContact targetContact;
2324

2425
[FormerlySerializedAs("thisJDController")]
2526
[HideInInspector] public JointDriveController thisJdController;
2627

27-
[Header("Current Joint Settings")][Space(10)]
28+
[Header("Current Joint Settings")]
29+
[Space(10)]
2830
public Vector3 currentEularJointRotation;
2931

3032
[HideInInspector] public float currentStrength;
3133
public float currentXNormalizedRot;
3234
public float currentYNormalizedRot;
3335
public float currentZNormalizedRot;
3436

35-
[Header("Other Debug Info")][Space(10)]
37+
[Header("Other Debug Info")]
38+
[Space(10)]
3639
public Vector3 currentJointForce;
3740

3841
public float currentJointForceSqrMag;
@@ -99,7 +102,8 @@ public void SetJointStrength(float strength)
99102

100103
public class JointDriveController : MonoBehaviour
101104
{
102-
[Header("Joint Drive Settings")][Space(10)]
105+
[Header("Joint Drive Settings")]
106+
[Space(10)]
103107
public float maxJointSpring;
104108

105109
public float jointDampen;

Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Unity.MLAgentsExamples
2323
/// </summary>
2424
public class ModelOverrider : MonoBehaviour
2525
{
26-
HashSet<string> k_SupportedExtensions = new HashSet<string>{"nn", "onnx"};
26+
HashSet<string> k_SupportedExtensions = new HashSet<string> { "nn", "onnx" };
2727
const string k_CommandLineModelOverrideFlag = "--mlagents-override-model";
2828
const string k_CommandLineModelOverrideDirectoryFlag = "--mlagents-override-model-directory";
2929
const string k_CommandLineModelOverrideExtensionFlag = "--mlagents-override-model-extension";
@@ -63,7 +63,7 @@ public class ModelOverrider : MonoBehaviour
6363

6464
int TotalCompletedEpisodes
6565
{
66-
get { return m_PreviousAgentCompletedEpisodes + (m_Agent == null ? 0 : m_Agent.CompletedEpisodes); }
66+
get { return m_PreviousAgentCompletedEpisodes + (m_Agent == null ? 0 : m_Agent.CompletedEpisodes); }
6767
}
6868

6969
int TotalNumSteps
@@ -73,7 +73,7 @@ int TotalNumSteps
7373

7474
public bool HasOverrides
7575
{
76-
get { return m_BehaviorNameOverrides.Count > 0 || !string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory); }
76+
get { return m_BehaviorNameOverrides.Count > 0 || !string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory); }
7777
}
7878

7979
public static string GetOverrideBehaviorName(string originalBehaviorName)
@@ -99,17 +99,17 @@ void GetAssetPathFromCommandLine()
9999
var args = commandLineArgsOverride ?? Environment.GetCommandLineArgs();
100100
for (var i = 0; i < args.Length; i++)
101101
{
102-
if (args[i] == k_CommandLineModelOverrideFlag && i < args.Length-2)
102+
if (args[i] == k_CommandLineModelOverrideFlag && i < args.Length - 2)
103103
{
104104
var key = args[i + 1].Trim();
105105
var value = args[i + 2].Trim();
106106
m_BehaviorNameOverrides[key] = value;
107107
}
108-
else if (args[i] == k_CommandLineModelOverrideDirectoryFlag && i < args.Length-1)
108+
else if (args[i] == k_CommandLineModelOverrideDirectoryFlag && i < args.Length - 1)
109109
{
110110
m_BehaviorNameOverrideDirectory = args[i + 1].Trim();
111111
}
112-
else if (args[i] == k_CommandLineModelOverrideExtensionFlag && i < args.Length-1)
112+
else if (args[i] == k_CommandLineModelOverrideExtensionFlag && i < args.Length - 1)
113113
{
114114
m_OverrideExtension = args[i + 1].Trim().ToLower();
115115
var isKnownExtension = k_SupportedExtensions.Contains(m_OverrideExtension);
@@ -124,7 +124,7 @@ void GetAssetPathFromCommandLine()
124124
#endif
125125
}
126126
}
127-
else if (args[i] == k_CommandLineQuitAfterEpisodesFlag && i < args.Length-1)
127+
else if (args[i] == k_CommandLineQuitAfterEpisodesFlag && i < args.Length - 1)
128128
{
129129
Int32.TryParse(args[i + 1], out maxEpisodes);
130130
}
@@ -198,7 +198,7 @@ public NNModel GetModelForBehaviorName(string behaviorName)
198198
{
199199
assetPath = m_BehaviorNameOverrides[behaviorName];
200200
}
201-
else if(!string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory))
201+
else if (!string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory))
202202
{
203203
assetPath = Path.Combine(m_BehaviorNameOverrideDirectory, $"{behaviorName}.{m_OverrideExtension}");
204204
}
@@ -214,7 +214,7 @@ public NNModel GetModelForBehaviorName(string behaviorName)
214214
{
215215
model = File.ReadAllBytes(assetPath);
216216
}
217-
catch(IOException)
217+
catch (IOException)
218218
{
219219
Debug.Log($"Couldn't load file {assetPath} at full path {Path.GetFullPath(assetPath)}", this);
220220
// Cache the null so we don't repeatedly try to load a missing file
@@ -270,7 +270,7 @@ void OverrideModel()
270270

271271
if (!overrideOk && m_QuitOnLoadFailure)
272272
{
273-
if(!string.IsNullOrEmpty(overrideError))
273+
if (!string.IsNullOrEmpty(overrideError))
274274
{
275275
Debug.LogWarning(overrideError);
276276
}

Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/Monitor.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Linq;
33
using UnityEngine;
44

@@ -419,7 +419,7 @@ void OnGUI()
419419
var displayValues = s_DisplayTransformValues[target];
420420

421421
var index = 0;
422-
var orderedKeys = displayValues.Keys.OrderBy(x => - displayValues[x].time);
422+
var orderedKeys = displayValues.Keys.OrderBy(x => -displayValues[x].time);
423423
foreach (var key in orderedKeys)
424424
{
425425
s_KeyStyle.alignment = TextAnchor.MiddleRight;
@@ -560,4 +560,4 @@ void Initialize()
560560
s_RedStyle = s_ColorStyle[5];
561561
}
562562
}
563-
}
563+
}

Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/OrientationCubeController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using UnityEngine;
1+
using UnityEngine;
22

33
namespace Unity.MLAgentsExamples
44
{

Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ProjectSettingsOverrides.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void Awake()
4242
m_OriginalMaximumDeltaTime = Time.maximumDeltaTime;
4343
m_OriginalSolverIterations = Physics.defaultSolverIterations;
4444
m_OriginalSolverVelocityIterations = Physics.defaultSolverVelocityIterations;
45-
m_OriginalReuseCollisionCallbacks = Physics.reuseCollisionCallbacks ;
45+
m_OriginalReuseCollisionCallbacks = Physics.reuseCollisionCallbacks;
4646

4747
// Override
4848
Physics.gravity *= gravityMultiplier;

Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/SensorBase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public virtual int Write(ObservationWriter writer)
3939
}
4040

4141
/// <inheritdoc/>
42-
public void Update() {}
42+
public void Update() { }
4343

4444
/// <inheritdoc/>
4545
public void Reset() { }

Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/TargetController.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using UnityEngine;
1+
using UnityEngine;
22
using Random = UnityEngine.Random;
33
using Unity.MLAgents;
44
using UnityEngine.Events;
@@ -12,14 +12,14 @@ namespace Unity.MLAgentsExamples
1212
/// </summary>
1313
public class TargetController : MonoBehaviour
1414
{
15-
15+
1616
[Header("Collider Tag To Detect")]
1717
public string tagToDetect = "agent"; //collider tag to detect
18-
18+
1919
[Header("Target Placement")]
2020
public float spawnRadius; //The radius in which a target can be randomly spawned.
2121
public bool respawnIfTouched; //Should the target respawn to a different position when touched
22-
22+
2323
[Header("Target Fell Protection")]
2424
public bool respawnIfFallsOffPlatform = true; //If the target falls off the platform, reset the position.
2525
public float fallDistance = 5; //distance below the starting height that will trigger a respawn

Project/Assets/ML-Agents/Examples/Startup/Scripts/Startup.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ void Awake()
1717
// no scene environment variable is found.
1818
var args = Environment.GetCommandLineArgs();
1919
Console.WriteLine("Command line arguments passed: " + String.Join(" ", args));
20-
for (int i = 0; i < args.Length; i++) {
21-
if (args [i] == k_SceneCommandLineFlag && i < args.Length - 1) {
20+
for (int i = 0; i < args.Length; i++)
21+
{
22+
if (args[i] == k_SceneCommandLineFlag && i < args.Length - 1)
23+
{
2224
sceneName = args[i + 1];
2325
}
2426
}

0 commit comments

Comments
 (0)