Skip to content

Commit

Permalink
Fix the usage of scripts (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx authored Sep 12, 2024
1 parent 66b66f4 commit c079ffd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ repos:
- id: black
args: [--safe, --line-length=100, --preview]
language_version: python3
- id: black
types_or: [file]
files: ^bin/
args: [--safe, --line-length=100, --preview]
language_version: python3

- repo: https://github.com/pycqa/docformatter
rev: v1.7.5
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
repository = "https://github.com/AxFoundation/strax"

[tool.poetry.scripts]
rechunker = "bin.rechunker:main"
rechunker = "strax.scripts.rechunker:main"

[tool.poetry.dependencies]
python = ">=3.6,<3.13"
Expand Down
5 changes: 0 additions & 5 deletions strax/__main__.py

This file was deleted.

Empty file added strax/scripts/__init__.py
Empty file.
31 changes: 17 additions & 14 deletions bin/rechunker → strax/scripts/rechunker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
import os.path
import argparse

Expand Down Expand Up @@ -66,7 +65,22 @@ def parse_args():
return args


def main(args):
def main():
args = parse_args()
if args.profile_memory:
from memory_profiler import memory_usage
import time

start = time.time()
mem = memory_usage(proc=(rechunk, (args,)))
print(f"Memory profiler says peak RAM usage was: {max(mem):.1f} MB")
print(f"Took {time.time() - start:.1f} s = {(time.time() - start) / 3600:.2f} h ")
print("Bye, bye")
else:
rechunk(args)


def rechunk(args):
source_mb = strax.utils.dir_size_mb(args.source)
report = strax.rechunker(
source_directory=args.source,
Expand Down Expand Up @@ -97,15 +111,4 @@ def main(args):


if __name__ == "__main__":
args = parse_args()
if args.profile_memory:
from memory_profiler import memory_usage
import time

start = time.time()
mem = memory_usage(proc=(main, (args,)))
print(f"Memory profiler says peak RAM usage was: {max(mem):.1f} MB")
print(f"Took {time.time() - start:.1f} s = {(time.time() - start) / 3600:.2f} h ")
print("Bye, bye")
else:
main(args)
main()

0 comments on commit c079ffd

Please sign in to comment.