Skip to content

Commit

Permalink
1. Drop support for python 3.6 and 3.7
Browse files Browse the repository at this point in the history
    * Update versions for most dependencies
    * Update python version matrix in CI workflow
2. Add cgranges as submodule
    * Add build script to compile cgranges
    * Update pyproject.toml to call build script, and include cgranges package
    * Tell mypy to ignore lines that reference cgranges
    * In CI workflow
        * Checkout with submodules
        * Install dev dependencies and build before install
        * Update poetry version
3. Misc
    * Put authors list in correct format, drop Nick, add myself
    * Replace references to `py.path` with `tmp_path` in unit tests
  • Loading branch information
jdidion committed Sep 11, 2023
1 parent d58b567 commit 2d5daa4
Show file tree
Hide file tree
Showing 9 changed files with 643 additions and 807 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ name: Python package

on: [push]
env:
POETRY_VERSION: 1.1.15
POETRY_VERSION: 1.6.1

jobs:
testing:
runs-on: ubuntu-20.04
strategy:
matrix:
PYTHON_VERSION: ["3.6", "3.7", "3.8", "3.9"]
PYTHON_VERSION: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
with:
submodules: 'true'

- name: Set up Python ${{matrix.PYTHON_VERSION}}
uses: actions/setup-python@v4
Expand All @@ -26,8 +28,6 @@ jobs:
- name: Install poetry
shell: bash
run: |
# See: https://github.com/python-poetry/poetry/blob/46bf7fd3d1797b75ad9b07adc280039d93414e07/pyproject.toml#L78-L81
python -m pip install --upgrade pip urllib3==1.25.10
pip install poetry==${{env.POETRY_VERSION}}
- name: Configure poetry
Expand All @@ -49,6 +49,8 @@ jobs:
- name: Install deps
shell: bash
run: |
poetry install --only dev
poetry build
poetry install --extras docs
- name: Run pytest
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "cgranges"]
path = cgranges
url = https://github.com/lh3/cgranges
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ required.

[rtd-link]: http://pybedlite.readthedocs.org/en/stable

**Requires python 3.6+**
**Requires python 3.8+** (for python < 3.8, please use pybedlite <= 0.0.3)

# Getting Setup for Development Work

Expand All @@ -62,14 +62,14 @@ required.
A simple way to create an environment with the desired version of python and poetry is to use [conda][conda-link]. E.g.:

```bash
conda create -n pybedlite python=3.6 poetry
conda create -n pybedlite python=3.8 poetry
conda activate pybedlite
poetry install
```

If the methods listed above do not work try the following:
```bash
mamba create -n pybedlite -c conda-forge "python=3.9.16" "poetry=1.1.15"
mamba create -n pybedlite -c conda-forge "python=3.9.16" "poetry=1.6.1"
mamba activate pybedlite
poetry install
```
Expand Down
26 changes: 26 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from setuptools import Extension
from Cython.Build import build_ext

ext_modules = [
Extension(
"cgranges",
sources=["cgranges/python/cgranges.pyx", "cgranges/cgranges.c"],
depends=[
"cgranges/cgranges.h",
"cgranges/khash.h",
"cgranges/python/cgranges.pyx"
],
include_dirs=["cgranges"]
)
]

def build(setup_kwargs):
"""
This function is mandatory in order to build the extensions.
"""
setup_kwargs.update(
{
"ext_modules": ext_modules,
"cmdclass": {"build_ext": build_ext},
}
)
1 change: 1 addition & 0 deletions cgranges
Submodule cgranges added at 2fb5a2
1,326 changes: 566 additions & 760 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pybedlite/overlap_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class OverlapDetector(Iterable[Interval]):

def __init__(self) -> None:
# A mapping from the contig/chromosome name to the associated interval tree
self._refname_to_tree: Dict[str, cr.cgranges] = {}
self._refname_to_tree: Dict[str, cr.cgranges] = {} # type: ignore
self._refname_to_indexed: Dict[str, bool] = {}
self._refname_to_intervals: Dict[str, List[Interval]] = {}

