Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to allow for autoformatting the project. #1214

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .csharpierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
unity/Dependencies/
unity/Assets/MagicMirror
unity/Assets/MessagePack
unity/Assets/MIConvexHull
unity/Assets/Priority Queue
unity/Assets/Plugins
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ csharp_prefer_braces = true:error

[*.cs]
indent_size = 4
insert_final_newline = true

# Newline settings
csharp_new_line_before_open_brace = none
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@23.12.1 # If version changed, update requirements-dev.txt
11 changes: 0 additions & 11 deletions .lgtm.yml

This file was deleted.

22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contributing

We welcome contributions from the greater community. If you would like to make such a contributions we recommend first submitting an [issue](https://github.com/allenai/ai2thor/issues) describing your proposed improvement. Doing so can ensure we can validate your suggestions before you spend a great deal of time upon them. Improvements and bug fixes should be made via a pull request from your fork of the repository at [https://github.com/allenai/ai2thor](https://github.com/allenai/ai2thor).

All code in pull requests should adhere to the following guidelines.

## Found a bug or want to suggest an enhancement?

Please submit an [issue](https://github.com/allenai/ai2thor/issues) in which you note the steps
to reproduce the bug or in which you detail the enhancement.

## Making a pull request?

When making a pull request we require that any code respects the following guidelines.

### Auto-formatting

All Python and C# must be auto-formatted. To do this, simply run
```bash
invoke format
```
from the root of the repository.
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.black]
line-length = 100

include = '\.pyi?$'

exclude = '''
(
__pycache__
| \.git
| \.mypy_cache
| \.pytest_cache
| \.vscode
| \.venv
| \bdist\b
| \bdoc\b
)
'''

[tool.isort]
profile = "black"
multi_line_output = 3
8 changes: 8 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pytest
pytest-timeout
pytest-cov
jsonschema
shapely
pytest-mock
dictdiffer
black==23.12.1 # If version changed, update .github/workflows/black.yaml
7 changes: 0 additions & 7 deletions requirements-test.txt

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _read_reqs(relpath):
]

REQUIREMENTS = _read_reqs("requirements.txt")
REQUIREMENTS_TEST = _read_reqs("requirements-test.txt")
REQUIREMENTS_TEST = _read_reqs("requirements-dev.txt")

setup(
name="ai2thor",
Expand Down
116 changes: 69 additions & 47 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import glob
import os
import signal
import sys
Expand Down Expand Up @@ -908,6 +909,7 @@ def pre_test(context):
"unity/builds/%s" % c.build_name(),
)


import scripts.update_private


Expand Down Expand Up @@ -1550,6 +1552,7 @@ def ci_build_arch(
finally:
os.chdir(start_wd)


@task
def poll_ci_build(context):
import requests
Expand Down Expand Up @@ -3686,18 +3689,44 @@ def format(context):

@task
def format_cs(context):
install_dotnet_format(context)
# assert tool in ["format", "csharpier"]
install_dotnet_tool(context, tool="dotnet-format")
install_dotnet_tool(context, tool="csharpier")

# the following message will get emitted, this can safely be ignored
# "Warnings were encountered while loading the workspace. Set the verbosity option to the 'diagnostic' level to log warnings"
# First run csharpier as it handles long lines correctly
print("Running csharpier on whole project")
subprocess.check_call(
".dotnet/dotnet tool run dotnet-format unity/AI2-THOR-Base.csproj -w -s",
".dotnet/dotnet tool run dotnet-csharpier unity",
shell=True,
)

# Now run dotnet-format as it allows more configuration options (e.g. curly brace with no new line).
# The following message will get emitted, this can safely be ignored
# "Warnings were encountered while loading the workspace. Set the verbosity option to the 'diagnostic' level to log warnings"
for proj in glob.glob("unity/*.csproj"):
if any(
k in proj
for k in [
"UnityStandardAssets",
"MagicMirror",
"I360Render",
"MessagePack",
"MIConvexHull",
"Priority",
"Plugins",
]
):
continue

print(f"\nRunning dotnet-format on {proj}")
subprocess.check_call(
f".dotnet/dotnet tool run dotnet-format {proj} -w -s",
shell=True,
)


@task
def install_dotnet_format(context, force=False):
def install_dotnet_tool(context, tool: str, force=False):
install_dotnet(context)

base_dir = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
Expand All @@ -3709,14 +3738,19 @@ def install_dotnet_format(context, force=False):
tools = json.loads(f.read())

# we may want to specify a version here in the future
if not force and "dotnet-format" in tools.get("tools", {}):
if not force and tool in tools.get("tools", {}):
# dotnet-format already installed
return

command = os.path.join(base_dir, ".dotnet/dotnet") + " tool install dotnet-format"
command = os.path.join(base_dir, ".dotnet/dotnet") + f" tool install {tool}"
subprocess.check_call(command, shell=True)


@task
def install_dotnet_format(context, force=False):
install_dotnet_tool(context, tool="dotnet-format", force=force)


@task
def install_dotnet(context, force=False):
import requests
Expand Down Expand Up @@ -3747,9 +3781,7 @@ def format_py(context):
except ImportError:
raise Exception("black not installed - run pip install black")

subprocess.check_call(
"black -v -t py38 --exclude unity/ --exclude .git/ .", shell=True
)
subprocess.check_call("black -v -t py38 --exclude unity/ --exclude .git/ .", shell=True)


@task
Expand Down Expand Up @@ -3868,9 +3900,11 @@ def test_utf(base_dir=None):
test_results_path = os.path.join(project_path, "utf_testResults-%s.xml" % commit_id)
logfile_path = os.path.join(base_dir, "thor-testResults-%s.log" % commit_id)

command = (
"%s -runTests -testResults %s -logFile %s -testPlatform PlayMode -projectpath %s "
% (_unity_path(), test_results_path, logfile_path, project_path)
command = "%s -runTests -testResults %s -logFile %s -testPlatform PlayMode -projectpath %s " % (
_unity_path(),
test_results_path,
logfile_path,
project_path,
)

subprocess.call(command, shell=True, cwd=base_dir)
Expand Down Expand Up @@ -4698,12 +4732,13 @@ def run_benchmark_from_s3_config(ctx):

@task
def run_benchmark_from_local_config(
ctx, config_path,
house_from_s3=False,
ctx,
config_path,
house_from_s3=False,
houses_path="./unity/Assets/Resources/rooms",
output="out.json",
local_build=False,
arch=None
arch=None,
):
import copy
from ai2thor.benchmarking import BENCHMARKING_S3_BUCKET, UnityActionBenchmarkRunner
Expand Down Expand Up @@ -4882,7 +4917,10 @@ def procedural_asset_hook_test(ctx, asset_dir, house_path, asset_id=""):
from objathor.asset_conversion.util import view_asset_in_thor

hook_runner = ProceduralAssetHookRunner(
asset_directory=asset_dir, asset_symlink=True, verbose=True, load_file_in_unity=True
asset_directory=asset_dir,
asset_symlink=True,
verbose=True,
load_file_in_unity=True,
)
controller = ai2thor.controller.Controller(
# local_executable_path="unity/builds/thor-OSXIntel64-local/thor-OSXIntel64-local.app/Contents/MacOS/AI2-THOR",
Expand All @@ -4897,15 +4935,15 @@ def procedural_asset_hook_test(ctx, asset_dir, house_path, asset_id=""):
visibilityScheme="Distance",
action_hook_runner=hook_runner,
)
#TODO bug why skybox is not changing? from just procedural pipeline

# TODO bug why skybox is not changing? from just procedural pipeline
evt = controller.step(
action="SetSkybox",
action="SetSkybox",
color={
"r": 0,
"g": 0,
"b": 0,
}
},
)

angle_increment = 45
Expand All @@ -4918,7 +4956,7 @@ def procedural_asset_hook_test(ctx, asset_dir, house_path, asset_id=""):
output_dir="./output-test",
rotations=rotations,
house_path=house_path,
skybox_color=(0, 0, 0)
skybox_color=(0, 0, 0),
)

