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

DM-39857: Remove --flake8 option and add ruff config #54

Merged
merged 6 commits into from
Jul 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- name: Build and install
run: |
python -m pip install --upgrade pip setuptools "flake8<5"
python -m pip install --upgrade pip setuptools
python -m pip install .[yaml,test]

- name: Run tests
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/cmake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ jobs:
python-version: 3.8

- name: Update Python packages
run: pip install --upgrade setuptools "flake8<5"
run: pip install --upgrade setuptools

- name: Install Python prereqs
run: |
pip install \
numpy \
pybind11[global] \
pytest \
pytest-flake8 \
pyyaml \
hpgeom

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ on:
jobs:
call-workflow:
uses: lsst/rubin_workflows/.github/workflows/lint.yaml@main
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
19 changes: 10 additions & 9 deletions misc/makeHilbertLuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""This script generates the lookup tables used by the C++ Hilbert index
"""Generates the lookup tables used by the C++ Hilbert index
functions in `lsst/sphgeom/curve.h`.
"""

Expand Down Expand Up @@ -68,7 +68,7 @@ def rotate_left(x, d):


def bit_component(x, i):
"""Return i-th bit of x"""
"""Return i-th bit of x."""
return (x & 2**i) >> i


Expand Down Expand Up @@ -96,7 +96,7 @@ def i_to_p(i):


def inverse_gc(g):
"""The inverse gray code."""
"""Invert the gray code."""
i = g
j = 1
while j < N:
Expand All @@ -106,12 +106,12 @@ def inverse_gc(g):


def g(i):
"""The direction between subcube i and the next one"""
"""Return the direction between subcube i and the next one."""
return int(np.log2(gc(i) ^ gc(i + 1)))


def d(i):
"""The direction of the arrow whithin a subcube."""
"""Return the direction of the arrow within a subcube."""
if i == 0:
return 0
elif (i % 2) == 0:
Expand All @@ -132,7 +132,7 @@ def T_inv(e, d, b):


def TR_algo2(p, M):
"""Return the Hilbert index of point p"""
"""Return the Hilbert index of point p."""
# h will contain the Hilbert index
h = 0
# ve and vd contain the entry point and dimension of the current subcube
Expand All @@ -158,7 +158,7 @@ def TR_algo2(p, M):


def TR_algo3(h, M):
"""Return the coordinates for the Hilbert index h"""
"""Return the coordinates for the Hilbert index h."""
ve = 0
vd = 0
p = [0] * N
Expand All @@ -175,6 +175,7 @@ def TR_algo3(h, M):


def deinterleave(z, M):
"""De-interleave."""
x = 0
y = 0
for i in range(M):
Expand All @@ -184,7 +185,7 @@ def deinterleave(z, M):


def make_TR_algo2_lut(M):
"""Return a LUT for the Hilbert index of point p"""
"""Return a LUT for the Hilbert index of point p."""
h = 0
lut = []
for ie in (0, 3):
Expand Down Expand Up @@ -216,7 +217,7 @@ def make_TR_algo2_lut(M):


def make_TR_algo3_lut(M):
"""Return a LUT for the point corresponding to the Hilbert index h"""
"""Return a LUT for the point corresponding to the Hilbert index h."""
h = 0
lut = []
for ie in (0, 3):
Expand Down
57 changes: 52 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ dynamic = ["version"]
[project.optional-dependencies]
test = [
"pytest >= 3.2",
"flake8 >= 3.7.5",
"pytest-flake8 >= 1.0.4",
]
yaml = ["pyyaml >= 5.1"]

Expand All @@ -67,8 +65,7 @@ line_length = 110
write_to = "python/lsst/sphgeom/version.py"

[tool.pytest.ini_options]
addopts = "--flake8"
flake8-ignore = ["E133", "E226", "E228", "N802", "N803", "N806", "N812", "N815", "N816", "W503"]
addopts = "--import-mode=importlib" # Recommended as best practice