Expand All @@ -132,7 +132,7 @@ def add(self, interval: Interval) -> None:
"""
refname = interval.refname
if refname not in self._refname_to_tree:
self._refname_to_tree[refname] = cr.cgranges()
self._refname_to_tree[refname] = cr.cgranges() # type: ignore
self._refname_to_indexed[refname] = False
self._refname_to_intervals[refname] = []

Expand Down
25 changes: 10 additions & 15 deletions pybedlite/tests/test_pybedlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest
from pathlib import Path
from py._path.local import LocalPath as TmpDir
from typing import List
import pybedlite as pybed
from pybedlite.bed_writer import MAX_BED_FIELDS
Expand Down Expand Up @@ -126,9 +125,8 @@ def compare_bed_records(
12,
],
)
def test_bed_parsing(tmpdir: TmpDir, bed_field_number: int, bed_records: List[BedRecord]) -> None:
tmpdir_path = Path(tmpdir)
test_bed = tmpdir_path / "test.bed"
def test_bed_parsing(tmp_path: Path, bed_field_number: int, bed_records: List[BedRecord]) -> None:
test_bed = tmp_path / "test.bed"

with BedWriter(test_bed, num_fields=bed_field_number) as test_out:
test_out.write_all(bed_records, truncate=True, add_missing=True)
Expand Down Expand Up @@ -157,10 +155,9 @@ def test_bed_parsing(tmpdir: TmpDir, bed_field_number: int, bed_records: List[Be
],
)
def test_preopened_bed_parsing(
tmpdir: TmpDir, bed_field_number: int, bed_records: List[BedRecord]
tmp_path: Path, bed_field_number: int, bed_records: List[BedRecord]
) -> None:
tmpdir_path = Path(tmpdir)
test_bed = tmpdir_path / "test.bed"
test_bed = tmp_path / "test.bed"

with BedWriter(test_bed, num_fields=bed_field_number) as test_out:
test_out.write_all(bed_records, truncate=True, add_missing=True)
Expand Down Expand Up @@ -190,10 +187,9 @@ def test_preopened_bed_parsing(
12,
],
)
def test_bed_writing(tmpdir: TmpDir, bed_field_number: int, bed_records: List[BedRecord]) -> None:
tmpdir_path = Path(tmpdir)
test_written_bed = tmpdir_path / "test_written.bed"
test_premade_bed = tmpdir_path / "test_premade.bed"
def test_bed_writing(tmp_path: Path, bed_field_number: int, bed_records: List[BedRecord]) -> None:
test_written_bed = tmp_path / "test_written.bed"
test_premade_bed = tmp_path / "test_premade.bed"

with BedWriter(test_written_bed, num_fields=bed_field_number) as test_out:
test_out.write_all(bed_records, truncate=True, add_missing=True)
Expand Down Expand Up @@ -228,11 +224,10 @@ def test_bed_writing(tmpdir: TmpDir, bed_field_number: int, bed_records: List[Be
],
)
def test_preopened_bed_writing(
tmpdir: TmpDir, bed_field_number: int, bed_records: List[BedRecord]
tmp_path: Path, bed_field_number: int, bed_records: List[BedRecord]
) -> None:
tmpdir_path = Path(tmpdir)
test_written_bed = tmpdir_path / "test_written.bed"
test_premade_bed = tmpdir_path / "test_premade.bed"
test_written_bed = tmp_path / "test_written.bed"
test_premade_bed = tmp_path / "test_premade.bed"

test_written_bed_fh = test_written_bed.open("w")

Expand Down
49 changes: 26 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
[tool.poetry]
name = "pybedlite"
version = "0.0.4-dev"
version = "0.0.4-dev1"
description = "Python classes for interfacing with bed intervals"
authors = ["Nils Homer", "Tim Fennell", "Nathan Roach"]
authors = [
"Nils Homer <[email protected]>",
"Tim Fennell <[email protected]>",
"John Didion <[email protected]>",
]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/fulcrumgenomics/pybedlite"
repository = "https://github.com/fulcrumgenomics/pybedlite"
keywords = ["bioinformatics"]
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Bio-Informatics",
"Topic :: Software Development :: Documentation",
"Topic :: Software Development :: Libraries :: Python Modules",
]
include = [
"LICENSE",
"Topic :: Software Development :: Documentation",
"Topic :: Software Development :: Libraries :: Python Modules",
]
include = ["LICENSE"]
packages = [{ include = "pybedlite" }, { include = "cgranges" }]

[tool.poetry.dependencies]
python = ">=3.6.0"
attrs = ">=19.3.0"
typing_extensions = { version = ">=3.7.4", python = "<3.8" } # Literal support
typing_inspect = { version = ">=0.3.1", python = "<3.8" } # inspecting types
sphinx = {version = "4.3.1", optional = true}
Cython = "^0.29.30"
cgranges = {git = "https://github.com/lh3/cgranges.git", rev = "v0.1"}
python = "^3.8.0"
attrs = "^23.0.0"
sphinx = { version = "^7.0.0", optional = true }

[tool.poetry.dev-dependencies]
pytest = ">=5.4.2"
mypy = ">=0.770"
flake8 = ">=4.0.1"
black = ">=19.10b0"
pytest-cov = ">=2.8.1"
pytest = "^7.0.0"
mypy = "^1.5.0"
flake8 = "^5.0.0"
black = "^23.0.0"
pytest-cov = "^4.0.0"

[tool.poetry.extras]
docs = ["sphinx"]

[tool.poetry.build]
script = "build.py"
generate-setup-file = true

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core", "setuptools", "cython"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 2d5daa4

Please sign in to comment.