Skip to content

Commit 358cff1

Browse files
authored
Merge pull request #180 from icbi-lab/improve-packaging2
Improve packaging
2 parents 664bb54 + 1c2becd commit 358cff1

14 files changed

+149
-84
lines changed

.conda/meta.yaml

+8-19
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,16 @@ build:
1616

1717
requirements:
1818
# The way the version is resolved from SCM (flit + get_version)
19-
# requires all dependencies to be installed at build time.
19+
# requires all dependencies to be installed at build time.
2020
host:
2121
- python >=3.6
2222
- flit
23-
- get_version
24-
- anndata >=0.7.3
25-
- scanpy>=1.5.1
26-
- pandas>=0.21
27-
- numpy=1.18
28-
- scipy
29-
- parasail-python
30-
- scikit-learn
31-
- python-levenshtein
32-
- python-igraph
33-
- networkx
34-
- squarify
35-
- tqdm>=4.29.1
36-
- airr>=1.2
23+
- setuptools_scm
24+
- pytoml
25+
- importlib_metadata
26+
3727
run:
3828
- python >=3.6
39-
- get_version
4029
- anndata >=0.7.3
4130
- scanpy>=1.5.1
4231
- pandas>=0.21
@@ -71,11 +60,11 @@ test:
7160

7261
about:
7362
home: https://icbi-lab.github.io/scirpy
74-
dev_url: https://github.com/icbi-lab/scirpy
63+
dev_url: https://github.com/icbi-lab/scirpy
7564
license: BSD-3
7665
license_family: BSD
77-
summary: A Scanpy extension for analyzing single-cell T-cell receptor sequencing data.
66+
summary: A Scanpy extension for analyzing single-cell T-cell receptor sequencing data.
7867

7968
extra:
8069
identifiers:
81-
- doi:10.1101/2020.04.10.035865
70+
- doi:10.1101/2020.04.10.035865

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
max_line_length = 88
9+
10+
[*.py]
11+
indent_size = 4
12+
indent_style = space
13+
14+
[Makefile]
15+
indent_style = tab

.github/workflows/conda.yml

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,37 @@ on:
55
branches: [master]
66
pull_request:
77
branches: [master]
8-
8+
99
jobs:
1010
tests:
1111
runs-on: ${{ matrix.os }}
12-
name: conda ${{ matrix.os }}
1312
strategy:
1413
fail-fast: false
1514
matrix:
15+
python-version: [3.6, 3.7, 3.8]
1616
os: ["ubuntu-latest", "macos-latest"]
17-
17+
1818
steps:
1919
- uses: actions/checkout@v2
20-
21-
- name: Setup Minoconda
20+
with:
21+
fetch-depth: 0 # required for setuptools-scm
22+
23+
- name: Setup Minoconda
2224
uses: goanpeca/setup-miniconda@v1
2325
with:
2426
auto-update-conda: true
25-
27+
python-version: ${{ matrix.python-version }}
28+
2629
- name: Set-up channels and install conda build
2730
run: |
2831
conda config --add channels defaults
2932
conda config --add channels bioconda
3033
conda config --add channels conda-forge
3134
conda install -y conda-build conda-verify
3235
shell: bash
33-
36+
3437
- name: build and test package
3538
run: |
3639
cd .conda
37-
conda build . --no-anaconda-upload
40+
conda build --no-anaconda-upload .
3841
shell: bash

.github/workflows/docs.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
os: [ubuntu-latest, macos-latest, windows-latest]
1919
steps:
2020
- uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 0 # required for setuptools-scm
2123
- name: Fetch all tags s.t. get_version can retrieve the correct version.
2224
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
2325

@@ -64,11 +66,7 @@ jobs:
6466
6567
- name: Install dependencies
6668
run: |
67-
python -m pip install flit
68-
flit install --deps develop
69-
env:
70-
FLIT_ROOT_INSTALL: 1
71-
69+
pip install .[doc,test,rpack]
7270
- name: run sphinx
7371
run: |
7472
cd docs && make html SPHINXOPTS="-W --keep-going"
@@ -101,3 +99,4 @@ jobs:
10199
TARGET_FOLDER: ${{ env.target_dir }}
102100
CLEAN: true
103101
CLEAN_EXCLUDE: '["heads", "pull", "tags"]'
102+
SINGLE_COMMIT: true