[tool.pydocstyle]
convention = "numpy"
Expand All @@ -78,4 +75,54 @@ convention = "numpy"
# Docstring at the very first line is not required
# D200, D205 and D400 all complain if the first sentence of the docstring does
# not fit on one line.
add-ignore = ["D107", "D105", "D102", "D100", "D200", "D205", "D400"]
add-ignore = ["D107", "D105", "D102", "D100", "D200", "D205", "D400", "D104"]

[tool.coverage.report]
show_missing = true
exclude_lines = [
"pragma: no cover",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

[tool.ruff]
exclude = [
"__init__.py",
]
ignore = [
"N802",
"N803",
"N806",
"N812",
"N815",
"N816",
"N999",
"D107",
"D105",
"D102",
"D104",
"D100",
"D200",
"D205",
]
line-length = 110
select = [
"E", # pycodestyle
"F", # pyflakes
"N", # pep8-naming
"W", # pycodestyle
"D", # pydocstyle
"UP", # pyupgrade
]
target-version = "py310"
extend-select = [
"RUF100", # Warn about unused noqa
]

[tool.ruff.pycodestyle]
max-doc-length = 79

[tool.ruff.pydocstyle]
convention = "numpy"
4 changes: 2 additions & 2 deletions python/lsst/sphgeom/_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def region_representer(dumper, data):


def region_constructor(loader, node):
"""Construct a sphgeom region from YAML"""
"""Construct a sphgeom region from YAML."""
mapping = loader.construct_mapping(node)
encoded = bytes.fromhex(mapping["encoded"])
# The generic Region base class can instantiate a region of the
Expand All @@ -92,7 +92,7 @@ def region_constructor(loader, node):


def pixel_representer(dumper, data):
"""Represent a pixelization in YAML
"""Represent a pixelization in YAML.

Stored as the pixelization level in a mapping with a single key
``level``.
Expand Down
4 changes: 3 additions & 1 deletion tests/test_Angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@


class AngleTestCase(unittest.TestCase):
"""Test the Angle class."""

def testConstruction(self):
a1 = Angle(1.0)
a2 = Angle.fromRadians(1.0)
Expand Down Expand Up @@ -63,7 +65,7 @@ def testString(self):
self.assertEqual(str(Angle(1)), "1.0")
self.assertEqual(repr(Angle(1)), "Angle(1.0)")
a = Angle(2.5)
self.assertEqual(a, eval(repr(a), dict(Angle=Angle)))
self.assertEqual(a, eval(repr(a), {"Angle": Angle}))

def testPickle(self):
a = Angle(1.5)
Expand Down
8 changes: 7 additions & 1 deletion tests/test_AngleIntervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@


class IntervalTests:
"""Test intervals."""

def testConstruction(self):
i = self.Interval(self.Scalar(1))
self.assertEqual(i.getA(), i.getB())
Expand Down Expand Up @@ -88,7 +90,7 @@ def testString(self):
a = self.Interval.fromRadians(0.5, 1.5)
self.assertEqual(str(a), "[0.5, 1.5]")
self.assertEqual(repr(a), self.Interval.__name__ + ".fromRadians(0.5, 1.5)")
self.assertEqual(a, eval(repr(a), dict([(self.Interval.__name__, self.Interval)])))
self.assertEqual(a, eval(repr(a), {self.Interval.__name__: self.Interval}))

def testPickle(self):
a = self.Interval.fromRadians(1, 3)
Expand All @@ -97,12 +99,16 @@ def testPickle(self):


class AngleIntervalTestCase(unittest.TestCase, IntervalTests):
"""Angle interval test cases."""

def setUp(self):
self.Interval = AngleInterval
self.Scalar = Angle


class NormalizedAngleIntervalTestCase(unittest.TestCase, IntervalTests):
"""Normalized angle interval test cases."""

def setUp(self):
self.Interval = NormalizedAngleInterval
self.Scalar = NormalizedAngle
Expand Down
8 changes: 7 additions & 1 deletion tests/test_Box.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@


class BoxTestCase(unittest.TestCase):
"""Test Box."""

def setUp(self):
np.random.seed(1)

Expand Down Expand Up @@ -171,7 +173,11 @@ def test_string(self):
b,
eval(
repr(b),
dict(AngleInterval=AngleInterval, Box=Box, NormalizedAngleInterval=NormalizedAngleInterval),
{
"AngleInterval": AngleInterval,
"Box": Box,
"NormalizedAngleInterval": NormalizedAngleInterval,
},
),
)

