Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
touilleMan committed Nov 19, 2023
1 parent a01f21e commit 98c916e
Show file tree
Hide file tree
Showing 528 changed files with 17,658 additions and 44,761 deletions.
9 changes: 9 additions & 0 deletions .cspell/custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ ALLSPHINXOPTS
alsa
androideabi
androidx
anyio
appendleft
aqtbot
aread
armv
arwx
Asas
asend
asgi
assetimporters
asynchronousness
asyncness
asyncpg
athrow
Expand Down Expand Up @@ -137,6 +141,7 @@ excrepr
executemany
executescript
farn
fastapi
fdata
fetchrow
fetchval
Expand Down Expand Up @@ -187,6 +192,7 @@ HKCU
HKLM
Hodi
htmlcov
httpx
humantime
hypercorn
icccm
Expand Down Expand Up @@ -318,6 +324,7 @@ modindex
moduleauthor
moff
monomorphization
monothreaded
mountdir
mountpoint
MountPoints
Expand Down Expand Up @@ -426,6 +433,7 @@ PyClass
pydeps
pydocs
pyenv
pydantic
PyFunction
pyinstaller
pylupdate
Expand Down Expand Up @@ -609,6 +617,7 @@ userguide
userspace
userto
usertotal
uvicorn
vacuum
Vacuum
verifykey
Expand Down
1 change: 1 addition & 0 deletions .cspell/names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fooo
Goku
Kryza
Leblond
Minimalorg
mailhog
Malloryy
Manraj
Expand Down
41 changes: 21 additions & 20 deletions .github/scripts/sink_cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS
from __future__ import annotations

# CLI to Delete Github Action Cache.
#
Expand All @@ -11,7 +12,7 @@
from dataclasses import dataclass
from datetime import datetime
from logging import basicConfig, getLogger
from typing import Any, Dict, Optional
from typing import Any

basicConfig(level=logging.INFO)
logger = getLogger()
Expand All @@ -33,7 +34,7 @@ def naturalize(bytes_size: int) -> str:
return f"{normalized_size:.1f} GiB"


def gh_api(url: str, method: Optional[str] = "GET"):
def gh_api(url: str, method: str | None = "GET") -> dict:
extra_args = ["--header='Accept: application/json'"]
if method is not None:
extra_args.append(f"--method={method}")
Expand All @@ -53,7 +54,8 @@ class CacheEntry:
created_at: datetime
size_in_bytes: int

def from_dict(dict: Dict[str, Any]) -> "CacheEntries":
@classmethod
def from_dict(cls, data: dict[str, Any]) -> CacheEntry:
# Datetime format for `2019-01-24T22:45:36.000Z``

def get_iso_datetime(raw: str) -> datetime:
Expand All @@ -76,24 +78,24 @@ def get_iso_datetime(raw: str) -> datetime:
dt = datetime.fromisoformat(raw_without_nano)
return dt

last_accessed_at = get_iso_datetime(dict["last_accessed_at"])
create_at = get_iso_datetime(dict["created_at"])
last_accessed_at = get_iso_datetime(data["last_accessed_at"])
create_at = get_iso_datetime(data["created_at"])