.github/workflows/pythonpublish.yml

+18-17
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ on:
66

77
jobs:
88
deploy:
9-
109
runs-on: ubuntu-latest
1110

1211
steps:
13-
- uses: actions/checkout@v2
14-
- name: Set up Python
15-
uses: actions/setup-python@v1
16-
with:
17-
python-version: '3.x'
18-
- name: Install dependencies
19-
run: |
20-
python -m pip install flit
21-
flit install
22-
- name: Build and publish
23-
env:
24-
FLIT_USERNAME: ${{ secrets.PYPI_USERNAME }}
25-
FLIT_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
26-
run: |
27-
flit build
28-
flit publish
12+
- uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0 # required for setuptools-scm
15+
- name: Set up Python
16+
uses: actions/setup-python@v1
17+
with:
18+
python-version: "3.x"
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install flit
22+
flit install
23+
- name: Build and publish
24+
env:
25+
FLIT_USERNAME: ${{ secrets.PYPI_USERNAME }}
26+
FLIT_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
27+
run: |
28+
flit build
29+
flit publish

.github/workflows/test.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717

1818
steps:
1919
- uses: actions/checkout@v2
20+
with:
21+
fetch-depth: 0 # required for setuptools-scm
2022
- uses: actions/cache@v1
2123
with:
2224
path: ~/.cache/pip
@@ -43,10 +45,7 @@ jobs:
4345
pip install $pkg
4446
- name: Install dependencies
4547
run: |
46-
python -m pip install flit
47-
flit install --deps all
48-
env:
49-
FLIT_ROOT_INSTALL: 1
48+
pip install .[test,rpack]
5049
- name: Check black formatting
5150
run: |
5251
black --check scirpy tests

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
*.code-workspace
12
.vscode/*
23
!.vscode/settings.json.default
34
notebooks

docs/Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ help:
1414

1515
.PHONY: help Makefile
1616

17-
livehtml: | clean
17+
livehtml: | clean symlink
1818
sleep 1 && touch *.rst
1919
sphinx-autobuild \
2020
-p 0 \
@@ -32,7 +32,15 @@ livehtml: | clean
3232
--ignore "*.tex" \
3333
-b html $(SOURCEDIR) $(BUILDDIR)/html
3434

35-
clean:
35+
html: | symlink
36+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
37+
38+
symlink:
39+
mkdir -p _build/html/generated
40+
# link static to the generated directory, s.t. relative links keep working.
41+
ln -sn ../_static _build/html/generated/_static || true
42+
43+
clean:
3644
rm -rf generated
3745
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
3846

docs/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
# -- HTML styling ----------------------------------------------------------------------
9595

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

111111

112112
def setup(app):
113-
app.add_css_file("custom.css")
113+
pass
114114

115115

116116
# -- Supress 'reference target not found' errors ---------------------------------------

pyproject.toml

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
[build-system]
2-
requires = ['flit']
3-
build-backend = 'flit.buildapi'
2+
requires = [
3+
'flit_core >=2,<4',
4+
'setuptools_scm',
5+
'pytoml',
6+
'wheel',
7+
'importlib_metadata>=0.7; python_version < "3.8"'
8+
]
9+
build-backend = 'flit_core.buildapi'
410

511
[tool.flit.metadata]
612
module = 'scirpy'
7-
author = 'Gregor Sturm'
13+
author = 'Gregor Sturm, Tamas Szabo'
814
author-email = '[email protected]'
915
home-page = 'https://github.com/grst/scirpy'
1016
description-file = "README.rst"
@@ -18,7 +24,6 @@ classifiers = [
1824
]
1925
requires-python = '>= 3.6'
2026
requires = [
21-
'get_version',
2227
'anndata>=0.7.3',
2328
'scanpy>=1.5.1',
2429
'pandas>=0.21',
@@ -31,11 +36,15 @@ requires = [
3136
'networkx',
3237
'squarify',
3338
'airr',
34-
'tqdm>=4.29.1' # See https://github.com/icbi-lab/scirpy/issues/128#issuecomment-632646608
39+
'tqdm>=4.29.1', # See https://github.com/icbi-lab/scirpy/issues/128#issuecomment-632646608
40+
# for getting the version
41+
'setuptools_scm',
42+
'pytoml',
43+
'importlib_metadata>=0.7; python_version < "3.8"'
3544
]
3645

3746
[tool.flit.metadata.requires-extra]
38-
optional = [
47+
rpack = [
3948
'rectangle-packer',
4049
]
4150
test = [
@@ -45,8 +54,8 @@ test = [
4554
doc = [
4655
'sphinx>=3.0.1,<3.1',
4756
'sphinx_autodoc_typehints>=1.8.0',
57+
'scanpydoc>=0.5',
4858
'sphinx_rtd_theme>=0.4',
49-
'scanpydoc>=0.4.5',
5059
'typing_extensions; python_version < "3.8"', # for `Literal`
5160
# for tutorial
5261
'leidenalg',
@@ -57,3 +66,6 @@ doc = [
5766
'jupyter_client',
5867
'ipykernel',
5968
]
69+
70+
[tool.flit.metadata.urls]
71+
Documentation = 'https://icbi-lab.github.io/scirpy/'

scirpy/__init__.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
"""Python library for single-cell TCR analysis"""
2-
from get_version import get_version
32

4-
__version__ = get_version(__file__)
5-
del get_version
3+
from ._metadata import __version__, __author__, __email__, within_flit
64

7-
__author__ = ", ".join(["Gregor Sturm", "Tamas Szabo"])
8-
9-
from scanpy import AnnData, read_h5ad
10-
from . import io
11-
from . import util
12-
from . import _preprocessing as pp
13-
from . import _tools as tl
14-
from . import _plotting as pl
15-
from . import datasets
5+
if not within_flit():
6+
from scanpy import AnnData, read_h5ad
7+
from . import io
8+
from . import util
9+
from . import _preprocessing as pp
10+
from . import _tools as tl
11+
from . import _plotting as pl
12+
from . import datasets

scirpy/_compat.py

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from packaging import version
2+
13
try:
24
from typing import Literal
35
except ImportError:
@@ -13,3 +15,19 @@ def __getitem__(cls, values):
1315

1416
class Literal(metaclass=LiteralMeta):
1517
pass
18+
19+
20+
def pkg_metadata(package):
21+
try:
22+
from importlib.metadata import metadata as m
23+
except ImportError: # < Python 3.8: Use backport module
24+
from importlib_metadata import metadata as m
25+
return m(package)
26+
27+
28+
def pkg_version(package):
29+
try:
30+
from importlib.metadata import version as v
31+
except ImportError: # < Python 3.8: Use backport module
32+
from importlib_metadata import version as v
33+
return version.parse(v(package))

scirpy/_metadata.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Metadata. Adapted from https://github.com/theislab/scanpy/pull/1374/."""
2+
import traceback
3+
from pathlib import Path
4+
5+
here = Path(__file__).parent
6+
7+
try:
8+
from setuptools_scm import get_version
9+
import pytoml
10+
11+
proj = pytoml.loads((here.parent / "pyproject.toml").read_text())
12+
metadata = proj["tool"]["flit"]["metadata"]
13+
14+
__version__ = get_version(root="..", relative_to=__file__)
15+
__author__ = metadata["author"]
16+
__email__ = metadata["author-email"]
17+
18+
except (ImportError, LookupError, FileNotFoundError):
19+
from ._compat import pkg_metadata
20+
21+
metadata = pkg_metadata(here.name)
22+
__version__ = metadata["Version"]
23+
__author__ = metadata["Author"]
24+
__email__ = metadata["Author-email"]
25+
26+
27+
def within_flit():
28+
for frame in traceback.extract_stack():
29+
if frame.name == "get_docstring_and_version_via_import":
30+
return True
31+
return False

0 commit comments

Comments
 (0)