Skip to content

Commit

Permalink
Centralize setup information (scverse#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Aug 24, 2020
1 parent c9fbe5c commit 912e7d0
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 92 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

8 changes: 8 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
version: 2
build:
image: latest
sphinx:
configuration: docs/conf.py
python:
version: 3.6
install:
- method: pip
path: .
extra_requirements:
- doc
47 changes: 24 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@ dist: xenial
language: python
matrix:
include:
- name: "static analysis"
python: "3.7"
script:
- black . --check --diff
- python -m scanpy.tests.blackdiff 10
after_success: skip
- name: "anndata dev"
python: "3.7"
install:
- pip install docutils sphinx
- pip install -e .[test,louvain,leiden,magic,scvi,harmony,skmisc]
- pip install git+https://github.com/theislab/anndata
- name: "static analysis"
python: "3.7"
install:
- pip install .[dev,doc]
script:
- black . --check --diff
- python -m scanpy.tests.blackdiff 10
- python setup.py check --restructuredtext --strict
- rst2html.py --halt=2 README.rst >/dev/null
after_success: skip
- name: "anndata dev"
python: "3.7"
install:
- pip install .[dev,test,louvain,leiden,magic,scvi,harmony,skmisc]
- pip install git+https://github.com/theislab/anndata
python:
- '3.6'
- '3.7'
#- '3.8-dev' # https://github.com/numpy/numpy/issues/13790
- '3.6'
- '3.7'
#- '3.8-dev' # https://github.com/numpy/numpy/issues/13790
cache:
- pip
- directories: data
- pip
- directories:
- data
install:
- pip install docutils sphinx
- pip install -e .[test,louvain,leiden,magic,scvi,harmony,skmisc]
- pip install .[dev,test,louvain,leiden,magic,scvi,harmony,skmisc]
env:
- MPLBACKEND=Agg
- MPLBACKEND=Agg
script:
- pytest --ignore=scanpy/tests/_images
- python setup.py check --restructuredtext --strict
- rst2html.py --halt=2 README.rst >/dev/null
- pytest --ignore=scanpy/tests/_images
6 changes: 0 additions & 6 deletions docs/requirements.txt

This file was deleted.

20 changes: 19 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
[build-system]
requires = ['setuptools', 'setuptools_scm', 'wheel']
requires = ['setuptools', 'setuptools_scm', 'wheel', 'pytoml']
build-backend = 'setuptools.build_meta'

# uses the format of tool.flit.metadata because we’ll move to it anyway
[tool.scanpy]
author = '''
Alex Wolf, Philipp Angerer, Fidel Ramirez, Isaac Virshup,
Sergei Rybakov, Gokcen Eraslan, Tom White, Malte Luecken,
Davide Cittaro, Tobias Callies, Marius Lange, Andrés R. Muñoz-Rojas
'''
# We don’t need all emails, the main authors are sufficient.
author-email = '[email protected], [email protected]'

[tool.pytest.ini_options]
python_files = 'test_*.py'
testpaths = 'scanpy/tests/'
xfail_strict = true
markers = [
'internet: tests which rely on internet resources (enable with `--internet-tests`)',
]

[tool.black]
line-length = 88
target-version = ['py36']
Expand Down
6 changes: 0 additions & 6 deletions pytest.ini

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ joblib
numba>=0.41.0
umap-learn>=0.3.10
legacy-api-wrap
setuptools_scm
packaging
sinfo
35 changes: 6 additions & 29 deletions scanpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
# some technical stuff
import sys
from ._utils import pkg_version, check_versions, annotate_doc_types
"""Single-Cell Analysis in Python."""

__author__ = ', '.join([
'Alex Wolf',
'Philipp Angerer',
'Fidel Ramirez',
'Isaac Virshup',
'Sergei Rybakov',
'Gokcen Eraslan',
'Tom White',
'Malte Luecken',
'Davide Cittaro',
'Tobias Callies',
'Marius Lange',
'Andrés R. Muñoz-Rojas',
])
__email__ = ', '.join([
'[email protected]',
'[email protected]',
# We don’t need all, the main authors are sufficient.
])
try:
from setuptools_scm import get_version
__version__ = get_version(root='..', relative_to=__file__)
del get_version
except (LookupError, ImportError):
__version__ = str(pkg_version(__name__))
from ._metadata import __version__, __author__, __email__

from ._utils import check_versions
check_versions()
del pkg_version, check_versions
del check_versions

# the actual API
from ._settings import settings, Verbosity # start with settings as several tools are using it
Expand All @@ -46,5 +21,7 @@
set_figure_params = settings.set_figure_params

# has to be done at the end, after everything has been imported
import sys
from ._utils import annotate_doc_types
annotate_doc_types(sys.modules[__name__], 'scanpy')
del sys, annotate_doc_types
18 changes: 18 additions & 0 deletions scanpy/_compat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from packaging import version

try:
from typing import Literal
except ImportError:
Expand All @@ -13,3 +15,19 @@ def __getitem__(cls, values):

class Literal(metaclass=LiteralMeta):
pass


def pkg_metadata(package):
try:
from importlib.metadata import metadata as m
except ImportError: # < Python 3.8: Use backport module
from importlib_metadata import metadata as m
return m(package)


def pkg_version(package):
try:
from importlib.metadata import version as v
except ImportError: # < Python 3.8: Use backport module
from importlib_metadata import version as v
return version.parse(v(package))
21 changes: 21 additions & 0 deletions scanpy/_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pathlib import Path

here = Path(__file__).parent

try:
from setuptools_scm import get_version
import pytoml

proj = pytoml.loads((here.parent / 'pyproject.toml').read_text())
metadata = proj['tool']['scanpy']

__version__ = get_version(root='..', relative_to=__file__)
__author__ = metadata['author']
__email__ = metadata['author-email']
except (ImportError, LookupError, FileNotFoundError):
from ._compat import pkg_metadata

metadata = pkg_metadata(here.name)
__version__ = metadata['Version']
__author__ = metadata['Author']
__email__ = metadata['Author-email']
15 changes: 4 additions & 11 deletions scanpy/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import numpy as np
from numpy import random
from scipy import sparse
from anndata import AnnData
from anndata import AnnData, __version__ as anndata_version
from textwrap import dedent
from packaging import version

Expand All @@ -36,19 +36,12 @@ class Empty(Enum):
EPS = 1e-15


def pkg_version(package):
try:
from importlib.metadata import version as v
except ImportError: # < Python 3.8: Use backport module
from importlib_metadata import version as v
return version.parse(v(package))


def check_versions():
anndata_version = pkg_version("anndata")
from ._compat import pkg_version

umap_version = pkg_version("umap-learn")

if anndata_version < version.parse('0.6.10'):
if version.parse(anndata_version) < version.parse('0.6.10'):
from . import __version__

raise ImportError(
Expand Down
2 changes: 1 addition & 1 deletion scanpy/tests/test_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import scanpy as sc
from scanpy import settings
from scanpy._utils import pkg_version
from scanpy._compat import pkg_version


X = np.array(
Expand Down
2 changes: 1 addition & 1 deletion scanpy/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from matplotlib.testing import setup
from packaging import version

from scanpy._utils import pkg_version
from scanpy._compat import pkg_version

setup()

Expand Down
5 changes: 3 additions & 2 deletions scanpy/tools/_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from anndata import AnnData

from .. import settings
from ..neighbors import _rp_forest_generate
from .. import logging as logg
from .._utils import pkg_version, NeighborsView
from ..neighbors import _rp_forest_generate
from .._utils import NeighborsView
from .._compat import pkg_version

ANNDATA_MIN_VERSION = version.parse("0.7rc1")

Expand Down
22 changes: 12 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

from setuptools import setup, find_packages


try:
from scanpy import __author__, __email__
except ImportError: # Deps not yet installed
__author__ = __email__ = ''
import pytoml
except ImportError:
sys.exit('Please use `pip install .` or install pytoml first.')

proj = pytoml.loads(Path('pyproject.toml').read_text())
metadata = proj['tool']['scanpy']

setup(
name='scanpy',
Expand All @@ -19,8 +21,8 @@
description='Single-Cell Analysis in Python.',
long_description=Path('README.rst').read_text('utf-8'),
url='http://github.com/theislab/scanpy',
author=__author__,
author_email=__email__,
author=metadata['author'],
author_email=metadata['author-email'],
license='BSD',
python_requires='>=3.6',
install_requires=[
Expand All @@ -33,11 +35,12 @@
scvi=['scvi>=0.6.5'],
rapids=['cudf>=0.9', 'cuml>=0.9', 'cugraph>=0.9'],
magic=['magic-impute>=2.0'],
skmisc=["scikit-misc>=0.1.3"],
skmisc=['scikit-misc>=0.1.3'],
harmony=['harmonypy'],
dev=['setuptools_scm', 'pytoml', 'black'],
doc=[
'sphinx',
'sphinx_rtd_theme',
'sphinx<3.1, >3',
'sphinx_rtd_theme>=0.3.1',
'sphinx_autodoc_typehints',
'scanpydoc>=0.5',
'typing_extensions; python_version < "3.8"', # for `Literal`
Expand All @@ -48,7 +51,6 @@
'fsspec',
'zappy',
'zarr',
'black',
'profimp',
],
),
Expand Down

0 comments on commit 912e7d0

Please sign in to comment.