Expand Down
4 changes: 3 additions & 1 deletion tests/test_Box3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@


class Box3dTestCase(unittest.TestCase):
"""Test Box3d."""

def setUp(self):
np.random.seed(1)

Expand Down Expand Up @@ -140,7 +142,7 @@ def test_string(self):
repr(b),
"Box3d(Interval1d(-1.0, 1.0),\n Interval1d(-1.0, 1.0),\n Interval1d(-1.0, 1.0))",
)
self.assertEqual(b, eval(repr(b), dict(Box3d=Box3d, Interval1d=Interval1d)))
self.assertEqual(b, eval(repr(b), {"Box3d": Box3d, "Interval1d": Interval1d}))

def test_pickle(self):
a = Box3d(Vector3d(0, 0, 0), 1, 1, 1)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_Chunker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@


class ChunkerTestCase(unittest.TestCase):
"""Test Chunker."""

def testConstruction(self):
chunker = Chunker(85, 12)
self.assertEqual(chunker.numStripes, 85)
Expand All @@ -48,7 +50,7 @@ def testString(self):
chunker = Chunker(85, 12)
self.assertEqual(str(chunker), "Chunker(85, 12)")
self.assertEqual(repr(chunker), "Chunker(85, 12)")
self.assertEqual(chunker, eval(repr(chunker), dict(Chunker=Chunker)))
self.assertEqual(chunker, eval(repr(chunker), {"Chunker": Chunker}))

def testPickle(self):
a = Chunker(85, 12)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_Circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@


class CircleTestCase(unittest.TestCase):
"""Test Circle."""

def setUp(self):
np.random.seed(1)

Expand Down Expand Up @@ -152,7 +154,7 @@ def test_string(self):
c = Circle(UnitVector3d.Z(), Angle(1.0))
self.assertEqual(str(c), "Circle([0.0, 0.0, 1.0], 1.0)")
self.assertEqual(repr(c), "Circle(UnitVector3d(0.0, 0.0, 1.0), Angle(1.0))")
self.assertEqual(c, eval(repr(c), dict(Angle=Angle, Circle=Circle, UnitVector3d=UnitVector3d)))
self.assertEqual(c, eval(repr(c), {"Angle": Angle, "Circle": Circle, "UnitVector3d": UnitVector3d}))

def test_pickle(self):
a = Circle(UnitVector3d(1, -1, 1), 1.0)
Expand Down
24 changes: 14 additions & 10 deletions tests/test_CompoundRegion.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ def testString(self):
self.instance,
eval(
repr(self.instance),
dict(
UnionRegion=UnionRegion,
IntersectionRegion=IntersectionRegion,
Box=Box,
Circle=Circle,
UnitVector3d=UnitVector3d,
Angle=Angle,
AngleInterval=AngleInterval,
NormalizedAngleInterval=NormalizedAngleInterval,
),
{
"UnionRegion": UnionRegion,
"IntersectionRegion": IntersectionRegion,
"Box": Box,
"Circle": Circle,
"UnitVector3d": UnitVector3d,
"Angle": Angle,
"AngleInterval": AngleInterval,
"NormalizedAngleInterval": NormalizedAngleInterval,
},
),
)

Expand All @@ -150,6 +150,8 @@ def testYaml(self):


class UnionRegionTestCase(CompoundRegionTestMixin, unittest.TestCase):
"""Test UnionRegion."""

def setUp(self):
CompoundRegionTestMixin.setUp(self)
self.instance = UnionRegion(*self.operands)
Expand All @@ -172,6 +174,8 @@ def testRelate(self):


class IntersectionRegionTestCase(CompoundRegionTestMixin, unittest.TestCase):
"""Test intersection region."""

def setUp(self):
CompoundRegionTestMixin.setUp(self)
self.instance = IntersectionRegion(*self.operands)
Expand Down