diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 43c4929f5..483161260 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,6 @@ jobs: - dependencies: > bandit libatomic - monkeytype pylint python3-dateutil python3-dbus-client-gen @@ -67,8 +66,6 @@ jobs: run: python --version - name: Install pyright run: pip install --user pyright - - name: Install abs2rel - run: pip install --user abs2rel - name: Run test run: ${{ matrix.task }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml deleted file mode 100644 index ed8324f15..000000000 --- a/.github/workflows/push.yml +++ /dev/null @@ -1,110 +0,0 @@ ---- -name: on push - -# yamllint disable-line rule:truthy -on: - push: - branches: [master] - - workflow_dispatch: - -jobs: - monkeytype: - runs-on: ubuntu-24.04 - container: - image: fedora:42 # CURRENT DEVELOPMENT ENVIRONMENT - # yamllint disable rule:line-length - options: --privileged --userns=host --ipc=host -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket:ro -v /usr/share/dbus-1:/usr/share/dbus-1 - steps: - - uses: dtolnay/rust-toolchain@master - with: - components: cargo - toolchain: 1.85.0 # LOWEST SUPPORTED RUST TOOLCHAIN - - name: Install dependencies for Fedora - run: > - dnf install -y - asciidoc - bandit - black - clang - cryptsetup-devel - device-mapper-devel - dbus-devel - git - glibc-static - libatomic - libblkid-devel - make - monkeytype - pip - pylint - python3-dateutil - python3-dbus-client-gen - python3-dbus-python-client-gen - python3-isort - python3-justbytes - python3-packaging - python3-psutil - python3-wcwidth - systemd-devel - - uses: actions/checkout@v6 - with: - path: stratis-cli - persist-credentials: false - - uses: stratis-storage/github-actions/github-modify@HEAD - with: - repo: stratisd - - name: Print head commit - run: git log --oneline -1 - working-directory: stratisd - - name: Overwrite stratisd dependencies as necessary - uses: stratis-storage/github-actions/stratisd-modify@HEAD - with: - working-directory: stratisd - - name: Build stratisd - run: PROFILEDIR=debug make build-all - working-directory: stratisd - - name: Install stratisd - run: PROFILEDIR=debug make install - working-directory: stratisd - - name: Workaround for D-Bus inotify - run: cp stratisd.conf /usr/share/dbus-1/system.d - working-directory: stratisd - - name: Run test - run: > - MONKEYTYPE=1 - RUST_LOG=stratisd=debug - STRATISD=/usr/libexec/stratisd - STRATIS_STRICT_POOL_FEATURES=1 - PYTHONPATH=./src - make -f Makefile all-tests - working-directory: stratis-cli - - name: Run tests without strict pool features enabled - run: > - MONKEYTYPE=1 - RUST_LOG=stratisd=debug - STRATISD=/usr/libexec/stratisd - PYTHONPATH=./src - make -f Makefile all-tests - working-directory: stratis-cli - - name: Apply annotations - run: PYTHONPATH=./src make apply - working-directory: stratis-cli - - name: Install abs2rel - run: pip install --user abs2rel - - name: Format result - run: - PATH=${PATH}:/github/home/.local/bin - make fmt - working-directory: stratis-cli - - name: Install pyright - run: pip install --user pyright - - name: Lint result - run: > - PATH=${PATH}:/github/home/.local/bin - PYTHONPATH=./src make -f Makefile lint - working-directory: stratis-cli - continue-on-error: true - - name: Diff the result - run: git diff --exit-code - working-directory: stratis-cli diff --git a/Makefile b/Makefile index 34bf7771c..6a512f90a 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,4 @@ -ifeq ($(origin MONKEYTYPE), undefined) - PYTHON = python3 -else - PYTHON = monkeytype run -endif - -ISORT_MODULES = monkeytype_config.py setup.py bin/stratis src tests - -MONKEYTYPE_MODULES = stratis_cli._actions._bind \ - stratis_cli._actions._constants \ - stratis_cli._actions._data \ - stratis_cli._actions._debug \ - stratis_cli._actions._environment \ - stratis_cli._actions._list_filesystem \ - stratis_cli._actions._logical \ - stratis_cli._actions._physical \ - stratis_cli._actions._pool \ - stratis_cli._actions._stratisd_version \ - stratis_cli._actions._stratis \ - stratis_cli._actions._top \ - stratis_cli._actions._utils \ - stratis_cli._exit \ - stratis_cli._main \ - stratis_cli._parser._debug \ - stratis_cli._parser._encryption \ - stratis_cli._parser._key \ - stratis_cli._parser._pool \ - stratis_cli._version +ISORT_MODULES = setup.py bin/stratis src tests UNITTEST_OPTS = --verbose # @@ -38,12 +11,10 @@ PYLINT_DISABLE = --disable=fixme .PHONY: lint lint: - pylint monkeytype_config.py ${PYLINT_DISABLE} pylint setup.py ${PYLINT_DISABLE} pylint bin/stratis ${PYLINT_DISABLE} pylint src/stratis_cli --disable=duplicate-code ${PYLINT_DISABLE} --ignore=_introspect.py pylint tests --disable=duplicate-code ${PYLINT_DISABLE} - bandit monkeytype_config.py ${BANDIT_SKIP} bandit setup.py ${BANDIT_SKIP} bandit bin/stratis ${BANDIT_SKIP} # Ignore B101 errors. We do not distribute optimized code, i.e., .pyo @@ -55,13 +26,11 @@ lint: .PHONY: fmt fmt: - (cd src; yes | abs2rel) isort ${ISORT_MODULES} black ./bin/stratis . .PHONY: fmt-ci fmt-ci: - (cd src; yes | abs2rel) isort --diff --check-only ${ISORT_MODULES} black ./bin/stratis . --check @@ -88,10 +57,10 @@ api-docs: sphinx-build-3 -b html api api/_build/html dbus-tests: - ${PYTHON} -m unittest discover ${UNITTEST_OPTS} --top-level-directory ./tests --start-directory ./tests/integration + python3 -m unittest discover ${UNITTEST_OPTS} --top-level-directory ./tests --start-directory ./tests/integration unit-tests: - ${PYTHON} -m unittest discover ${UNITTEST_OPTS} --start-directory ./tests/unit + python3 -m unittest discover ${UNITTEST_OPTS} --start-directory ./tests/unit .PHONY: coverage coverage: @@ -118,12 +87,3 @@ yamllint: .PHONY: package package: (umask 0022; python -m build; python -m twine check --strict ./dist/*) - -.PHONY: apply -apply: - @echo "Modules traced:" - @monkeytype list-modules - @echo "Annotating:" - @for module in ${MONKEYTYPE_MODULES}; do \ - monkeytype --verbose apply --sample-count --ignore-existing-annotations $${module} > /dev/null; \ - done diff --git a/monkeytype_config.py b/monkeytype_config.py deleted file mode 100644 index e85c5af4e..000000000 --- a/monkeytype_config.py +++ /dev/null @@ -1,95 +0,0 @@ -""" -Monkeytype Configuration File -""" - -# isort: STDLIB -import os -from types import CodeType -from typing import Any, Union - -# isort: THIRDPARTY -from monkeytype.config import DefaultConfig -from monkeytype.typing import ( - ChainedRewriter, - RemoveEmptyContainers, - RewriteConfigDict, - RewriteGenerator, - RewriteLargeUnion, - TypeRewriter, -) - - -class CanonicalizeUnionElementOrder(TypeRewriter): - """ - Monkeytype type rewriter to sort union elements in canonical order. - """ - - @staticmethod - def type_order(the_type) -> str: - """ - Return a value to be used as a key for sorting. - """ - - print(f"BIG: {the_type}", flush=True) - if the_type is Any: - return "Any" - - try: - under_name = the_type._name # pylint: disable=protected-access - except AttributeError: - under_name = None - - try: - dunder_name = the_type.__name__ - except AttributeError: - dunder_name = None - - return ( - under_name - if under_name is not None - else (dunder_name if dunder_name is not None else "") - ) - - def rewrite_Union(self, union): - return Union[ - tuple( - sorted( - list(union.__args__), - key=CanonicalizeUnionElementOrder.type_order, - ) - ) - ] - - -def _filter(code: CodeType) -> bool: - """ - Return False if information about this function should not be - recorded, otherwise return True. - """ - return not ( - all("stratis-cli" != x for x in code.co_filename.split(os.path.sep)) - or code.co_qualname == "PoolFeature._missing_" - ) - - -class MyConfig(DefaultConfig): - """ - Monkeytype configuration for this project - """ - - def code_filter(self): - return _filter - - def type_rewriter(self): - return ChainedRewriter( - ( - RemoveEmptyContainers(), - RewriteConfigDict(), - RewriteLargeUnion(), - RewriteGenerator(), - CanonicalizeUnionElementOrder(), - ) - ) - - -CONFIG = MyConfig()