diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0ff7e63..f055986 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,9 @@ repos: -- repo: https://github.com/psf/black - rev: 23.9.1 - hooks: - - id: black - language_version: "python3.10" - -- repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.292 - hooks: - - id: ruff - language_version: "python3.10" +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.1.5 + hooks: + # Run the linter. + - id: ruff + # Run the formatter. + - id: ruff-format diff --git a/agasc/scripts/supplement_diff.py b/agasc/scripts/supplement_diff.py index ec21969..5ece6a1 100755 --- a/agasc/scripts/supplement_diff.py +++ b/agasc/scripts/supplement_diff.py @@ -18,7 +18,9 @@ from astropy.io import ascii -def read_file(filename, exclude=[]): +def read_file(filename, exclude=None): + if exclude is None: + exclude = [] formats = { "agasc_versions": {k: "{:>21s}" for k in ["mags", "obs", "bad", "supplement"]}, "last_updated": {k: "{:>21s}" for k in ["mags", "obs", "bad", "supplement"]}, @@ -36,7 +38,7 @@ def read_file(filename, exclude=[]): continue node = h5.get_node(f"/{name}") t = table.Table(node[:]) - t.convert_bytestring_to_unicode + t.convert_bytestring_to_unicode() s = StringIO() ascii.write(t, s, format="fixed_width", formats=formats.get(name, {})) s.seek(0) diff --git a/agasc/scripts/supplement_tasks.py b/agasc/scripts/supplement_tasks.py index b4f4e22..cc989e5 100644 --- a/agasc/scripts/supplement_tasks.py +++ b/agasc/scripts/supplement_tasks.py @@ -21,11 +21,10 @@ from cxotime import CxoTime AGASC_DATA = Path(os.environ["SKA"]) / "data" / "agasc" +SENDER = f"{getpass.getuser()}@{platform.uname()[1]}" -def email_promotion_report( - filenames, destdir, to, sender=f"{getpass.getuser()}@{platform.uname()[1]}" -): +def email_promotion_report(filenames, destdir, to, sender=SENDER): date = CxoTime().date[:14] filenames = "- " + "\n- ".join([str(f) for f in filenames]) diff --git a/agasc/supplement/magnitudes/mag_estimate_report.py b/agasc/supplement/magnitudes/mag_estimate_report.py index a55f2f3..594a0f8 100644 --- a/agasc/supplement/magnitudes/mag_estimate_report.py +++ b/agasc/supplement/magnitudes/mag_estimate_report.py @@ -25,6 +25,7 @@ loader=jinja2.PackageLoader("agasc.supplement.magnitudes", "templates"), autoescape=jinja2.select_autoescape(["html", "xml"]), ) +SENDER = f"{getpass.getuser()}@{platform.uname()[1]}" logger = logging.getLogger("agasc.supplement") @@ -503,8 +504,9 @@ def plot_agasc_id_single( ylims_set = True if ylim == "max" or not ylims_set: if np.any(ok_ylim): - ymin, ymax = np.min(telem["mags"][ok_ylim]), np.max( - telem["mags"][ok_ylim] + ymin, ymax = ( + np.min(telem["mags"][ok_ylim]), + np.max(telem["mags"][ok_ylim]), ) else: ymin, ymax = np.min(telem["mags"]), np.max(telem["mags"]) @@ -939,9 +941,7 @@ def plot_set(self, agasc_id, args, telem=None, filename=None): return fig -def email_bad_obs_report( - bad_obs, to, sender=f"{getpass.getuser()}@{platform.uname()[1]}" -): +def email_bad_obs_report(bad_obs, to, sender=SENDER): date = CxoTime().date[:14] message = JINJA2.get_template("email_report.txt") diff --git a/agasc/supplement/magnitudes/star_obs_catalogs.py b/agasc/supplement/magnitudes/star_obs_catalogs.py index 82d8932..10c14f2 100644 --- a/agasc/supplement/magnitudes/star_obs_catalogs.py +++ b/agasc/supplement/magnitudes/star_obs_catalogs.py @@ -55,6 +55,6 @@ def load(tstop=None): """ Populate this module's global variable STARS_OBS. """ - global STARS_OBS + global STARS_OBS # noqa: PLW0603 if STARS_OBS is None: STARS_OBS = get_star_observations(stop=tstop) diff --git a/agasc/supplement/magnitudes/update_mag_supplement.py b/agasc/supplement/magnitudes/update_mag_supplement.py index 9d36346..fc90e64 100755 --- a/agasc/supplement/magnitudes/update_mag_supplement.py +++ b/agasc/supplement/magnitudes/update_mag_supplement.py @@ -49,7 +49,9 @@ def level0_archive_time_range(): return CxoTime(t_stop).date, CxoTime(t_start).date -def get_agasc_id_stats(agasc_ids, obs_status_override={}, tstop=None, no_progress=None): +def get_agasc_id_stats( + agasc_ids, obs_status_override=None, tstop=None, no_progress=None +): """ Call mag_stats.get_agasc_id_stats for each AGASC ID @@ -67,6 +69,8 @@ def get_agasc_id_stats(agasc_ids, obs_status_override={}, tstop=None, no_progres from agasc.supplement.magnitudes import mag_estimate + if obs_status_override is None: + obs_status_override = {} fails = [] obs_stats = [] agasc_stats = [] diff --git a/agasc/tests/test_agasc_2.py b/agasc/tests/test_agasc_2.py index 8d5763b..01611a1 100644 --- a/agasc/tests/test_agasc_2.py +++ b/agasc/tests/test_agasc_2.py @@ -238,7 +238,7 @@ def _test_agasc(ra, dec, ref_stars, version="1p7"): if adj_mag < 11.5 * 0.99: # Allow for loss of precision in output of mp_get_agasc print("Bad star", agasc_id, rad, adj_mag, bad_is_star1) - assert False + raise AssertionError() def test_basic(): diff --git a/agasc/tests/test_obs_status.py b/agasc/tests/test_obs_status.py index a303cff..c3b1308 100644 --- a/agasc/tests/test_obs_status.py +++ b/agasc/tests/test_obs_status.py @@ -908,7 +908,7 @@ def mock_write(fname, *args, **kwargs): monkeypatch.setattr( table.Table, "write", - lambda *args, **kwargs: mock_write(filename, *args, **kwargs), + lambda *args, **kwargs: mock_write(filename, *args, **kwargs), # noqa: B023 ) status = update_supplement.parse_args(filename=filename) print(filename) @@ -927,7 +927,7 @@ def mock_write(*args, **kwargs): if "path" in kwargs and kwargs["path"] == "bad": mock_write.n_calls += 1 ref = table.Table() - assert False + raise AssertionError() if "path" in kwargs and kwargs["path"] == "obs": mock_write.n_calls += 1 ref = table.Table( diff --git a/ruff.toml b/ruff.toml index 49b41cc..0374411 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,117 +1,55 @@ -# Copy ruff settings from pandas -line-length = 100 +# Copied originally from pandas target-version = "py310" + # fix = true unfixable = [] select = [ - # isort - "I", - # pyflakes - "F", - # pycodestyle - "E", "W", - # flake8-2020 - "YTT", - # flake8-bugbear - "B", - # flake8-quotes - "Q", - # flake8-debugger - "T10", - # flake8-gettext - "INT", - # pylint - "PLC", "PLE", "PLR", "PLW", - # misc lints - "PIE", - # flake8-pyi - "PYI", - # tidy imports - "TID", - # implicit string concatenation - "ISC", - # type-checking imports - "TCH", - # comprehensions - "C4", - # pygrep-hooks - "PGH" + "I", # isort + "F", # pyflakes + "E", "W", # pycodestyle + "YTT", # flake8-2020 + "B", # flake8-bugbear + "Q", # flake8-quotes + "T10", # flake8-debugger + "INT", # flake8-gettext + "PLC", "PLE", "PLR", "PLW", # pylint + "PIE", # misc lints + "PYI", # flake8-pyi + "TID", # tidy imports + "ISC", # implicit string concatenation + "TCH", # type-checking imports + "C4", # comprehensions + "PGH" # pygrep-hooks ] ignore = [ - # space before : (needed for how black formats slicing) - # "E203", # not yet implemented - # module level import not at top of file - "E402", - # do not assign a lambda expression, use a def - "E731", - # line break before binary operator - # "W503", # not yet implemented - # line break after binary operator - # "W504", # not yet implemented - # controversial - "B006", - # controversial?: Loop control variable not used within loop body - # "B007", - # controversial - "B008", - # setattr is used to side-step mypy - "B009", - # getattr is used to side-step mypy - "B010", - # tests use assert False - "B011", - # tests use comparisons but not their returned value - "B015", - # false positives - "B019", - # Loop control variable overrides iterable it iterates - "B020", - # Function definition does not bind loop variable - "B023", - # No explicit `stacklevel` keyword argument found - "B028", - # Functions defined inside a loop must not use variables redefined in the loop - # "B301", # not yet implemented - # Only works with python >=3.10 - "B905", - # Too many arguments to function call - "PLR0913", - # Too many returns - "PLR0911", - # Too many branches - "PLR0912", - # Too many statements - "PLR0915", - # Redefined loop name - "PLW2901", - # Global statements are discouraged - "PLW0603", - # Docstrings should not be included in stubs - "PYI021", - # No builtin `eval()` allowed - "PGH001", - # compare-to-empty-string - "PLC1901", - # Use typing_extensions.TypeAlias for type aliases - # "PYI026", # not yet implemented - # Use "collections.abc.*" instead of "typing.*" (PEP 585 syntax) - # "PYI027", # not yet implemented - # while int | float can be shortened to float, the former is more explicit - # "PYI041", # not yet implemented + "ISC001", # Disable this for compatibility with ruff format + "B028", # No explicit `stacklevel` keyword argument found + "B905", # `zip()` without an explicit `strict=` parameter + "E402", # module level import not at top of file + "E731", # do not assign a lambda expression, use a def + "PLC1901", # compare-to-empty-string + "PLR0911", # Too many returns + "PLR0912", # Too many branches + "PLR0913", # Too many arguments to function call + "PLR2004", # Magic number + "PYI021", # Docstrings should not be included in stubs + "PLR0915", # Too many statements +] - # Additional checks that don't pass yet - # Useless statement - "B018", - # Within an except clause, raise exceptions with ... - "B904", - # Magic number - "PLR2004", - # Consider `elif` instead of `else` then `if` to remove indentation level - "PLR5501", +# TODO : fix these and stop ignoring. Commented out ones are common and OK to except. +extend-ignore = [ + "PGH004", # Use specific rule codes when using `noqa` ] -exclude = [ - "docs/", +extend-exclude = [ + "docs", + "validate", ] + +[pycodestyle] +max-line-length = 100 # E501 reports lines that exceed the length of 100. + +[lint.extend-per-file-ignores] +"__init__.py" = ["E402", "F401", "F403"]