Skip to content

Commit

Permalink
Merge pull request #180 from icbi-lab/improve-packaging2
Browse files Browse the repository at this point in the history
Improve packaging
  • Loading branch information
grst authored Aug 26, 2020
2 parents 664bb54 + 1c2becd commit 358cff1
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 84 deletions.
27 changes: 8 additions & 19 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,16 @@ build:

requirements:
# The way the version is resolved from SCM (flit + get_version)
# requires all dependencies to be installed at build time.
# requires all dependencies to be installed at build time.
host:
- python >=3.6
- flit
- get_version
- anndata >=0.7.3
- scanpy>=1.5.1
- pandas>=0.21
- numpy=1.18
- scipy
- parasail-python
- scikit-learn
- python-levenshtein
- python-igraph
- networkx
- squarify
- tqdm>=4.29.1
- airr>=1.2
- setuptools_scm
- pytoml
- importlib_metadata

run:
- python >=3.6
- get_version
- anndata >=0.7.3
- scanpy>=1.5.1
- pandas>=0.21
Expand Down Expand Up @@ -71,11 +60,11 @@ test:

about:
home: https://icbi-lab.github.io/scirpy
dev_url: https://github.com/icbi-lab/scirpy
dev_url: https://github.com/icbi-lab/scirpy
license: BSD-3
license_family: BSD
summary: A Scanpy extension for analyzing single-cell T-cell receptor sequencing data.
summary: A Scanpy extension for analyzing single-cell T-cell receptor sequencing data.

extra:
identifiers:
- doi:10.1101/2020.04.10.035865
- doi:10.1101/2020.04.10.035865
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 88

[*.py]
indent_size = 4
indent_style = space

[Makefile]
indent_style = tab
19 changes: 11 additions & 8 deletions .github/workflows/conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,37 @@ on:
branches: [master]
pull_request:
branches: [master]

jobs:
tests:
runs-on: ${{ matrix.os }}
name: conda ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8]
os: ["ubuntu-latest", "macos-latest"]

steps:
- uses: actions/checkout@v2

- name: Setup Minoconda
with:
fetch-depth: 0 # required for setuptools-scm

- name: Setup Minoconda
uses: goanpeca/setup-miniconda@v1
with:
auto-update-conda: true

python-version: ${{ matrix.python-version }}

- name: Set-up channels and install conda build
run: |
conda config --add channels defaults
conda config --add channels bioconda
conda config --add channels conda-forge
conda install -y conda-build conda-verify
shell: bash

- name: build and test package
run: |
cd .conda
conda build . --no-anaconda-upload
conda build --no-anaconda-upload .
shell: bash
9 changes: 4 additions & 5 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # required for setuptools-scm
- name: Fetch all tags s.t. get_version can retrieve the correct version.
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

Expand Down Expand Up @@ -64,11 +66,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install flit
flit install --deps develop
env:
FLIT_ROOT_INSTALL: 1

