From 23e92efdf603e0fb077ee375ad8dc5a5713189ae Mon Sep 17 00:00:00 2001 From: Bryce Kalmbach Date: Thu, 2 Nov 2023 11:36:59 -0700 Subject: [PATCH] Add T&S pre-commit settings to ts_imsim. --- setup.cfg => .flake8 | 0 .github/workflows/changelog.yaml | 19 +++++++++++++++ .github/workflows/lint.yaml | 24 +++++++++++++++++++ .gitignore | 4 +--- .isort.cfg | 2 ++ .pre-commit-config.yaml | 33 ++++++++++++++++++++++++++ .ruff.toml | 8 +++++++ .ts_pre_commit_config.yaml | 6 ----- doc/versionHistory.rst | 6 +++++ python/lsst/ts/imsim/closedLoopTask.py | 2 +- python/lsst/ts/imsim/imsimCmpt.py | 10 ++++---- python/lsst/ts/imsim/opdMetrology.py | 2 -- python/lsst/ts/imsim/utils/utility.py | 3 ++- 13 files changed, 101 insertions(+), 18 deletions(-) rename setup.cfg => .flake8 (100%) create mode 100644 .github/workflows/changelog.yaml create mode 100644 .github/workflows/lint.yaml create mode 100644 .isort.cfg create mode 100644 .pre-commit-config.yaml create mode 100644 .ruff.toml delete mode 100644 .ts_pre_commit_config.yaml diff --git a/setup.cfg b/.flake8 similarity index 100% rename from setup.cfg rename to .flake8 diff --git a/.github/workflows/changelog.yaml b/.github/workflows/changelog.yaml new file mode 100644 index 0000000..96d8245 --- /dev/null +++ b/.github/workflows/changelog.yaml @@ -0,0 +1,19 @@ +name: ChangelogUpdated +on: + pull_request: + types: [assigned, opened, synchronize, reopened, labeled, unlabeled] + branches: + - develop +jobs: + build: + name: Check Actions + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Changelog check + uses: Zomzog/changelog-checker@v1.2.0 + with: + fileName: doc/versionHistory.rst + checkNotification: Simple + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..0326bb1 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,24 @@ +name: lint + +on: + - push + - pull_request + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.11' + + - name: Install + run: | + $CONDA/bin/conda install -c lsstts ts-pre-commit-config -y + $CONDA/bin/conda install -c conda-forge pre-commit -y + + - name: Run pre commit checks + run: $CONDA/bin/pre-commit run --all diff --git a/.gitignore b/.gitignore index d205584..72bdcc8 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,6 @@ config.log *Lib.py # Pre-commit configs -.pre-commit-config.yaml -.flake8 -.isort.cfg .mypy.ini # Built by sconsUtils @@ -37,3 +34,4 @@ pytest_session.txt # MacOS metadata .DS_Store +.clang-format diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..b9fb3f3 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,2 @@ +[settings] +profile=black diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7d3d971 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +repos: + - repo: https://github.com/psf/black + rev: 23.7.0 + hooks: + - id: black + + - repo: https://github.com/pycqa/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + + - repo: https://github.com/lsst-ts/pre-commit-xmllint + rev: v1.0.0 + hooks: + - id: format-xmllint + + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + name: isort (python) + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-yaml + exclude: conda/meta.yaml|^policy/config/[input|image|output|stamp|opd] + - id: check-xml + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.287 + hooks: + - id: ruff diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..7eb1bc9 --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,8 @@ +ignore = ["E203", "E226", "E228", "E999", "N802", "N803", "N806", "N812", "N813", "N815", "N816", "N999"] +line-length = 110 +exclude = ["__init__.py", "doc/conf.py"] +select = ["E", "F", "N", "W"] +[pycodestyle] +max-doc-length = 79 +[pydocstyle] +convention = "numpy" diff --git a/.ts_pre_commit_config.yaml b/.ts_pre_commit_config.yaml deleted file mode 100644 index e1e33e9..0000000 --- a/.ts_pre_commit_config.yaml +++ /dev/null @@ -1,6 +0,0 @@ -check-yaml: true -check-xml: true -black: true -flake8: true -isort: true -mypy: false diff --git a/doc/versionHistory.rst b/doc/versionHistory.rst index a524ff0..3505ec9 100644 --- a/doc/versionHistory.rst +++ b/doc/versionHistory.rst @@ -6,6 +6,12 @@ Version History ################## +------------- +0.6.1 +------------- + +* Add T&S pre-commit settings to ts_imsim. + ------------- 0.6.0 ------------- diff --git a/python/lsst/ts/imsim/closedLoopTask.py b/python/lsst/ts/imsim/closedLoopTask.py index e984497..075da41 100644 --- a/python/lsst/ts/imsim/closedLoopTask.py +++ b/python/lsst/ts/imsim/closedLoopTask.py @@ -756,7 +756,7 @@ def _generate_images( imsim_config_yaml["output"]["opd"]["file_name"], ) if os.path.exists(imsimOpdPath): - self.log.info(f"OPD already created, moving to analysis.") + self.log.info("OPD already created, moving to analysis.") else: self.log.info( f"Writing Imsim Configuration file to {imsim_config_path}" diff --git a/python/lsst/ts/imsim/imsimCmpt.py b/python/lsst/ts/imsim/imsimCmpt.py index 18cd8cf..d13a230 100644 --- a/python/lsst/ts/imsim/imsimCmpt.py +++ b/python/lsst/ts/imsim/imsimCmpt.py @@ -285,12 +285,12 @@ def add_config_header(self, obs_metadata: ObsMetadata) -> str: Header information for ImSim config """ header_text = " header:\n" - header_text += f" mjd: *mjd\n" + header_text += " mjd: *mjd\n" header_text += ( f" observationStartMJD: {obs_metadata.mjd - (15/(60*60*24))}\n" ) - header_text += f" seqnum: *seqnum\n" - header_text += f" band: *band\n" + header_text += " seqnum: *seqnum\n" + header_text += " band: *band\n" header_text += f" fieldRA: {obs_metadata.ra}\n" header_text += f" fieldDec: {obs_metadata.dec}\n" header_text += f" rotTelPos: {obs_metadata.rotator_angle}\n" @@ -602,8 +602,8 @@ def _map_opd_to_zk(self, rot_opd_in_deg: float, num_opd: int) -> np.ndarray: opd_rot = opd.copy() # Since to rotate the opd we need to substitue the nan values # for zeros, we need to find the minimum value of the opd - # excluding the nan values. Then after the rotation we will discard - # the values that are smaller than the minimum value. + # excluding the nan values. Then after the rotation we will + # discard the values that are smaller than the minimum value. # Note that we use order = 0 to avoid interpolation errors. min_value = np.nanmin(np.abs(opd_rot)) opd_rot[np.isnan(opd_rot)] = 0.0 diff --git a/python/lsst/ts/imsim/opdMetrology.py b/python/lsst/ts/imsim/opdMetrology.py index 3c9d438..74b0991 100644 --- a/python/lsst/ts/imsim/opdMetrology.py +++ b/python/lsst/ts/imsim/opdMetrology.py @@ -19,8 +19,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os - import numpy as np import yaml from astropy.io import fits diff --git a/python/lsst/ts/imsim/utils/utility.py b/python/lsst/ts/imsim/utils/utility.py index 4fe4719..55f2f76 100644 --- a/python/lsst/ts/imsim/utils/utility.py +++ b/python/lsst/ts/imsim/utils/utility.py @@ -173,7 +173,8 @@ def __enter__(self) -> None: def __exit__(self, exc_type: None, exc_val: None, exc_tb: None) -> None: for key in self._overrides: - # Restore original values, delete or keep as they are based on the original state + # Restore original values, delete or keep as they are + # based on the original state. if key in self._originals: os.environ[key] = self._originals[key] else: