Skip to content

Commit

Permalink
blacken everything without too many line changes (scverse#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Sep 14, 2019
1 parent be420bc commit 178a098
Show file tree
Hide file tree
Showing 33 changed files with 321 additions and 83 deletions.
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
dist: xenial
language: python
stages:
- name: static analysis
- name: test
python:
- '3.6'
- '3.7'
#- '3.8-dev' # https://github.com/numpy/numpy/issues/13790
cache:
cache:
- pip
- directories: data
install:
Expand All @@ -16,3 +19,11 @@ script:
- pytest --ignore=scanpy/tests/_images
- python setup.py check --restructuredtext --strict
- rst2html.py --halt=2 README.rst >/dev/null
jobs:
include:
- stage: static analysis
python: "3.7"
script:
- black . --check --diff
- python -m scanpy.tests.blackdiff 10
after_success: skip
6 changes: 4 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ def pytest_addoption(parser):

def pytest_collection_modifyitems(config, items):
run_internet = config.getoption("--internet-tests")
skip_internet = pytest.mark.skip(reason="need --internet-tests option to run")
skip_internet = pytest.mark.skip(
reason="need --internet-tests option to run"
)
for item in items:
# All tests marked with `pytest.mark.internet` get skipped unless
# `--run-internet` passed
if not run_internet and ("internet" in item.keywords):
item.add_marker(skip_internet)
item.add_marker(skip_internet)
87 changes: 62 additions & 25 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from datetime import datetime

import matplotlib # noqa

# Don’t use tkinter agg when importing scanpy → … → matplotlib
matplotlib.use('agg')

HERE = Path(__file__).parent
sys.path.insert(0, str(HERE.parent))
import scanpy # noqa

with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=FutureWarning)
import scanpy.api
Expand Down Expand Up @@ -83,7 +85,10 @@
scvelo=('https://scvelo.readthedocs.io/en/stable/', None),
seaborn=('https://seaborn.pydata.org/', None),
sklearn=('https://scikit-learn.org/stable/', None),
scanpy_tutorials=('https://scanpy-tutorials.readthedocs.io/en/latest', None),
scanpy_tutorials=(
'https://scanpy-tutorials.readthedocs.io/en/latest',
None,
),
)


Expand All @@ -92,20 +97,21 @@

html_theme = 'sphinx_rtd_theme'
html_theme_options = dict(
navigation_depth=4,
logo_only=True, # Only show the logo
navigation_depth=4, logo_only=True # Only show the logo
)
html_context = dict(
display_github=True, # Integrate GitHub
github_user='theislab', # Username
github_repo='scanpy', # Repo name
display_github=True, # Integrate GitHub
github_user='theislab', # Username
github_repo='scanpy', # Repo name
github_version='master', # Version
conf_py_path='/docs/', # Path in the checkout to the docs root
conf_py_path='/docs/', # Path in the checkout to the docs root
)
html_static_path = ['_static']
html_show_sphinx = False
html_logo = '_static/img/Scanpy_Logo_RGB.png'
gh_url = 'https://github.com/{github_user}/{github_repo}'.format_map(html_context)
gh_url = 'https://github.com/{github_user}/{github_repo}'.format_map(
html_context
)


def setup(app):
Expand All @@ -115,19 +121,24 @@ def setup(app):
app.connect('build-finished', show_param_warnings)
app.add_role('pr', autolink(f'{gh_url}/pull/{{}}', 'PR {}'))


# -- Options for other output formats ------------------------------------------


htmlhelp_basename = f'{project}doc'
doc_title = f'{project} Documentation'
latex_documents = [
(master_doc, f'{project}.tex', doc_title, author, 'manual'),
]
man_pages = [
(master_doc, project, doc_title, [author], 1)
]
latex_documents = [(master_doc, f'{project}.tex', doc_title, author, 'manual')]
man_pages = [(master_doc, project, doc_title, [author], 1)]
texinfo_documents = [
(master_doc, project, doc_title, author, project, 'One line description of project.', 'Miscellaneous'),
(
master_doc,
project,
doc_title,
author,
project,
'One line description of project.',
'Miscellaneous',
)
]


Expand All @@ -136,20 +147,28 @@ def setup(app):

def insert_function_images(app, what, name, obj, options, lines):
path = Path(__file__).parent / 'api' / f'{name}.png'
if what != 'function' or not path.is_file(): return
lines[0:0] = [f'.. image:: {path.name}', ' :width: 200', ' :align: right', '']
if what != 'function' or not path.is_file():
return
lines[0:0] = [
f'.. image:: {path.name}',
' :width: 200',
' :align: right',
'',
]


# -- GitHub links --------------------------------------------------------------


def autolink(url_template, title_template='{}'):
from docutils import nodes

def role(name, rawtext, text, lineno, inliner, options={}, content=[]):
url = url_template.format(text)
title = title_template.format(text)
node = nodes.reference(rawtext, title, refuri=url, **options)
return [node], []

return role


Expand All @@ -171,7 +190,9 @@ def process_return(lines):


def scanpy_parse_returns_section(self, section):
lines_raw = list(process_return(self._dedent(self._consume_to_next_section())))
lines_raw = list(
process_return(self._dedent(self._consume_to_next_section()))
)
lines = self._format_block(':returns: ', lines_raw)
if lines and lines[-1]:
lines.append('')
Expand All @@ -190,15 +211,20 @@ def scanpy_parse_returns_section(self, section):

def scanpy_log_param_types(self, fields, field_role='param', type_role='type'):
for _name, _type, _desc in fields:
if not _type: continue
if not _type:
continue
set_item = r"`'[a-z0-9_.-]+'`"
if re.fullmatch(rf"{{{set_item}(, {set_item})*}}", _type): continue
param_warnings.setdefault((self._name, self._obj), []).append((_name, _type))
if re.fullmatch(rf"{{{set_item}(, {set_item})*}}", _type):
continue
param_warnings.setdefault((self._name, self._obj), []).append(
(_name, _type)
)
return _format_docutils_params_orig(self, fields, field_role, type_role)


