Skip to content

Commit

Permalink
Moved info to BUILD.md and added a png check to check_large_files.py
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Nov 27, 2024
1 parent 8a0738a commit 20ab64a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 37 deletions.
15 changes: 15 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ If you are using an Apple-silicon Mac (M1, M2), make sure `rustc -vV` outputs `h
rustup set default-host aarch64-apple-darwin && rustup install 1.80.0
```

## git-lfs

We use [git-lfs](https://git-lfs.com/) to store big files in the repository, such as UI test snapshots.
We aim to keep this project buildable without the need of git-lfs (for example, icons and similar assets are checked in to the repo as regular files).
However, git-lfs is generally required for a proper development environment, e.g. to run tests.

### Setting up git-lfs

The TL;DR is to install git-lfs via your favorite package manager (`apt`, Homebrew, MacPorts, etc.) and run `git lfs install`.
See the many resources available online more details.

You can ensure that everything is correctly installed by running `git lfs ls-files` from the repository root.
It should list some test snapshot files.


## Validating your environment
You can validate your environment is set up correctly by running:
```sh
Expand Down
7 changes: 0 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ This is written for anyone who wants to contribute to the Rerun repository.

You can also look at our [`good first issue` tag](https://github.com/rerun-io/rerun/labels/good%20first%20issue).

## Git LFS

We use [git-lfs](https://git-lfs.com/) to store big files in the repository.
Make sure you have it installed (running `git lfs ls-files` from the repository root should list some files).
Don't forget to run `git lfs install` after installing the git-lfs binary.
If the CI complains about this, make sure you run `git add --renormalize .`.

## Pull requests
We use [Trunk Based Development](https://trunkbaseddevelopment.com/), which means we encourage small, short-lived branches.

Expand Down
95 changes: 74 additions & 21 deletions scripts/ci/check_large_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,86 @@
import os
import subprocess

#!/usr/bin/env python3
# These files are allowed to be larger than our limit
FILES_ALLOWED_TO_BE_LARGE = {
"CHANGELOG.md",
"Cargo.lock",
"crates/build/re_types_builder/src/reflection.rs",
"crates/store/re_dataframe/src/query.rs",
"crates/store/re_types/src/datatypes/tensor_buffer.rs",
"crates/viewer/re_ui/data/Inter-Medium.otf",
"crates/viewer/re_viewer/src/reflection/mod.rs",
"pixi.lock",
"rerun_cpp/docs/Doxyfile",
}

# Check for files that are too large to be checked into the repository.
# Whenever we want to make an exception, we add it to `check_large_files_allow_list.txt`
# Paths with the following prefixes are allowed to contain PNG files that are not checked into LFS
PATH_PREFIXES_ALLOWED_TO_CONTAIN_NON_LFS_PNGS = (
"crates/viewer/re_ui/data/icons/",
"crates/viewer/re_ui/data/logo_dark_mode.png",
"crates/viewer/re_ui/data/logo_light_mode.png",
"crates/viewer/re_viewer/data/app_icon_mac.png",
"crates/viewer/re_viewer/data/app_icon_windows.png",
"docs/snippets/all/archetypes/ferris.png",
"docs/snippets/src/snippets/ferris.png",
"examples/assets/example.png",
)

# Maximum file size, unless found in `check_large_files_allow_list.txt`
maximum_size = 100 * 1024

result = 0
script_path = os.path.dirname(os.path.realpath(__file__))
os.chdir(os.path.join(script_path, "../.."))
def check_large_files(files_to_check: set[str]) -> int:
"""Check for files that are too large to be checked into the repository."""

# Get the list of tracked files using git ls-files command
tracked_files = subprocess.check_output(["git", "ls-files"]).decode().splitlines()
maximum_size = 100 * 1024

for file_path in tracked_files:
actual_size = os.path.getsize(file_path)
result = 0
for file_path in files_to_check:
actual_size = os.path.getsize(file_path)

if actual_size >= maximum_size:
allow_list_path = os.path.join(script_path, "check_large_files_allow_list.txt")
if actual_size >= maximum_size:
if file_path not in FILES_ALLOWED_TO_BE_LARGE:
print(f"{file_path} is {actual_size} bytes (max allowed is {maximum_size} bytes)")
result = 1

with open(allow_list_path, encoding="utf8") as allow_list_file:
allow_list = allow_list_file.read().splitlines()
print(f"checked {len(files_to_check)} files")

if file_path not in allow_list:
print(f"{file_path} is {actual_size} bytes (max allowed is {maximum_size} bytes)")
result = 1
return result

print(f"checked {len(tracked_files)} files")
exit(result)

def check_for_non_lfs_pngs(files_to_check: set[str]) -> int:
"""Check for PNG files that are not checked into LFS."""

result = 0
for file_path in files_to_check:
if file_path.startswith(PATH_PREFIXES_ALLOWED_TO_CONTAIN_NON_LFS_PNGS):
continue

print(f"{file_path} is a PNG file that is not checked into LFS")
result = 1

print(f"checked {len(files_to_check)} pngs")

return result


def main() -> None:
script_path = os.path.dirname(os.path.realpath(__file__))
os.chdir(os.path.join(script_path, "../.."))

all_tracked_files = set(subprocess.check_output(["git", "ls-files"]).decode().splitlines())
lfs_files = set(subprocess.check_output(["git", "lfs", "ls-files", "-n"]).decode().splitlines())
not_lfs_files = all_tracked_files - lfs_files

result = check_large_files(not_lfs_files)
if result != 0:
exit(result)

all_tracked_pngs = {f for f in all_tracked_files if f.endswith(".png")}
not_lfs_pngs = all_tracked_pngs - lfs_files

result = check_for_non_lfs_pngs(not_lfs_pngs)
if result != 0:
exit(result)


if __name__ == "__main__":
main()
9 changes: 0 additions & 9 deletions scripts/ci/check_large_files_allow_list.txt

This file was deleted.

0 comments on commit 20ab64a

Please sign in to comment.