NVIDIA / NVIDIA/cuda-quantum

Add extra python formatting step for imports

Open
#408 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

maintenance stale-notified
Dominant language
C++
Stars
1.1k
Forks
456
Avg merge
1d 22h
Merged PRs (30d)
165

Description

We currently use yapf to ensure the proper formatting of all .py code. Our initial python implementation used this structure for imports:

  1. Python future import statements
  2. Python standard library imports.
  3. module or package imports.
  4. Code repository sub-package imports.

With each import getting its own line. E.g, avoiding a single line such as import numpy, scipy, ... . The only exception are relative imports, like from package import thing1, thing2, .... Each block of imports should then be separated by a new-line.

This has slowly gotten out of order over time, so we should automate the import formatting before running yapf. A tool such as isort could be used to do this.

This will likely require the following (subject to evolve):

  1. Creating some form of custom profile for our import format (maybe relevant)
  2. Adding the isort command to the bash script in cuda-quantum/.github/workflows/repo_checks.yml. Specifically here in the python formatting step.

If there are multiple commands needed to run isort, we should consider creating a convenience run_python_format.sh script akin to the scripts/run_clang_format.sh file.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Python formatting step in .github/workflows/repo_checks.yml around line 127 and review the isort custom-section documentation linked in the issue. Compare the proposed convenience script with scripts/run_clang_format.sh if multiple commands are needed. Done means the repository's Python imports follow the stated grouping and the formatting workflow applies the check.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, python
Domain
ci-cd, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.