return CacheEntry(
id=int(dict["id"]),
key=dict["key"],
ref=dict["ref"],
version=dict["version"],
return cls(
id=int(data["id"]),
key=data["key"],
ref=data["ref"],
version=data["version"],
last_accessed_at=last_accessed_at,
created_at=create_at,
size_in_bytes=int(dict["size_in_bytes"]),
size_in_bytes=int(data["size_in_bytes"]),
)


@dataclass
class CacheEntries:
total_count: int
actions_caches: Dict[int, CacheEntry]
actions_caches: dict[int, CacheEntry]

def __repr__(self) -> str:
return f"{type(self).__name__}({self.total_count}, {self.actions_caches:r})"
Expand All @@ -105,11 +107,12 @@ def empty() -> "CacheEntries":
def need_to_download_more(self) -> bool:
return self.total_count - 1 != len(self.actions_caches)

def from_dict(raw_dict: Dict[str, Any]) -> "CacheEntries":
return CacheEntries(0, {}).update_from_dict(raw_dict, unique_cache=True)
@classmethod
def from_dict(cls, raw_dict: dict[str, Any]) -> CacheEntries:
return cls(0, {}).update_from_dict(raw_dict, unique_cache=True)

def update_from_dict(
self, raw_dict: Dict[str, Any], unique_cache: bool = False
self, raw_dict: dict[str, Any], unique_cache: bool = False
) -> "CacheEntries":
self.total_count = int(raw_dict["total_count"])

Expand All @@ -129,7 +132,7 @@ def __add__(self, x: "CacheEntries") -> "CacheEntries":
return new_entries


def get_cache_entries(owner: str, repo: str, ref: Optional[str]) -> CacheEntries:
def get_cache_entries(owner: str, repo: str, ref: str | None) -> CacheEntries:
"""
Documentation: https://docs.github.com/en/rest/actions/cache#list-github-actions-caches-for-a-repository
"""
Expand All @@ -153,9 +156,7 @@ def get_cache_entries(owner: str, repo: str, ref: Optional[str]) -> CacheEntries
return cache_entries


def remove_cache_entries(
entries: CacheEntries, owner: str, repo: str, dry: bool, ref: Optional[str]
):
def remove_cache_entries(entries: CacheEntries, owner: str, repo: str, dry: bool, ref: str | None):
log = logger.getChild(remove_cache_entries.__name__)
base_url = f"/repos/{owner}/{repo}/actions/caches?"
if ref is not None:
Expand All @@ -175,7 +176,7 @@ def remove_cache_entries(
log.debug(f"res={return_val}")


def remove_caches_from_repository(owner: str, repo: str, dry: bool, ref: Optional[str]):
def remove_caches_from_repository(owner: str, repo: str, dry: bool, ref: str | None):
logger.info(f"Will remove caches from {owner}/{repo}" + (f"/{ref}" if ref is not None else ""))
entries = get_cache_entries(owner, repo, ref)
if entries.actions_caches:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ env:
pytest-base-args: >-
--log-level=DEBUG
--durations=10
--side-effects-timeout=10
--timeout=10
-vv
-x
# TODO: We stick to PostgreSQL 12 for the moment given later versions are
Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
- name: Check python code style
run: |
set -eux
for step in mypy black ruff; do
for step in black ruff pyright; do
python \
${{ steps.pre-commit.outputs.install-path }} \
run \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ jobs:
with:
config-file: ${{ steps.patched-pre-commit-config.outputs.path }}
env:
SKIP: clippy,fmt,cspell,ruff,black,mypy,eslint
SKIP: clippy,fmt,cspell,ruff,black,pyright,eslint
timeout-minutes: 5

python:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/docker-testbed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ on:
paths:
# Testbed code also depends on `libparsec/**`, but this code change very often
# and we consider the server tests are good enough on this part.
- server/tests/scripts/run_testbed_server.py
- server/packaging/testbed-server/**
- .github/workflows/docker-testbed.yml
push:
Expand All @@ -20,7 +19,6 @@ on:
paths:
# Testbed code also depends on `libparsec/**`, but this code change very often
# and we consider the server tests are good enough on this part.
- server/tests/scripts/run_testbed_server.py
- server/packaging/testbed-server/**
- .github/workflows/docker-testbed.yml

Expand Down
114 changes: 67 additions & 47 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ repos:
# - lastly, mypy is started
# So this is similar to what the developer does when running mypy from it dev shell \o/
#
# Now that we use poetry to run mypy, why not also use it for ruff & black !
# Now that we use poetry to run mypy, why not also use it for ruff linter & formatter !
# This have the following benefits:
# - It prevents going out of sync in tools version between pre-commit-config
# and poetry.lock
Expand All @@ -107,72 +107,92 @@ repos:
hooks:
- id: ruff
name: ruff (using `poetry run ruff`)
entry: poetry --directory ./server run ruff check
# Wow this looks ugly ! But there is a reason why:
# - Ruff's `extend-exclude` doesn't work if it is not run from it config's folder
# - Pre-commit only run script from the repo root directory
# - A file passed as parameter is check by Ruff even if it part of `extend-exclude`
# - Splitting lines with YAML add heading whitespaces for no reason, and Python
# then complains about indentation :'(
#
# So (after a lot of pain) we came up with this: a one liner (because YAML)
# of a Python script that jumps in the correct directory (because pre-commit)
# to run Ruff on the whole codebase (because Ruff).
#
# Fortunately Ruff is (as cool kids say) blazingly fast, so it's no big
# deal to check everything on each run.
entry:
poetry --directory ./server run python -c 'import os;os.chdir("./server");os.execlp("ruff", "ruff", "check", "--fix", "./parsec", "./tests", "../docs", "../make.py", "../misc");'
require_serial: true
pass_filenames: false
language: system
types_or: [ python, pyi ]
args:
[
--config=server/pyproject.toml,
--extend-exclude=client/*,
--fix,
]

- id: black
name: black (using `poetry run black`)
entry: poetry --directory ./server run black
- id: black # Still named `black` as it makes a unique recognizable name
name: black (using `poetry run ruff format`)
entry: poetry --directory ./server run ruff format
require_serial: true
language: system
types_or: [ python, pyi ]
args:
[
--line-length=100,
--config=server/pyproject.toml,
]

- id: mypy
name: Mypy (using `poetry run mypy`)
entry: poetry --directory ./server run mypy
- id: pyright
name: Pyright (using `poetry run pyright`)
entry: poetry --directory ./server run pyright
require_serial: true
language: system
types_or: [ python, pyi ]
args:
[
--config=server/pyproject.toml,
--project=server/,
]
files: ^(server|misc|bindings/generator)/

######
# Rust
# - id: mypy

Check warning on line 152 in .pre-commit-config.yaml

View workflow job for this annotation

GitHub Actions / 📊 Q&A

152:7 [comments-indentation] comment not indented like content
# name: Mypy (using `poetry run mypy`)
# entry: poetry --directory ./server run mypy
# require_serial: true
# language: system
# types_or: [ python, pyi ]
# args:
# [
# --config=server/pyproject.toml,
# ]
# files: ^(server|misc|bindings/generator)/

- repo: local
hooks:
- id: fmt
name: fmt
entry: cargo fmt
language: system
types: [ rust ]
args: [ -- ]
# ######
# # Rust

- id: clippy
name: clippy
entry: cargo clippy
language: system
types: [ rust ]
pass_filenames: false
args:
[
--workspace,
--tests,
--bins,
--lib,
--exclude=libparsec_bindings_android,
--exclude=libparsec_bindings_web,
--exclude=libparsec_bindings_electron,
--,
--deny=warnings,
--deny=clippy::undocumented_unsafe_blocks,
--deny=clippy::unwrap_used
]
# - repo: local
# hooks:
# - id: fmt
# name: fmt
# entry: cargo fmt
# language: system
# types: [ rust ]
# args: [ -- ]

# - id: clippy
# name: clippy
# entry: cargo clippy
# language: system
# types: [ rust ]
# pass_filenames: false
# args:
# [
# --workspace,
# --tests,
# --bins,
# --lib,
# --exclude=libparsec_bindings_android,
# --exclude=libparsec_bindings_web,
# --exclude=libparsec_bindings_electron,
# --,
# --deny=warnings,
# --deny=clippy::undocumented_unsafe_blocks,
# --deny=clippy::unwrap_used
# ]

####
# Js
Expand Down
4 changes: 2 additions & 2 deletions bindings/generator/api/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS

from typing import Any, Generic, TypeVar
from typing import Any, ClassVar, Generic, TypeVar

#
# Meta-types
Expand Down Expand Up @@ -167,7 +167,7 @@ class DeviceLabel(StrBasedType):
class HumanHandle(Structure):
email: str
label: str
custom_getters: dict[str, str] = {
custom_getters: ClassVar = {
"email": "|obj| { fn access(obj: &libparsec::HumanHandle) -> &str { obj.email() } access(obj) }",
"label": "|obj| { fn access(obj: &libparsec::HumanHandle) -> &str { obj.label() } access(obj) }",
}
Expand Down
Loading

0 comments on commit 98c916e

Please sign in to comment.