Skip to content

Commit

Permalink
Merge pull request #110 from seequent/LF-55044-add-pre-commit-and-cop…
Browse files Browse the repository at this point in the history
…yrights

LF-55044 Add pre-commit hooks for linting and Bentley copyrights
  • Loading branch information
loganbeard-seequent authored Oct 29, 2024
2 parents 588ef6e + 1b34131 commit 04d784a
Show file tree
Hide file tree
Showing 33 changed files with 193 additions and 46 deletions.
52 changes: 26 additions & 26 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
name: pre-commit

on:
push:
branches:
- master

pull_request:
branches:
- master

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Run pre-commit
uses: pre-commit/[email protected]
name: pre-commit

on:
push:
branches:
- master

pull_request:
branches:
- master

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Run pre-commit
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
30 changes: 16 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-toml
- id: trailing-whitespace
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-toml
- id: check-yaml

- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
language_version: python3.10
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
language_version: python3.10

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
6 changes: 5 additions & 1 deletion pure_interface/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

from ._sub_interface import sub_interface_of
from .adaption import AdapterTracker, adapt_args, adapts, register_adapter
from .delegation import Delegate
Expand All @@ -15,4 +19,4 @@
type_is_interface,
)

__version__ = "8.0.2"
__version__ = "8.0.3" # Don't change this manually - run `bump-my-version bump [major|minor|patch]` instead
4 changes: 4 additions & 0 deletions pure_interface/_sub_interface.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

""" decorator function for sub-interfaces
A sub-interface is a non-empty subset of another, larger, interface.
Expand Down
4 changes: 4 additions & 0 deletions pure_interface/adaption.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

from __future__ import absolute_import, division, print_function

import functools
Expand Down
4 changes: 4 additions & 0 deletions pure_interface/delegation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

from __future__ import absolute_import, division, print_function

import operator
Expand Down
5 changes: 5 additions & 0 deletions pure_interface/errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------


class PureInterfaceError(Exception):
"""All exceptions raised by this module are subclasses of this exception"""

Expand Down
4 changes: 4 additions & 0 deletions pure_interface/interface.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

"""
pure_interface enforces empty functions and properties on interfaces and provides adaption and structural type checking.
"""
Expand Down
4 changes: 4 additions & 0 deletions pure_interface/mypy_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

from collections.abc import Callable
from typing import Dict, Final, List, Optional, TypeAlias, cast

Expand Down
35 changes: 31 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pure-interface"
dynamic = ["version"]
version = "8.0.3"
description = "A Python interface library that disallows function body content on interfaces and supports adaption."
keywords = ["interface", "protocol", "adaption", "structural", "dataclass"]
authors = [
Expand Down Expand Up @@ -33,9 +33,6 @@ typing = ['mypy']
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic]
version = {attr = "pure_interface.__version__"}

[tool.mypy]
plugins = "pure_interface/mypy_plugin.py"

Expand All @@ -44,3 +41,33 @@ line-length = 120

[tool.isort]
profile = "black"

[tool.bumpversion]
current_version = "8.0.3"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"
replace = "{new_version}"
regex = false
ignore_missing_version = false
ignore_missing_files = false
tag = true
sign_tags = false
tag_name = "v{new_version}"
tag_message = "Bump version: {current_version} → {new_version}"
allow_dirty = false
commit = true
message = "Bump version: {current_version} → {new_version}"
setup_hooks = []
pre_commit_hooks = []
post_commit_hooks = []

[[tool.bumpversion.files]]
filename = "pyproject.toml"
search = 'version = "{current_version}"'
replace = 'version = "{new_version}"'

[[tool.bumpversion.files]]
filename = "pure_interface/__init__.py"
search = '__version__ = "{current_version}"'
replace = '__version__ = "{new_version}"'
3 changes: 2 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
-r requirements.txt
bump-my-version==0.26.0
mypy
pre-commit==3.8.0
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import warnings

warnings.filterwarnings("ignore", category=UserWarning)
4 changes: 4 additions & 0 deletions tests/interface_module.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import pure_interface


Expand Down
4 changes: 4 additions & 0 deletions tests/mypy_source.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

"""With the pure-interface mypy plugin enabled, mypy should validate this file without error.
This is working except for dataclasses __init__ call arguments.
Expand Down
4 changes: 4 additions & 0 deletions tests/temp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import dataclasses

import pure_interface
Expand Down
4 changes: 4 additions & 0 deletions tests/test_adapt_args_anno.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import unittest

try:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_adapt_args_no_anno.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import unittest

import pure_interface.errors
Expand Down
4 changes: 4 additions & 0 deletions tests/test_adaption.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import unittest
import warnings
from unittest import mock
Expand Down
4 changes: 4 additions & 0 deletions tests/test_dataclass_support.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import unittest
from dataclasses import dataclass

Expand Down
4 changes: 4 additions & 0 deletions tests/test_delegate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import dataclasses
import unittest
from unittest import mock
Expand Down
4 changes: 4 additions & 0 deletions tests/test_func_sigs3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import types
import unittest

Expand Down
4 changes: 4 additions & 0 deletions tests/test_func_sigs_po.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals

Expand Down
4 changes: 4 additions & 0 deletions tests/test_function_sigs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import types
import unittest

Expand Down
4 changes: 4 additions & 0 deletions tests/test_generic_support.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import unittest
from typing import Iterable, List, TypeVar

Expand Down
4 changes: 4 additions & 0 deletions tests/test_implementation_checks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import abc
import unittest
import warnings
Expand Down
4 changes: 4 additions & 0 deletions tests/test_inheritance.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import unittest

import pure_interface
Expand Down
4 changes: 4 additions & 0 deletions tests/test_isinstance.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import io
import unittest
import warnings
Expand Down
4 changes: 4 additions & 0 deletions tests/test_meta_classes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import abc
import unittest

Expand Down
4 changes: 4 additions & 0 deletions tests/test_module_funcs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import unittest

from pure_interface import *
Expand Down
4 changes: 4 additions & 0 deletions tests/test_no_content_checks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import abc
import unittest

Expand Down
4 changes: 4 additions & 0 deletions tests/test_singledispatch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import unittest
from functools import singledispatchmethod
from typing import Any
Expand Down
4 changes: 4 additions & 0 deletions tests/test_sub_interfaces.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import dataclasses
import unittest

Expand Down
4 changes: 4 additions & 0 deletions tests/test_tracker.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) 2024 Bentley Systems, Incorporated. All rights reserved.
# --------------------------------------------------------------------------------------------

import unittest

from pure_interface import *
Expand Down

0 comments on commit 04d784a

Please sign in to comment.