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

Lint setup fix #122

Merged
merged 12 commits into from
Jun 13, 2022
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
51 changes: 15 additions & 36 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,28 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Copy link
Member

Choose a reason for hiding this comment

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

It's good practice to run this to make sure the latest version of pip is being used - was it causing issues?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought it was this line that was entering the endless loop of non-resolvable pip version search, but maybe it was actually one of the docgen packages that I now removed as dev deps. I'll try to put this line back, thanks for the tip!

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I'll just try to emulate the structure of the imio repo as per @adamltyson suggestion

pip install .[dev]
- name: Lint
run: |
black ./ --check
flake8
- uses: brainglobe/actions/lint@v1

test:
needs: lint
name: ${{ matrix.os }} py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.7, 3.8]
exclude:
- os: macos-latest
python-version: 3.7
- os: windows-latest
python-version: 3.7
# Run all supported Python versions on linux
python-version: ["3.7", "3.8", "3.9"]
os: [ubuntu-latest]
# Include one windows and macos run
include:
- os: macos-latest
python-version: "3.9"
- os: windows-latest
python-version: "3.9"

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- uses: brainglobe/actions/test@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Test
run: pytest
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pip install coveralls
coveralls --service=github

deploy:
needs: test
Expand All @@ -59,7 +38,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: "3.7"
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ venv/
ENV/
env.bak/
venv.bak/
.envrc