# with open(house_path, "r") as f:
Expand All @@ -4938,22 +4976,20 @@ def procedural_asset_hook_test(ctx, asset_dir, house_path, asset_id=""):
# ]
# evt = controller.step(action="CreateHouse", house=house)


# print(
# f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}"
# )
# print(f'Error: {evt.metadata["errorMessage"]}')

# evt = controller.step(
# action="SetSkybox",
# action="SetSkybox",
# color={
# "r": 0,
# "g": 0,
# "b": 0,
# }
# )


# evt = controller.step(dict(action="LookAtObjectCenter", objectId=instance_id))

# print(
Expand All @@ -4962,10 +4998,9 @@ def procedural_asset_hook_test(ctx, asset_dir, house_path, asset_id=""):
# print(f'Error: {evt.metadata["errorMessage"]}')
# input()


@task
def procedural_asset_cache_test(
ctx, asset_dir, house_path, asset_ids="", cache_limit=1
):
def procedural_asset_cache_test(ctx, asset_dir, house_path, asset_ids="", cache_limit=1):
import json
import ai2thor.controller
from ai2thor.hooks.procedural_asset_hook import ProceduralAssetHookRunner
Expand Down Expand Up @@ -5012,28 +5047,20 @@ def procedural_asset_cache_test(

evt = controller.step(action="CreateHouse", house=house)

print(
f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}"
)
print(f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}")
print(f'Error: {evt.metadata["errorMessage"]}')

evt = controller.step(
dict(action="LookAtObjectCenter", objectId=f"{instance_id}_0")
)
evt = controller.step(dict(action="LookAtObjectCenter", objectId=f"{instance_id}_0"))

# while True:
# pass

print(
f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}"
)
print(f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}")
print(f'Error: {evt.metadata["errorMessage"]}')

evt = controller.step(action="GetLRUCacheKeys")

print(
f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}"
)
print(f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}")
print(f'Error: {evt.metadata["errorMessage"]}')
print(f'return {evt.metadata["actionReturn"]}')

Expand Down Expand Up @@ -5061,17 +5088,12 @@ def procedural_asset_cache_test(

evt = controller.step(action="CreateHouse", house=house)

print(
f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}"
)
print(f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}")
print(f'Error: {evt.metadata["errorMessage"]}')

controller.reset()
evt = controller.step(action="GetLRUCacheKeys")

print(
f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}"
)
print(f"Action {controller.last_action['action']} success: {evt.metadata['lastActionSuccess']}")
print(f'Error: {evt.metadata["errorMessage"]}')
print(f'return {evt.metadata["actionReturn"]}')