Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement code style via pre-commit #264

Merged
merged 10 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions .ci/start_fluent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,30 @@ def start_fluent_container(args):
port = os.environ["PYFLUENT_FLUENT_PORT"]

try:
subprocess.run(["docker", "run", "--name", "fluent_server", "-d",
"--rm", "-p", f"{port}:{port}",
"-v", f"{EXAMPLES_PATH}:{EXAMPLES_PATH}",
"-e", f"ANSYSLMD_LICENSE_FILE={license_server}",
"-e", f"REMOTING_PORTS={port}/portspan=2",
"-e", "FLUENT_LAUNCHED_FROM_PYFLUENT=1",
"ghcr.io/pyansys/pyfluent",
"-g", f"-sifile={sifile}"] + args)
subprocess.run(
[
"docker",
"run",
"--name",
"fluent_server",
"-d",
"--rm",
"-p",
f"{port}:{port}",
"-v",
f"{EXAMPLES_PATH}:{EXAMPLES_PATH}",
"-e",
f"ANSYSLMD_LICENSE_FILE={license_server}",
"-e",
f"REMOTING_PORTS={port}/portspan=2",
"-e",
"FLUENT_LAUNCHED_FROM_PYFLUENT=1",
"ghcr.io/pyansys/pyfluent",
"-g",
f"-sifile={sifile}",
]
+ args
)

sifile_last_mtime = os.stat(sifile).st_mtime
while True:
Expand Down
9 changes: 0 additions & 9 deletions .flake8

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ jobs:
with:
python-version: 3.9

- name: Install Style Requirements
- name: Install pre-commit
run: |
pip install -r requirements_style.txt --disable-pip-version-check
python -m pip install pre-commit

- name: Run flake8
- name: Run pre-commit
if: always()
run: |
make flake8
pre-commit run --all-files --show-diff-on-failure