def show_param_warnings(app, exception):
import inspect

for (fname, fun), params in param_warnings.items():
_, line = inspect.getsourcelines(fun)
file_name = inspect.getsourcefile(fun)
Expand All @@ -207,7 +233,9 @@ def show_param_warnings(app, exception):
f'\nParameters in `{fname}` not set-like: {{`elm-1`, `s_el.2`}}.\n'
'Convert to this format or replace with type annotations:\n'
+ params_str,
UserWarning, file_name, line,
UserWarning,
file_name,
line,
)


Expand All @@ -220,19 +248,23 @@ def show_param_warnings(app, exception):
# Just do the following to see the rst of a function:
# rm -f _build/doctrees/api/scanpy.<what_you_want>.doctree; DEBUG=1 make html
import os

if os.environ.get('DEBUG') is not None:
import sphinx.ext.napoleon

pd = sphinx.ext.napoleon._process_docstring

def pd_new(app, what, name, obj, options, lines):
pd(app, what, name, obj, options, lines)
print(*lines, sep='\n')

sphinx.ext.napoleon._process_docstring = pd_new


# -- Suppress link warnings ----------------------------------------------------

qualname_overrides = {
"sklearn.neighbors.dist_metrics.DistanceMetric": "sklearn.neighbors.DistanceMetric",
"sklearn.neighbors.dist_metrics.DistanceMetric": "sklearn.neighbors.DistanceMetric"
}

nitpick_ignore = [
Expand All @@ -243,8 +275,13 @@ def pd_new(app, what, name, obj, options, lines):
]

for mod_name in [
'pp', 'tl', 'pl',
'queries', 'logging', 'datasets', 'export_to',
'pp',
'tl',
'pl',
'queries',
'logging',
'datasets',
'export_to',
None,
]:
if mod_name is None:
Expand Down
77 changes: 77 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
[build-system]
requires = ['setuptools', 'setuptools_scm', 'wheel']
build-backend = 'setuptools.build_meta'

[tool.black]
line-length = 80
target-version = ['py36']
skip-string-normalization = true
exclude = '''
/build/.*
|/scanpy/(
get
|__init__
|cli
|logging
|readwrite
|_utils
|_settings
|neighbors/__init__
|api/(__init__|pp|pl|datasets)
|external/(exporting|tl/_palantir)
|datasets/(__init__|_ebi_expression_atlas)
|preprocessing/(
__init__
|_qc
|_combat
|_simple
|_recipes
|_normalization
|_highly_variable_genes
|_deprecated/highly_variable_genes
)
|tools/(
_dpt
|_sim
|_paga
|_tsne
|_umap
|_utils
|_leiden
|_louvain
|_tsne_fix
|_top_genes
|_dendrogram
|_draw_graph
|_score_genes
|_utils_clustering
|_rank_genes_groups
|_embedding_density
|_marker_gene_overlap
)
|plotting/(
__init__
|palettes
|_anndata
|_utils
|_preprocessing
|_tools/(scatterplots|__init__|paga)
)
|tests/(
test_get
|test_pca
|test_docs
|test_binary
|test_combat
|test_plotting
|test_read_10x
|test_neighbors
|test_readwrite
|test_clustering
|test_qc_metrics
|test_score_genes
|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'''
1 change: 1 addition & 0 deletions scanpy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .cli import console_main

console_main()
7 changes: 6 additions & 1 deletion scanpy/api/tl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from ..tools._diffmap import diffmap
from ..tools._draw_graph import draw_graph

from ..tools._paga import paga, paga_degrees, paga_expression_entropies, paga_compare_paths
from ..tools._paga import (
paga,
paga_degrees,
paga_expression_entropies,
paga_compare_paths,
)
from ..tools._rank_genes_groups import rank_genes_groups
from ..tools._dpt import dpt
from ..tools._leiden import leiden
Expand Down
1 change: 1 addition & 0 deletions scanpy/external/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import sys
from .. import _utils

_utils.annotate_doc_types(sys.modules[__name__], 'scanpy')
del sys, _utils

Expand Down
2 changes: 1 addition & 1 deletion scanpy/external/pp/_bbknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def bbknn(
trim: Optional[int] = None,
n_trees: int = 10,
use_faiss: bool = True,
set_op_mix_ratio: float = 1.,
set_op_mix_ratio: float = 1.0,
local_connectivity: int = 1,
**kwargs,
) -> AnnData:
Expand Down
6 changes: 4 additions & 2 deletions scanpy/external/pp/_dca.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def dca(
log1p=True,
# network args
hidden_size=(64, 32, 64),
hidden_dropout=0.,
hidden_dropout=0.0,
batchnorm=True,
activation='relu',
init='glorot_uniform',
Expand Down Expand Up @@ -138,7 +138,9 @@ def dca(
try:
from dca.api import dca
except ImportError:
raise ImportError('Please install dca package (>= 0.2.1) via `pip install dca`')
raise ImportError(
'Please install dca package (>= 0.2.1) via `pip install dca`'
)

return dca(
adata,
Expand Down
5 changes: 3 additions & 2 deletions scanpy/external/pp/_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ def magic(
time=start,
deep=(
"added\n 'X_magic', PCA on MAGIC coordinates (adata.obsm)"
if name_list == "pca_only" else ''
)
if name_list == "pca_only"
else ''
),
)
# update AnnData instance
if name_list == "pca_only":
Expand Down
Loading

0 comments on commit 178a098

Please sign in to comment.