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

FIX: Namespace packaging #42

Merged
merged 13 commits into from
Jul 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- '*'

concurrency:
group: environment-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
run: pip install .[tests]
- name: Run tests
shell: bash {0}
run: python -m pytest --pyargs bids/ext/reports --cov=bids/ext/reports
run: pytest --pyargs bids.ext.reports --doctest-modules --cov=bids.ext.reports
- name: Upload coverage to CodeCov
uses: codecov/codecov-action@v3
if: success()
2 changes: 1 addition & 1 deletion .github/workflows/testing_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- '*'

concurrency:
group: environment-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
Expand Down
6 changes: 1 addition & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repos:
- id: check-ast
- id: check-added-large-files
- id: check-case-conflict
- id: check-toml

- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
Expand Down Expand Up @@ -43,11 +44,6 @@ repos:
- id: black
args: [--config=pyproject.toml, --verbose]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
hooks:
- id: mypy
Comment on lines -46 to -49
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is this previously worked by accident. Here's what you get now:

$ mypy --explicit-package-bases bids/ext/reports
bids/ext/reports/templates/demos/python/demo.py:5: error: Module "bids" has no attribute "BIDSLayout"  [attr-defined]
bids/ext/reports/templates/demos/python/demo.py:10: error: Function is missing a return type annotation  [no-untyped-def]
bids/ext/reports/templates/demos/python/demo.py:14: error: Function is missing a type annotation  [no-untyped-def]
bids/ext/reports/templates/demos/python/demo.py:21: error: Function is missing a type annotation  [no-untyped-def]
bids/ext/reports/templates/demos/python/demo.py:39: error: Function is missing a return type annotation  [no-untyped-def]
bids/ext/reports/templates/demos/python/demo.py:39: note: Use "-> None" if function does not return a value
bids/ext/reports/utils.py:11: error: Cannot find implementation or library stub for module named "bids.layout"  [import]
bids/ext/reports/parameters.py:9: error: Cannot find implementation or library stub for module named "num2words"  [import]
bids/ext/reports/parameters.py:15: error: Cannot find implementation or library stub for module named "bids.layout"  [import]
bids/ext/reports/parameters.py:56: error: Argument 1 to "append" of "list" has incompatible type "None"; expected "int"  [arg-type]
bids/ext/reports/parameters.py:71: error: Argument 1 to "get_nb_vols" has incompatible type "List[Nifti1Image]"; expected "List[Optional[Nifti1Image]]"  [arg-type]
bids/ext/reports/parameters.py:71: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
bids/ext/reports/parameters.py:71: note: Consider using "Sequence" instead, which is covariant
bids/ext/reports/parameters.py:80: error: Argument 1 to "get_nb_vols" has incompatible type "List[Nifti1Image]"; expected "List[Optional[Nifti1Image]]"  [arg-type]
bids/ext/reports/parameters.py:80: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
bids/ext/reports/parameters.py:80: note: Consider using "Sequence" instead, which is covariant
bids/ext/reports/parsing.py:14: error: Cannot find implementation or library stub for module named "bids.layout"  [import]
bids/ext/reports/parsing.py:107: error: Module has no attribute "func_info"  [attr-defined]
bids/ext/reports/parsing.py:143: error: Module has no attribute "anat_info"  [attr-defined]
bids/ext/reports/parsing.py:174: error: Incompatible types in assignment (expression has type "int", variable has type "str")  [assignment]
bids/ext/reports/parsing.py:185: error: Module has no attribute "dwi_info"  [attr-defined]
bids/ext/reports/parsing.py:228: error: Module has no attribute "fmap_info"  [attr-defined]
bids/ext/reports/parsing.py:253: error: Module has no attribute "meg_info"  [attr-defined]
bids/ext/reports/parsing.py:362: error: Incompatible return value type (got "Optional[FileBasedImage]", expected "Optional[Nifti1Image]")  [return-value]
bids/ext/reports/report.py:14: error: Cannot find implementation or library stub for module named "bids.layout"  [import]
bids/ext/reports/cli.py:15: error: Cannot find implementation or library stub for module named "bids.layout"  [import]
bids/ext/reports/cli.py:15: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 21 errors in 6 files (checked 10 source files)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be re-added later, but fixing these issues feels out-of-scope for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally outside of the scope indeed


- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion bids/ext/reports/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from typing import Sequence

import rich
from reports import BIDSReport

from ._version import __version__
from .logger import pybids_reports_logger
from bids.ext.reports import BIDSReport
from bids.layout import BIDSLayout

# from bids.reports import BIDSReport
Expand Down
3 changes: 2 additions & 1 deletion bids/ext/reports/tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from __future__ import annotations

import pytest
from ext.reports import parameters

from bids.ext.reports import parameters


@pytest.mark.parametrize(
Expand Down
3 changes: 1 addition & 2 deletions bids/ext/reports/tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

from pathlib import Path

from ext.reports import parsing

from bids import BIDSLayout
from bids.ext.reports import parsing
from bids.tests import get_test_data_path


Expand Down
3 changes: 1 addition & 2 deletions bids/ext/reports/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from os.path import abspath
from os.path import join

from ext.reports import BIDSReport

from bids.ext.reports import BIDSReport
from bids.tests import get_test_data_path


Expand Down
4 changes: 2 additions & 2 deletions bids/ext/reports/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import json
from pathlib import Path

from ext.reports import parsing
from ext.reports import templates
from bids.ext.reports import parsing
from bids.ext.reports import templates


def test_pet():
Expand Down
24 changes: 12 additions & 12 deletions docs/source/reports.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
reports package
===============
bids.ext.reports package
========================

Module contents
---------------

.. automodule:: reports
.. automodule:: bids.ext.reports
:members:
:undoc-members:
:show-inheritance:
Expand All @@ -13,26 +13,26 @@ Module contents
Submodules
----------

reports.parameters module
-------------------------
bids.ext.reports.parameters module
----------------------------------

.. automodule:: reports.parameters
.. automodule:: bids.ext.reports.parameters
:members:
:undoc-members:
:show-inheritance:

reports.parsing module
----------------------
bids.ext.reports.parsing module
-------------------------------

.. automodule:: reports.parsing
.. automodule:: bids.ext.reports.parsing
:members:
:undoc-members:
:show-inheritance:

reports.report module
---------------------
bids.ext.reports.report module
------------------------------

.. automodule:: reports.report
.. automodule:: bids.ext.reports.report
:members:
:undoc-members:
:show-inheritance:
26 changes: 16 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ build-backend = "hatchling.build"
source = "vcs"

[tool.hatch.build.targets.wheel]
packages = ["bids/ext/reports"]

[tool.hatch.build.targets.wheel.sources]
"src" = ""
"scripts" = "mypackage/scripts"
packages = ["bids"]
only-include = ["bids/ext/reports"]
Comment on lines +9 to +10
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For your reference, this was the main issue: https://hatch.pypa.io/latest/config/build/#explicit-selection

Everything else just followed from fixing tests


[tool.hatch.build.hooks.vcs]
version-file = "bids/ext/reports/_version.py"
Expand Down Expand Up @@ -44,7 +41,7 @@ classifiers = [
dynamic = ["version"]

[project.scripts]
pybids_reports = "reports.cli:cli"
pybids_reports = "bids.ext.reports.cli:cli"

[project.urls]
Homepage = "http://github.com/bids-standard/pybids-reports"
Expand Down Expand Up @@ -101,7 +98,7 @@ exclude = '''
'''

[tool.codespell]
skip = "./.git,versioneer.py,_version.py,bids/ext/reports/tests/data/*"
skip = "./.git,bids/ext/reports/tests/data/*"
ignore-words-list = "te"

[tool.mypy]
Expand All @@ -116,8 +113,17 @@ warn_unused_ignores = true

[[tool.mypy.overrides]]
module = [
'ext.reports.tests.*',
'ext.reports._version.*',
'ext.reports.due.*',
'bids.ext.reports.tests.*',
'bids.ext.reports._version.*',
'bids.ext.reports.due.*',
]
ignore_errors = true

[tool.coverage.paths]
source = [
"bids/ext/reports",
"**/bids/ext/reports",
]

[tool.coverage.report]
include_namespace_packages = true