- name: Run protolint
uses: plexsystems/[email protected]
Expand Down
69 changes: 69 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
repos:

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args: [
--line-length, "79",
--force-exclude, ansys/api/fluent/v0/|ansys/fluent/core/meshing/tui.py|ansys/fluent/core/solver/tui.py|ansys/fluent/core/solver/settings.py,
ansys, codegen, doc, examples, tests
]

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: [
--profile, black,
--skip, ansys/fluent/core/meshing/tui.py,
--skip, ansys/fluent/core/solver/tui.py,
--skip, ansys/fluent/core/solver/settings.py,
--skip-glob, ansys/api/fluent/v0/*,
--force-sort-within-sections,
--line-length, "79",
--section-default, THIRDPARTY,
--filter-files,
ansys, codegen, doc, examples, tests
]

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
args: [
--exclude, ansys/api/fluent/v0/* ansys/fluent/core/meshing/tui.py ansys/fluent/core/solver/tui.py ansys/fluent/core/solver/settings.py,
--select, W191 W291 W293 W391 E115 E117 E122 E124 E125 E225 E231 E301 E303 F401 F403 N801 N802 N803 N804 N805 N806,
--count,
--statistics,
--max-complexity, "10",
--max-line-length, "79",
ansys, codegen, doc, examples, tests
]

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args: [
--skip, "ansys/api/fluent/v0/*,ansys/fluent/core/meshing/tui.py,ansys/fluent/core/solver/tui.py,ansys/fluent/core/solver/settings.py",
]

- repo: https://github.com/myint/docformatter
rev: v1.3.1
hooks:
- id: docformatter
exclude: ^(tests\/|ansys\/api\/fluent\/v0\/|ansys\/fluent\/core\/meshing\/tui.py|ansys\/fluent\/core\/solver\/tui.py|ansys\/fluent\/core\/solver\/settings.py)
args: [-r, --in-place]

#- repo: https://github.com/pycqa/pydocstyle
# rev: 6.1.1
# hooks:
# - id: pydocstyle
# additional_dependencies: [toml]
# exclude: ^(tests\/|ansys\/api\/fluent\/v0\/|ansys\/fluent\/core\/meshing\/tui.py|ansys\/fluent\/core\/solver\/tui.py|ansys\/fluent\/core\/solver\/settings.py)
# args: [
# # Error codes: http://www.pydocstyle.org/en/stable/error_codes.html
# --ignore, "D107,D105,D4",
# --count,
# ]
File renamed without changes.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
flake8:
@echo "Running flake8"
@flake8 .
style:
@echo "Running code style"
@pre-commit run --all-files --show-diff-on-failure

install:
@pip install -r requirements_build.txt
Expand Down
11 changes: 5 additions & 6 deletions ansys/fluent/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""A package providing Fluent's Solver and Meshing capabilities in Python."""

import appdirs
import os

import appdirs

from ansys.fluent.core._version import __version__ # noqa: F401
from ansys.fluent.core.launcher.launcher import launch_fluent # noqa: F401
from ansys.fluent.core.session import Session
from ansys.fluent.core.utils.logging import LOG
from ansys.fluent.core._version import __version__ # noqa: F401

try:
from ansys.fluent.core.meshing import tui as meshing_tui
Expand All @@ -19,8 +20,7 @@


def set_log_level(level):
"""
Set logging level.
"""Set logging level.

Parameters
----------
Expand All @@ -42,8 +42,7 @@ def disable_logging_to_stdout():


def enable_logging_to_file(filepath: str = None):
"""
Enable logging to file.
"""Enable logging to file.

Parameters
----------
Expand Down
8 changes: 3 additions & 5 deletions ansys/fluent/core/examples/downloads.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Functions to download sample datasets from the pyansys data repository.
"""Functions to download sample datasets from the pyansys data repository.

Example
-------
Expand All @@ -8,7 +7,6 @@
>>> filename = examples.download_file("bracket.iges", "geometry")
>>> filename
'/home/user/.local/share/ansys_fluent_core/examples/bracket.iges'

"""
import os
import shutil
Expand All @@ -19,13 +17,13 @@


def get_ext(filename):
"""Extract the extension of the filename"""
"""Extract the extension of the filename."""
ext = os.path.splitext(filename)[1].lower()
return ext


def delete_downloads():
"""Delete all downloaded examples to free space or update the files"""
"""Delete all downloaded examples to free space or update the files."""
shutil.rmtree(pyfluent.EXAMPLES_PATH)
os.makedirs(pyfluent.EXAMPLES_PATH)
return True
Expand Down
11 changes: 5 additions & 6 deletions ansys/fluent/core/launcher/launcher.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
"""
Provide a module for launching Fluent.
"""Provide a module for launching Fluent.

This module supports both starting Fluent locally or connecting to a remote
instance with gRPC.
This module supports both starting Fluent locally or connecting to a
remote instance with gRPC.
"""

import json
import os
from pathlib import Path
import platform
import subprocess
import tempfile
import time
from pathlib import Path
from typing import Any, Dict

from ansys.fluent.core.utils.logging import LOG
from ansys.fluent.core.session import Session
from ansys.fluent.core.utils.logging import LOG

_THIS_DIR = os.path.dirname(__file__)
_OPTIONS_FILE = os.path.join(_THIS_DIR, "fluent_launcher_options.json")
Expand Down
4 changes: 1 addition & 3 deletions ansys/fluent/core/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ def wrapper(self, obj=None):
return wrapper

def __new__(cls, name, bases, attrs):
attrs[
"_get_parent_by_type"
] = cls.__create_get_parent_by_type()
attrs["_get_parent_by_type"] = cls.__create_get_parent_by_type()
attrs["_get_top_most_parent"] = cls.__create_get_top_most_parent()
return super(PyLocalBaseMeta, cls).__new__(cls, name, bases, attrs)

Expand Down
Loading