Skip to content

Commit

Permalink
Add ruff linter, including pre-commit hook support. (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenskeiner authored Jul 5, 2023
1 parent 868bf8a commit d3cc7ba
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 126 deletions.
5 changes: 2 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
FROM mcr.microsoft.com/devcontainers/base:jammy
# FROM mcr.microsoft.com/devcontainers/base:jammy

ARG DEBIAN_FRONTEND=noninteractive
ARG USER=vscode

RUN DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get update \
&& apt-get install -y build-essential --no-install-recommends make \
ca-certificates \
git \
Expand Down Expand Up @@ -42,4 +41,4 @@ RUN echo "done 0" \
&& pyenv global ${PYTHON_VERSION} \
&& echo "done 3" \
&& curl -sSL https://install.python-poetry.org | python3 - \
&& poetry config virtualenvs.in-project true
&& poetry config virtualenvs.in-project true
2 changes: 1 addition & 1 deletion .github/workflows/publish-rc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Python 3.10.
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"
cache: 'poetry'
- name: Determine RC version number.
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Python 3.10.
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: "3.11"
cache: 'poetry'
- name: Set poetry package version from tag.
run: poetry version ${{ github.ref_name }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# Ruff linter cache
.ruff_cache
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.275
hooks:
- id: ruff
1 change: 0 additions & 1 deletion exchange_calendars_extensions/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
from datetime import date
from datetime import timedelta

Expand Down
298 changes: 256 additions & 42 deletions poetry.lock

Large diffs are not rendered by default.

61 changes: 57 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ documentation = "https://github.com/jenskeiner/exchange_calendars_extensions/tre
keywords = ["exchange", "calendar", "trading", "holidays"]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Intended Audience :: Financial and Insurance Industry",
"Intended Audience :: Information Technology",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
]
packages = [{include = "exchange_calendars_extensions"}]

Expand All @@ -37,6 +41,55 @@ pydantic = "~=1.10.8"
[tool.poetry.group.dev.dependencies]
pytest = ">=7.3.1,<7.5.0"
pytest-cov = "~=4.1.0"
pre-commit = "~=3.3.3"


#[tool.pytest.ini_options]
#addopts = "--cov=exchange_calendars_extensions --cov-report=term-missing"

[tool.ruff]
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
select = ["E", "F"]
ignore = ["E501"]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

# Same as Black.
line-length = 88

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.10.
target-version = "py38"

[tool.ruff.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 10
31 changes: 0 additions & 31 deletions test.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ def pytest_pyfunc_call(pyfuncitem):
original_func = pyfuncitem.obj
pyfuncitem.obj = run_test_in_separate_process(original_func)

outcome = yield
yield
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ def test_monthly_expiry_rollback_one_day():


@pytest.mark.isolated
def test_quarterly_expiry_rollback_multiple_days():
def test_monthly_expiry_rollback_multiple_days():
add_test_calendar_and_apply_extensions(holidays=[pd.Timestamp("2022-02-18")],
adhoc_holidays=[pd.Timestamp("2022-02-17")],
regular_special_close=time(14, 00),
Expand Down
82 changes: 41 additions & 41 deletions tests/test_holiday_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def test_get_holiday_calendar_from_timestamps(self):
holidays = calendar.holidays(start=pd.Timestamp("2019-01-01"), end=pd.Timestamp("2019-01-31"))
assert pd.Timestamp("2019-01-01") in holidays
assert pd.Timestamp("2019-01-02") in holidays
assert not pd.Timestamp("2019-01-03") in holidays
assert not pd.Timestamp("2019-01-04") in holidays
assert pd.Timestamp("2019-01-03") not in holidays
assert pd.Timestamp("2019-01-04") not in holidays

def test_get_holiday_calendar_from_day_of_week(self):
calendar = get_holiday_calendar_from_day_of_week(0)
Expand All @@ -30,24 +30,24 @@ def test_get_holiday_calendar_from_day_of_week(self):
assert pd.Timestamp("2019-01-14") in holidays
assert pd.Timestamp("2019-01-21") in holidays
assert pd.Timestamp("2019-01-28") in holidays
assert not pd.Timestamp("2019-01-01") in holidays
assert not pd.Timestamp("2019-01-02") in holidays
assert not pd.Timestamp("2019-01-03") in holidays
assert not pd.Timestamp("2019-01-04") in holidays
assert not pd.Timestamp("2019-01-05") in holidays
assert not pd.Timestamp("2019-01-06") in holidays
assert not pd.Timestamp("2019-01-08") in holidays
assert not pd.Timestamp("2019-01-09") in holidays
assert not pd.Timestamp("2019-01-10") in holidays
assert not pd.Timestamp("2019-01-11") in holidays
assert not pd.Timestamp("2019-01-12") in holidays
assert not pd.Timestamp("2019-01-13") in holidays
assert not pd.Timestamp("2019-01-15") in holidays
assert not pd.Timestamp("2019-01-16") in holidays
assert not pd.Timestamp("2019-01-17") in holidays
assert not pd.Timestamp("2019-01-18") in holidays
assert not pd.Timestamp("2019-01-19") in holidays
assert not pd.Timestamp("2019-01-20") in holidays
assert pd.Timestamp("2019-01-01") not in holidays
assert pd.Timestamp("2019-01-02") not in holidays
assert pd.Timestamp("2019-01-03") not in holidays
assert pd.Timestamp("2019-01-04") not in holidays
assert pd.Timestamp("2019-01-05") not in holidays
assert pd.Timestamp("2019-01-06") not in holidays
assert pd.Timestamp("2019-01-08") not in holidays
assert pd.Timestamp("2019-01-09") not in holidays
assert pd.Timestamp("2019-01-10") not in holidays
assert pd.Timestamp("2019-01-11") not in holidays
assert pd.Timestamp("2019-01-12") not in holidays
assert pd.Timestamp("2019-01-13") not in holidays
assert pd.Timestamp("2019-01-15") not in holidays
assert pd.Timestamp("2019-01-16") not in holidays
assert pd.Timestamp("2019-01-17") not in holidays
assert pd.Timestamp("2019-01-18") not in holidays
assert pd.Timestamp("2019-01-19") not in holidays
assert pd.Timestamp("2019-01-20") not in holidays

def test_merge_calendars(self):
calendar1 = get_holiday_calendar_from_timestamps([pd.Timestamp("2019-01-01"), pd.Timestamp("2019-01-02")])
Expand All @@ -60,26 +60,26 @@ def test_merge_calendars(self):
assert pd.Timestamp("2019-01-14") in holidays
assert pd.Timestamp("2019-01-21") in holidays
assert pd.Timestamp("2019-01-28") in holidays
assert not pd.Timestamp("2019-01-03") in holidays
assert not pd.Timestamp("2019-01-04") in holidays
assert not pd.Timestamp("2019-01-05") in holidays
assert not pd.Timestamp("2019-01-06") in holidays
assert not pd.Timestamp("2019-01-08") in holidays
assert not pd.Timestamp("2019-01-09") in holidays
assert not pd.Timestamp("2019-01-10") in holidays
assert not pd.Timestamp("2019-01-11") in holidays
assert not pd.Timestamp("2019-01-12") in holidays
assert not pd.Timestamp("2019-01-13") in holidays
assert not pd.Timestamp("2019-01-15") in holidays
assert not pd.Timestamp("2019-01-16") in holidays
assert not pd.Timestamp("2019-01-17") in holidays
assert not pd.Timestamp("2019-01-18") in holidays
assert not pd.Timestamp("2019-01-19") in holidays
assert not pd.Timestamp("2019-01-20") in holidays
assert not pd.Timestamp("2019-01-22") in holidays
assert not pd.Timestamp("2019-01-23") in holidays
assert not pd.Timestamp("2019-01-24") in holidays
assert not pd.Timestamp("2019-01-25") in holidays
assert pd.Timestamp("2019-01-03") not in holidays
assert pd.Timestamp("2019-01-04") not in holidays
assert pd.Timestamp("2019-01-05") not in holidays
assert pd.Timestamp("2019-01-06") not in holidays
assert pd.Timestamp("2019-01-08") not in holidays
assert pd.Timestamp("2019-01-09") not in holidays
assert pd.Timestamp("2019-01-10") not in holidays
assert pd.Timestamp("2019-01-11") not in holidays
assert pd.Timestamp("2019-01-12") not in holidays
assert pd.Timestamp("2019-01-13") not in holidays
assert pd.Timestamp("2019-01-15") not in holidays
assert pd.Timestamp("2019-01-16") not in holidays
assert pd.Timestamp("2019-01-17") not in holidays
assert pd.Timestamp("2019-01-18") not in holidays
assert pd.Timestamp("2019-01-19") not in holidays
assert pd.Timestamp("2019-01-20") not in holidays
assert pd.Timestamp("2019-01-22") not in holidays
assert pd.Timestamp("2019-01-23") not in holidays
assert pd.Timestamp("2019-01-24") not in holidays
assert pd.Timestamp("2019-01-25") not in holidays

def test_merge_calendars_with_overlapping_holidays(self):
calendar1 = get_holiday_calendar_from_timestamps([pd.Timestamp("2019-01-01"), pd.Timestamp("2019-01-02")])
Expand All @@ -90,7 +90,7 @@ def test_merge_calendars_with_overlapping_holidays(self):
assert pd.Timestamp("2019-01-01") in holidays
assert pd.Timestamp("2019-01-02") in holidays
assert pd.Timestamp("2019-01-03") in holidays
assert not pd.Timestamp("2019-01-04") in holidays
assert pd.Timestamp("2019-01-04") not in holidays

def test_get_holidays_calendar(self):
calendar = get_calendar("XLON")
Expand Down

0 comments on commit d3cc7ba

Please sign in to comment.