STKCodeExamples icon indicating copy to clipboard operation
STKCodeExamples copied to clipboard

Discuss about code style checkers

Open jorgepiloto opened this issue 2 years ago • 3 comments

🐞 Problem

The different scripts and notebooks are not being tested from the point of view of code style. I am aware of the different languages being used in this repo, such as C#, Python, Matlab...

Nevertheless, it should be feasible to implement a .github/workflow/style.yml to check for custom-defined code style guidelines. This would ensure that all the code for a particular programming language looks the same, no matter the original author.

💡 Solution

If you are interested in implementing this feature, I could go for it.

We could start by implementing a Python code style checker based on black, isort and flake8. These tools can also be used in the Jupyter Notebooks.

Please, let me know what you think about this and if it would be of your interes.

jorgepiloto avatar May 21 '22 07:05 jorgepiloto

@jorgepiloto I think this is a great idea, and if you'd like to take the first shot at it that would be much appreciated!

Please let me know if you have any questions or issues along the way

jpthompson212 avatar May 23 '22 17:05 jpthompson212

@jorgepiloto I have finally got around to working on this. I have gone about adding both black and isort to a pre-commit file so that these can be run prior to any code commits.

These can also be added to a github action, just have not done that yet...

I also have not integrated flake8 yet but can do that.

jpthompson212 avatar Jan 20 '23 23:01 jpthompson212

Thanks for working on this, @jpthompson212.

Some months ago, we created pyansys/actions. This repository is a collection of reusable GitHub workflows. These allow to simplify the common CI/CD pipelines of a project. The pyansys/actions/style@v3 action installs, reads and runs the pre-commit-config.yaml file.

Since this is not a Python project, the use-python-cache argument needs to be equal to false.

code-style:
  name: "Running code style checks"
  runs-on: ubuntu-latest
  steps:
    - name: "Install pre-commit and run it"
      uses: pyansys/actions/code-style@v3
      with:
        use-python-cache: false

jorgepiloto avatar Jan 23 '23 05:01 jorgepiloto