← back to Exo
simplify formatting with yapf
2e270766655636588ae6697cae5460ddf8f328f2 · 2024-08-22 14:04:28 +0100 · Alex Cheema
Files touched
A .style.yapfM format.pyM pyproject.tomlM setup.py
Diff
commit 2e270766655636588ae6697cae5460ddf8f328f2
Author: Alex Cheema <alexcheema123@gmail.com>
Date: Thu Aug 22 14:04:28 2024 +0100
simplify formatting with yapf
---
.style.yapf | 13 ++++++++
format.py | 97 ++++++----------------------------------------------------
pyproject.toml | 10 ------
setup.py | 83 +++++++++++++++++++++++++------------------------
4 files changed, 64 insertions(+), 139 deletions(-)
diff --git a/.style.yapf b/.style.yapf
new file mode 100644
index 00000000..727e57d2
--- /dev/null
+++ b/.style.yapf
@@ -0,0 +1,13 @@
+[style]
+based_on_style = pep8
+indent_width = 2
+column_limit = 200
+allow_split_before_dict_value = False
+dedent_closing_brackets = True
+split_before_first_argument = False
+split_complex_comprehension = False
+continuation_indent_width = 2
+indent_dictionary_value = True
+allow_multiline_dictionary_keys = True
+each_dict_entry_on_separate_line = False
+allow_multiline_lambdas = True
\ No newline at end of file
diff --git a/format.py b/format.py
index 7586bbf2..2afda665 100644
--- a/format.py
+++ b/format.py
@@ -1,99 +1,22 @@
#!/usr/bin/env python
-import re
import subprocess
import sys
import os
-import fnmatch
-DEBUG_PATTERN = re.compile(r'^(\s*)(if\s+DEBUG\s*>=?\s*\d+\s*:.+)$', re.MULTILINE)
-PLACEHOLDER = "###DEBUG_PLACEHOLDER###"
-# Add ignore patterns here
-IGNORE_PATTERNS = [
- '.venv/*',
- 'setup.py',
- '*helpers.py',
- '*node_service_pb2.py',
- '*node_service_pb2_grpc.py',
-]
-
-
-def should_ignore(file_path):
- for pattern in IGNORE_PATTERNS:
- if fnmatch.fnmatch(file_path, pattern):
- return True
- return False
-
-
-def preserve_debug_lines(content):
- def replace(match):
- indent, line = match.groups()
- return f"{indent}{PLACEHOLDER}{line.strip()}"
-
- return DEBUG_PATTERN.sub(replace, content)
-
-
-def restore_debug_lines(content):
- return re.sub(f"^(\\s*){PLACEHOLDER}(.+)$", r"\1\2", content, flags=re.MULTILINE)
-
-
-def adjust_indentation(content):
- lines = content.split('\n')
- adjusted_lines = []
- for line in lines:
- if line.strip() and not line.startswith(PLACEHOLDER):
- indent = len(line) - len(line.lstrip())
- new_indent = ' ' * (indent // 2)
- adjusted_lines.append(new_indent + line.lstrip())
- else:
- adjusted_lines.append(line)
- return '\n'.join(adjusted_lines)
-
-
-def process_file(file_path, process_func):
- with open(file_path, 'r') as file:
- content = file.read()
-
- modified_content = process_func(content)
-
- if content != modified_content:
- with open(file_path, 'w') as file:
- file.write(modified_content)
-
-
-def run_black(target):
- # Convert ignore patterns to Black's --extend-exclude format
- exclude_patterns = '|'.join(f'({pattern.replace("*", ".*")})' for pattern in IGNORE_PATTERNS)
- command = ["black", "--line-length", "200", "--extend-exclude", exclude_patterns, target]
- subprocess.run(command, check=True)
-
-
-def format_files(target):
+def run_yapf(target):
if os.path.isfile(target):
- files = [target] if not should_ignore(target) else []
- elif os.path.isdir(target):
- files = []
- for root, _, filenames in os.walk(target):
- for filename in filenames:
- if filename.endswith('.py'):
- file_path = os.path.join(root, filename)
- if not should_ignore(file_path):
- files.append(file_path)
+ files = [target]
else:
- print(f"Error: {target} is not a valid file or directory")
- return
-
- # Preserve debug lines
- for file in files:
- process_file(file, preserve_debug_lines)
-
- # Run Black
- run_black(target)
+ files = [os.path.join(root, file) for root, _, files in os.walk(target) for file in files if file.endswith('.py')]
- # Adjust indentation and restore debug lines
for file in files:
- process_file(file, adjust_indentation)
- process_file(file, restore_debug_lines)
+ try:
+ command = ["yapf", "-i", file]
+ subprocess.run(command, check=True, capture_output=True, text=True)
+ print(f"Formatted: {file}")
+ except subprocess.CalledProcessError as e:
+ print(f"Error formatting {file}: {e.stderr}")
def main():
@@ -102,7 +25,7 @@ def main():
sys.exit(1)
target = sys.argv[1]
- format_files(target)
+ run_yapf(target)
print("Formatting completed.")
diff --git a/pyproject.toml b/pyproject.toml
index 09cae440..4fa6bfbc 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,13 +1,3 @@
-[tool.black]
-line-length = 200
-indent-size = 2
-skip-string-normalization = true
-
-[tool.isort]
-profile = "black"
-line_length = 200
-indent = " "
-
[tool.pylint.format]
indent-string = ' '
max-line-length = 200
diff --git a/setup.py b/setup.py
index d5426510..f22e158a 100644
--- a/setup.py
+++ b/setup.py
@@ -4,55 +4,54 @@ from setuptools import find_packages, setup
# Base requirements for all platforms
install_requires = [
- "aiohttp==3.10.2",
- "aiohttp_cors==0.7.0",
- "aiofiles==24.1.0",
- "blobfile==2.1.1",
- "grpcio==1.64.1",
- "grpcio-tools==1.64.1",
- "hf-transfer==0.1.8",
- "huggingface-hub==0.24.5",
- "Jinja2==3.1.4",
- "netifaces==0.11.0",
- "numpy==2.0.0",
- "pillow==10.4.0",
- "prometheus-client==0.20.0",
- "protobuf==5.27.1",
- "psutil==6.0.0",
- "pynvml==11.5.3",
- "requests==2.32.3",
- "rich==13.7.1",
- "safetensors==0.4.3",
- "tenacity==9.0.0",
- "tiktoken==0.7.0",
- "tokenizers==0.19.1",
- "tqdm==4.66.4",
- "transformers==4.43.3",
- "uuid==1.30",
- "tinygrad @ git+https://github.com/tinygrad/tinygrad.git@639af3f823cf242a1945dc24183e52a9df0af2b7",
+ "aiohttp==3.10.2",
+ "aiohttp_cors==0.7.0",
+ "aiofiles==24.1.0",
+ "blobfile==2.1.1",
+ "grpcio==1.64.1",
+ "grpcio-tools==1.64.1",
+ "hf-transfer==0.1.8",
+ "huggingface-hub==0.24.5",
+ "Jinja2==3.1.4",
+ "netifaces==0.11.0",
+ "numpy==2.0.0",
+ "pillow==10.4.0",
+ "prometheus-client==0.20.0",
+ "protobuf==5.27.1",
+ "psutil==6.0.0",
+ "pynvml==11.5.3",
+ "requests==2.32.3",
+ "rich==13.7.1",
+ "safetensors==0.4.3",
+ "tenacity==9.0.0",
+ "tiktoken==0.7.0",
+ "tokenizers==0.19.1",
+ "tqdm==4.66.4",
+ "transformers==4.43.3",
+ "uuid==1.30",
+ "tinygrad @ git+https://github.com/tinygrad/tinygrad.git@639af3f823cf242a1945dc24183e52a9df0af2b7",
]
# Add macOS-specific packages if on Darwin (macOS)
if sys.platform.startswith("darwin"):
- install_requires.extend(
- [
- "mlx==0.16.3",
- "mlx-lm==0.17.0",
- ]
- )
+ install_requires.extend([
+ "mlx==0.16.3",
+ "mlx-lm==0.17.0",
+ ])
extras_require = {
- "linting": [
- "pylint==3.2.6",
- "ruff==0.5.5",
- "mypy==1.11.0",
- ],
+ "linting": [
+ "pylint==3.2.6",
+ "ruff==0.5.5",
+ "mypy==1.11.0",
+ "yapf==0.40.2",
+ ],
}
setup(
- name="exo",
- version="0.0.1",
- packages=find_packages(),
- install_requires=install_requires,
- extras_require=extras_require,
+ name="exo",
+ version="0.0.1",
+ packages=find_packages(),
+ install_requires=install_requires,
+ extras_require=extras_require,
)
← 417114fa fix mistral nemo
·
back to Exo
·
reformat with yapf format.py ea70c9fb →