pip install .[doc,test,rpack]
- name: run sphinx
run: |
cd docs && make html SPHINXOPTS="-W --keep-going"
Expand Down Expand Up @@ -101,3 +99,4 @@ jobs:
TARGET_FOLDER: ${{ env.target_dir }}
CLEAN: true
CLEAN_EXCLUDE: '["heads", "pull", "tags"]'
SINGLE_COMMIT: true
35 changes: 18 additions & 17 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ on:

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install flit
flit install
- name: Build and publish
env:
FLIT_USERNAME: ${{ secrets.PYPI_USERNAME }}
FLIT_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
flit build
flit publish
- uses: actions/checkout@v2
with:
fetch-depth: 0 # required for setuptools-scm
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install flit
flit install
- name: Build and publish
env:
FLIT_USERNAME: ${{ secrets.PYPI_USERNAME }}
FLIT_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
flit build
flit publish
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # required for setuptools-scm
- uses: actions/cache@v1
with:
path: ~/.cache/pip
Expand All @@ -43,10 +45,7 @@ jobs:
pip install $pkg
- name: Install dependencies
run: |
python -m pip install flit
flit install --deps all
env:
FLIT_ROOT_INSTALL: 1
pip install .[test,rpack]
- name: Check black formatting
run: |
black --check scirpy tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.code-workspace
.vscode/*
!.vscode/settings.json.default
notebooks
Expand Down
12 changes: 10 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ help:

.PHONY: help Makefile

livehtml: | clean
livehtml: | clean symlink
sleep 1 && touch *.rst
sphinx-autobuild \
-p 0 \
Expand All @@ -32,7 +32,15 @@ livehtml: | clean
--ignore "*.tex" \
-b html $(SOURCEDIR) $(BUILDDIR)/html

clean:
html: | symlink
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

symlink:
mkdir -p _build/html/generated
# link static to the generated directory, s.t. relative links keep working.
ln -sn ../_static _build/html/generated/_static || true

clean:
rm -rf generated
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

# -- HTML styling ----------------------------------------------------------------------

html_theme = "sphinx_rtd_theme"
html_theme = "scanpydoc"
# add custom stylesheet
# https://stackoverflow.com/a/43186995/2340703
html_static_path = ["_static"]
Expand All @@ -110,7 +110,7 @@


def setup(app):
app.add_css_file("custom.css")
pass


# -- Supress 'reference target not found' errors ---------------------------------------
Expand Down
26 changes: 19 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
[build-system]
requires = ['flit']
build-backend = 'flit.buildapi'
requires = [
'flit_core >=2,<4',
'setuptools_scm',
'pytoml',
'wheel',
'importlib_metadata>=0.7; python_version < "3.8"'
]
build-backend = 'flit_core.buildapi'

[tool.flit.metadata]
module = 'scirpy'
author = 'Gregor Sturm'
author = 'Gregor Sturm, Tamas Szabo'
author-email = '[email protected]'
home-page = 'https://github.com/grst/scirpy'
description-file = "README.rst"
Expand All @@ -18,7 +24,6 @@ classifiers = [
]
requires-python = '>= 3.6'
requires = [
'get_version',
'anndata>=0.7.3',
'scanpy>=1.5.1',
'pandas>=0.21',
Expand All @@ -31,11 +36,15 @@ requires = [
'networkx',
'squarify',
'airr',
'tqdm>=4.29.1' # See https://github.com/icbi-lab/scirpy/issues/128#issuecomment-632646608
'tqdm>=4.29.1', # See https://github.com/icbi-lab/scirpy/issues/128#issuecomment-632646608
# for getting the version
'setuptools_scm',
'pytoml',
'importlib_metadata>=0.7; python_version < "3.8"'
]

[tool.flit.metadata.requires-extra]
optional = [
rpack = [
'rectangle-packer',
]
test = [
Expand All @@ -45,8 +54,8 @@ test = [
doc = [
'sphinx>=3.0.1,<3.1',
'sphinx_autodoc_typehints>=1.8.0',
'scanpydoc>=0.5',
'sphinx_rtd_theme>=0.4',
'scanpydoc>=0.4.5',
'typing_extensions; python_version < "3.8"', # for `Literal`
# for tutorial
'leidenalg',
Expand All @@ -57,3 +66,6 @@ doc = [
'jupyter_client',
'ipykernel',
]

[tool.flit.metadata.urls]
Documentation = 'https://icbi-lab.github.io/scirpy/'
21 changes: 9 additions & 12 deletions scirpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
"""Python library for single-cell TCR analysis"""
from get_version import get_version

__version__ = get_version(__file__)
del get_version
from ._metadata import __version__, __author__, __email__, within_flit

__author__ = ", ".join(["Gregor Sturm", "Tamas Szabo"])

from scanpy import AnnData, read_h5ad
from . import io
from . import util
from . import _preprocessing as pp
from . import _tools as tl
from . import _plotting as pl
from . import datasets
if not within_flit():
from scanpy import AnnData, read_h5ad
from . import io
from . import util
from . import _preprocessing as pp
from . import _tools as tl
from . import _plotting as pl
from . import datasets
18 changes: 18 additions & 0 deletions scirpy/_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))
31 changes: 31 additions & 0 deletions scirpy/_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Metadata. Adapted from https://github.com/theislab/scanpy/pull/1374/."""
import traceback
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"]["flit"]["metadata"]

__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"]


def within_flit():
for frame in traceback.extract_stack():
if frame.name == "get_docstring_and_version_via_import":
return True
return False
Loading

0 comments on commit 358cff1

Please sign in to comment.