question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Educational]: Add linting to Python files with `black`

See original GitHub issue

For new contributors only

We’re looking to add linting to torchserve to improve code quality and readability

Once we have a couple of files linted we can start asking contributors to lint their files before committing and I’ll add a github action to do a lint check on CI - @sudomaze already did this #1602

Since there’s a lot of .py files which would be impossible to merge in a single code review I pulled out the 20 files with most commits and we can use them as a roadmap for what to do

If you’ve never contributed to torchserve before this is a great place to start, pick one of the files here and add linting to it, make a PR and make sure linting passes. Do not submit more than 1 PR or fixes to more than 1 lines this issue is mainly open for educational purposes

  1. pip install black
  2. Run black <file_to_lint.py>
  3. Make your PR and comment on this thread saying which of the below tasks should be closed. Only git add a single file at a time otherwise we won’t be able to code review
  4. If all the tasks are done increase head -n 20 to a bigger integer and pick a file there to contribute

The most important files to add linting to are the ones that change the most often i.e have the most commits

git rev-list --objects --all | awk '$2 ~ /\.py/' | awk '{print $2}' | sort -k2 | uniq -c | sort -rn | head -n 20

Number of commits, file

  • 59 ts_scripts/install_dependencies.py - https://github.com/pytorch/serve/pull/1596
  • 57 ts/torch_handler/base_handler.py https://github.com/pytorch/serve/pull/1597
  • 52 ts/model_service_worker.py #1599
  • 47 examples/Huggingface_Transformers/Transformer_handler_generalized.py https://github.com/pytorch/serve/pull/1612
  • 42 ts_scripts/sanity_utils.py
  • 41 test/pytest/test_handler.py
  • 35 ts_scripts/tsutils.py
  • 34 ts/model_server.py
  • 34 benchmarks/benchmark-ab.py
  • 29 ts_scripts/marsgen.py
  • 29 ts/model_loader.py #1605
  • 28 model-archiver/model_archiver/model_packaging.py
  • 28 benchmarks/benchmark.py
  • 24 torchserve_sanity.py
  • 23 ts/torch_handler/object_detector.py #1603
  • 23 model-archiver/model_archiver/model_packaging_utils.py
  • 22 setup.py
  • 21 ts_scripts/torchserve_grpc_client.py
  • 21 model-archiver/model_archiver/manifest_components/model.py
  • 21 model-archiver/model_archiver/arg_parser.py

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dat-nguyen96commented, May 3, 2022

I submitted PR #1605 , taking care of the linting for ts/model_loader.py

2reactions
jezebleumcommented, May 3, 2022

Just submitted PR #1604, taking care of the linting for ts/model_server.py

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Auto-Format Your Python Code with Black
Pylint is a tool that checks for errors in Python. It tries to enforce a coding standard and looks for code smells. It...
Read more >
Code Formatting In Python With Black - Python Tutorial
Learn how to use the black tool for code formatting in Python. Stop wasting time to determine the best format, and just let...
Read more >
Stylising your Python code: An introduction to linting and ...
Linting is a process for identifying bugs and stylistic errors in your code. The process is carried out by analysis tools called 'linters', ......
Read more >
Improve Your Code with Pylint and Black
Black is a really useful code formatting tool maintained by the Python Software Foundation. It reformats files to improve readability.
Read more >
Python code formatting using Black - GeeksforGeeks
It is very simple to use black. Run the below command in the terminal. ... This will reformat your code using the Black...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found