# Spyder project settings
.spyderproject
Expand Down
47 changes: 35 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
repos:
- repo: https://github.com/python/black
rev: 20.8b1
hooks:
- id: black
pass_filenames: true
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
pass_filenames: true
# this seems to need to be here in addition to setup.cfg
exclude: __init__.py
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
types: [text]
types_or: [python, cython]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-toml
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: requirements-txt-fixer
- id: trailing-whitespace
# bump2version produces whitespace in setup.cfg, so exclude to
# not inferfere with versioning
exclude: setup.cfg
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.961
hooks:
- id: mypy
additional_dependencies:
- types-requests
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
![banner](https://github.com/brainglobe/bg-atlasapi/blob/master/docs/img/banner.jpeg)


The brainglobe atlas API (BG-AtlasAPI) provides a common interface for programmers to download and process brain atlas data from multiple sources.
The brainglobe atlas API (BG-AtlasAPI) provides a common interface for programmers to download and process brain atlas data from multiple sources.

## Atlases available

Expand Down Expand Up @@ -44,7 +44,7 @@ To see a list of atlases use `bg_atlasapi.show_atlases`
```python
from bg_atlasapi import show_atlases
show_atlases()
# Brainglobe Atlases
# Brainglobe Atlases
# ╭──────────────────────────────────┬────────────┬───────────────┬──────────────╮
# │ Name │ Downloaded │ Local version │ Latest │
# │ │ │ │ version │
Expand All @@ -61,7 +61,7 @@ show_atlases()

**Using the atlases**

All the features of each atlas can be accessed via the `BrainGlobeAtlas` class.
All the features of each atlas can be accessed via the `BrainGlobeAtlas` class.


e.g. for the 25um Allen Mouse Brain Atlas:
Expand Down Expand Up @@ -119,7 +119,7 @@ pprint(VISp)
# 'structure_id_path': [997, 8, 567, 688, 695, 315, 669, 385]}
```

### Note on coordinates in `bg-atlasapi`
### Note on coordinates in `bg-atlasapi`
Working with both image coordinates and cartesian coordinates in the same space can be confusing! In `bg-atlasapi`, the origin is always assumed to be in the upper left corner of the image (sectioning along the first dimension), the "ij" convention. This means that when plotting meshes and points using cartesian systems, you might encounter confusing behaviors coming from the fact that in cartesian plots one axis is inverted with respect to ij coordinates (vertical axis increases going up, image row indexes increase going down). To make things as consistent as possible, in `bg-atlasapi` the 0 of the meshes coordinates is assumed to coincide with the 0 index of the images stack, and meshes coordinates increase following the direction stack indexes increase.
To deal with transformations between your data space and `bg-atlasapi`, you might find helpful the [bg-space](https://github.com/brainglobe/bg-space) package.

Expand All @@ -134,4 +134,3 @@ Someone might have already asked a question you might have, so if you're not sur
The BrainGlobe project is generously supported by the Sainsbury Wellcome Centre and the Institute of Neuroscience, Technical University of Munich, with funding from Wellcome, the Gatsby Charitable Foundation and the Munich Cluster for Systems Neurology - Synergy.

<img src='https://brainglobe.info/images/logos_combined.png' width="550">

11 changes: 5 additions & 6 deletions bg_atlasapi/bg_atlas.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from pathlib import Path
import tarfile
from io import StringIO
from pathlib import Path

import requests
from rich import print as rprint
from rich.console import Console
from io import StringIO
from bg_atlasapi.utils import _rich_atlas_metadata


from bg_atlasapi import utils, config, core, descriptors

from bg_atlasapi import config, core, descriptors, utils
from bg_atlasapi.utils import _rich_atlas_metadata

COMPRESSED_FILENAME = "atlas.tar.gz"

Expand Down
7 changes: 4 additions & 3 deletions bg_atlasapi/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from bg_atlasapi.list_atlases import show_atlases
from bg_atlasapi.update_atlases import update_atlas, install_atlas
from bg_atlasapi.config import cli_modify_config
import click

from bg_atlasapi.config import cli_modify_config
from bg_atlasapi.list_atlases import show_atlases
from bg_atlasapi.update_atlases import install_atlas, update_atlas


@click.command()
@click.argument("command")
Expand Down
3 changes: 2 additions & 1 deletion bg_atlasapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
BRAINGLOBE_CONFIG_DIR.
"""

import os
import configparser
import os
from pathlib import Path

import click

CONFIG_FILENAME = "bg_config.conf"
Expand Down
18 changes: 9 additions & 9 deletions bg_atlasapi/core.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from pathlib import Path
import pandas as pd
import numpy as np
from collections import UserDict
import warnings
from collections import UserDict
from pathlib import Path

import numpy as np
import pandas as pd
from bg_space import AnatomicalSpace

from bg_atlasapi.utils import read_json, read_tiff
from bg_atlasapi.structure_class import StructuresDict
from bg_atlasapi.descriptors import (
METADATA_FILENAME,
STRUCTURES_FILENAME,
REFERENCE_FILENAME,
ANNOTATION_FILENAME,
HEMISPHERES_FILENAME,
MESHES_DIRNAME,
METADATA_FILENAME,
REFERENCE_FILENAME,
STRUCTURES_FILENAME,
)
from bg_atlasapi.structure_class import StructuresDict
from bg_atlasapi.utils import read_json, read_tiff


class Atlas:
Expand Down
13 changes: 6 additions & 7 deletions bg_atlasapi/list_atlases.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from rich.table import Table
from rich import print as rprint
from rich.panel import Panel

from bg_atlasapi import config, utils, descriptors


"""
Some functionality to list all available and downloaded brainglobe atlases
"""

from rich import print as rprint
from rich.panel import Panel
from rich.table import Table

from bg_atlasapi import config, descriptors, utils


def get_downloaded_atlases():
"""Get a list of all the downloaded atlases and their version.
Expand Down
5 changes: 3 additions & 2 deletions bg_atlasapi/structure_class.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import meshio as mio
from collections import UserDict
import warnings
from collections import UserDict

import meshio as mio

from bg_atlasapi.structure_tree_util import get_structures_tree

Expand Down
3 changes: 2 additions & 1 deletion bg_atlasapi/update_atlases.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rich import print as rprint
import shutil

from rich import print as rprint

from bg_atlasapi.bg_atlas import BrainGlobeAtlas, _version_str_from_tuple
from bg_atlasapi.list_atlases import get_downloaded_atlases

Expand Down
15 changes: 8 additions & 7 deletions bg_atlasapi/utils.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import configparser
import json
import tifffile
import requests
import logging
import configparser

import requests
import tifffile
from rich.panel import Panel
from rich.pretty import Pretty
from rich.progress import (
BarColumn,
DownloadColumn,
Progress,
TextColumn,
TransferSpeedColumn,
TimeRemainingColumn,
Progress,
TransferSpeedColumn,
)
from rich.table import Table
from rich.panel import Panel
from rich.pretty import Pretty
from rich.text import Text

logging.getLogger("urllib3").setLevel(logging.WARNING)
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ exclude = '''
| examples
)/
)
'''
'''

[tool.isort]
multi_line_output = 3
include_trailing_comma = true
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[pytest]
addopts = --cov=bg_atlasapi
addopts = --cov=bg_atlasapi
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
bg-space>=0.5.0
click
meshio
numpy
tifffile
treelib
pandas
requests
meshio
click
rich>=9.0.0
bg-space>=0.5.0
tifffile
treelib
16 changes: 7 additions & 9 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
sphinx
sphinx_rtd_theme
pydoc-markdown
pytest-cov
pytest
gitpython
coverage
pre-commit
black
flake8
coverage
flake8
gitpython
isort
pre - commit
pytest
pytest - cov
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, find_namespace_packages
from setuptools import find_namespace_packages, setup

with open("requirements.txt") as f:
requirements = f.read().splitlines()
Expand Down
8 changes: 5 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pytest
from bg_atlasapi.bg_atlas import BrainGlobeAtlas
import tempfile
import shutil
import tempfile
from pathlib import Path

import pytest

from bg_atlasapi.bg_atlas import BrainGlobeAtlas


@pytest.fixture()
def atlas():
Expand Down
Loading