Skip to content

Commit

Permalink
Merge pull request #1684 from ivirshup/precommit
Browse files Browse the repository at this point in the history
Pre-commit
  • Loading branch information
ivirshup committed Feb 24, 2021
2 parents 1f1f6d5 + d654852 commit 5db49c2
Show file tree
Hide file tree
Showing 41 changed files with 1,792 additions and 1,104 deletions.
6 changes: 0 additions & 6 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ jobs:
pip list
displayName: 'Display installed versions'
- script: |
pip install black
black . --check --diff
python -m scanpy.tests.blackdiff 10
displayName: 'Black'
- script: |
pytest --color=yes --ignore=scanpy/tests/_images --nunit-xml="nunit/test-results.xml"
displayName: 'PyTest'
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.0
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/python/black
rev: 20.8b1
hooks:
- id: black
22 changes: 22 additions & 0 deletions docs/dev/getting-set-up.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ To do this manually, first make a fork of the repository by clicking the "fork"
git remote add upstream https://github.com/theislab/scanpy.git
# git branch --set-upstream-to "upstream/master"
`pre-commit`
~~~~~~~~~~~~

We use `precommit <https://pre-commit.com>`__ to run some styling checks in an automated way.
We also test against these checks, so make sure you follow them!

You can install pre-commit with:

.. code:: shell
pip install pre-commit
You can then install it to run while developing here with:

.. code:: shell
pre-commit install
From the root of the repo.

If you choose not to run the hooks on each commit, you can run them manually with `pre-commit run --files={your files}`.

.. _creating-a-branch:

Creating a branch for your feature
Expand Down
46 changes: 1 addition & 45 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,4 @@ target-version = ['py36']
skip-string-normalization = true
exclude = '''
/build/.*
|/scanpy/(
get
|__init__
|logging
|_utils
|neighbors/__init__
|external/(exporting|tl/_palantir)
|preprocessing/(
_qc
|_simple
|_normalization
|_highly_variable_genes
|_deprecated/highly_variable_genes
)
|tools/(
_dpt
|_sim
|_paga
|_umap
|_utils
|_louvain
|_tsne_fix
|_top_genes
|_score_genes
|_utils_clustering
|_rank_genes_groups
)
|plotting/(
__init__
|palettes
|_tools/(__init__|paga)
)
|tests/(
test_get
|test_neighbors
|test_readwrite
|test_clustering
|test_preprocessing
|test_rank_genes_groups
|test_marker_gene_overlap
|test_highly_variable_genes
|test_rank_genes_groups_logreg
|notebooks/(test_paga_paul15_subsampled|test_pbmc3k)
)
).py'''
'''
19 changes: 17 additions & 2 deletions scanpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,41 @@
from ._metadata import __version__, __author__, __email__

from ._utils import check_versions

check_versions()
del check_versions

# the actual API
from ._settings import settings, Verbosity # start with settings as several tools are using it
from ._settings import (
settings,
Verbosity,
) # start with settings as several tools are using it
from . import tools as tl
from . import preprocessing as pp
from . import plotting as pl
from . import datasets, logging, queries, external, get

from anndata import AnnData, concat
from anndata import read_h5ad, read_csv, read_excel, read_hdf, read_loom, read_mtx, read_text, read_umi_tools
from anndata import (
read_h5ad,
read_csv,
read_excel,
read_hdf,
read_loom,
read_mtx,
read_text,
read_umi_tools,
)
from .readwrite import read, read_10x_h5, read_10x_mtx, write, read_visium
from .neighbors import Neighbors

set_figure_params = settings.set_figure_params

# has to be done at the end, after everything has been imported
import sys

sys.modules.update({f'{__name__}.{m}': globals()[m] for m in ['tl', 'pp', 'pl']})
from ._utils import annotate_doc_types

annotate_doc_types(sys.modules[__name__], 'scanpy')
del sys, annotate_doc_types
17 changes: 10 additions & 7 deletions scanpy/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ def sanitize_anndata(adata):
def view_to_actual(adata):
if adata.is_view:
warnings.warn(
"Revieved a view of an AnnData. Making a copy.", stacklevel=2,
"Revieved a view of an AnnData. Making a copy.",
stacklevel=2,
)
adata._init_as_actual(adata.copy())

Expand Down Expand Up @@ -432,7 +433,9 @@ def moving_average(a: np.ndarray, n: int):


def update_params(
old_params: Mapping[str, Any], new_params: Mapping[str, Any], check=False,
old_params: Mapping[str, Any],
new_params: Mapping[str, Any],
check=False,
) -> Dict[str, Any]:
"""\
Update old_params with new_params.
Expand Down Expand Up @@ -474,8 +477,7 @@ def update_params(


def check_nonnegative_integers(X: Union[np.ndarray, sparse.spmatrix]):
"""Checks values of X to ensure it is count data
"""
"""Checks values of X to ensure it is count data"""
from numbers import Integral

data = X if isinstance(X, np.ndarray) else X.data
Expand All @@ -492,8 +494,7 @@ def check_nonnegative_integers(X: Union[np.ndarray, sparse.spmatrix]):


def select_groups(adata, groups_order_subset='all', key='groups'):
"""Get subset of groups in adata.obs[key].
"""
"""Get subset of groups in adata.obs[key]."""
groups_order = adata.obs[key].cat.categories
if key + '_masks' in adata.uns:
groups_masks = adata.uns[key + '_masks']
Expand Down Expand Up @@ -555,7 +556,9 @@ def warn_with_traceback(message, category, filename, lineno, file=None, line=Non


def subsample(
X: np.ndarray, subsample: int = 1, seed: int = 0,
X: np.ndarray,
subsample: int = 1,
seed: int = 0,
) -> Tuple[np.ndarray, np.ndarray]:
"""\
Subsample a fraction of 1/subsample samples from the rows of X.
Expand Down
Loading

0 comments on commit 5db49c2

Please sign in to comment.