From b17f3b1ab6ab0c7056a16dedf05b5c95afab1b45 Mon Sep 17 00:00:00 2001 From: Nezar Abdennur Date: Fri, 5 Apr 2024 19:57:45 -0400 Subject: [PATCH] build: Use importlib.metadata for versioning (#195) * build: Use importlib.metadata for versioning * docs: Use importlib.metadata for version --- bioframe/__init__.py | 156 ++++++++++++++++++++++++++++++++++++-- bioframe/_version.py | 1 - bioframe/core/__init__.py | 61 +++++++++++---- bioframe/io/__init__.py | 41 +++++++--- docs/conf.py | 50 +++--------- pyproject.toml | 37 ++++----- 6 files changed, 255 insertions(+), 91 deletions(-) delete mode 100644 bioframe/_version.py diff --git a/bioframe/__init__.py b/bioframe/__init__.py index 16c262f2..abc2ea36 100644 --- a/bioframe/__init__.py +++ b/bioframe/__init__.py @@ -1,6 +1,150 @@ -from ._version import __version__ -from .core import * -from .io import * -from .ops import * -from .extras import * -from .vis import * +try: + from importlib.metadata import PackageNotFoundError, version +except ImportError: + from importlib_metadata import PackageNotFoundError, version + +try: + __version__ = version("bioframe") +except PackageNotFoundError: + __version__ = "unknown" + +__all__ = [ + "arrops", + "from_any", + "from_dict", + "from_list", + "from_series", + "is_bedframe", + "is_cataloged", + "is_chrom_dtype", + "is_complete_ucsc_string", + "is_contained", + "is_covering", + "is_overlapping", + "is_sorted", + "is_tiling", + "is_viewframe", + "make_viewframe", + "parse_region", + "parse_region_string", + "sanitize_bedframe", + "to_ucsc_string", + "update_default_colnames", + "binnify", + "digest", + "frac_gc", + "frac_gene_coverage", + "frac_mapped", + "make_chromarms", + "pair_by_distance", + "seq_gc", + "SCHEMAS", + "UCSCClient", + "assemblies_available", + "assembly_info", + "fetch_centromeres", + "fetch_chromsizes", + "load_fasta", + "read_bam", + "read_bigbed", + "read_bigwig", + "read_chromsizes", + "read_pairix", + "read_tabix", + "read_table", + "to_bigbed", + "to_bigwig", + "assign_view", + "closest", + "cluster", + "complement", + "count_overlaps", + "coverage", + "expand", + "merge", + "overlap", + "select", + "select_indices", + "select_labels", + "select_mask", + "setdiff", + "sort_bedframe", + "subtract", + "trim", + "plot_intervals", + "to_ucsc_colorstring", +] + +from .core import ( + arrops, + from_any, + from_dict, + from_list, + from_series, + is_bedframe, + is_cataloged, + is_chrom_dtype, + is_complete_ucsc_string, + is_contained, + is_covering, + is_overlapping, + is_sorted, + is_tiling, + is_viewframe, + make_viewframe, + parse_region, + parse_region_string, + sanitize_bedframe, + to_ucsc_string, + update_default_colnames, +) +from .extras import ( + binnify, + digest, + frac_gc, + frac_gene_coverage, + frac_mapped, + make_chromarms, + pair_by_distance, + seq_gc, +) +from .io import ( + SCHEMAS, + UCSCClient, + assemblies_available, + assembly_info, + fetch_centromeres, + fetch_chromsizes, + load_fasta, + read_bam, + read_bigbed, + read_bigwig, + read_chromsizes, + read_pairix, + read_tabix, + read_table, + to_bigbed, + to_bigwig, +) +from .ops import ( + assign_view, + closest, + cluster, + complement, + count_overlaps, + coverage, + expand, + merge, + overlap, + select, + select_indices, + select_labels, + select_mask, + setdiff, + sort_bedframe, + subtract, + trim, +) +from .vis import plot_intervals, to_ucsc_colorstring + +del version, PackageNotFoundError diff --git a/bioframe/_version.py b/bioframe/_version.py deleted file mode 100644 index 63af8876..00000000 --- a/bioframe/_version.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "0.6.3" diff --git a/bioframe/core/__init__.py b/bioframe/core/__init__.py index 6d22eddf..eb6f11bc 100644 --- a/bioframe/core/__init__.py +++ b/bioframe/core/__init__.py @@ -1,21 +1,50 @@ from . import arrops - -from . import specs -from .specs import * - -from . import stringops -from .stringops import * - -from . import checks -from .checks import * - -from . import construction -from .construction import * +from .checks import ( + is_bedframe, + is_cataloged, + is_contained, + is_covering, + is_overlapping, + is_sorted, + is_tiling, + is_viewframe, +) +from .construction import ( + from_any, + from_dict, + from_list, + from_series, + make_viewframe, + sanitize_bedframe, +) +from .specs import is_chrom_dtype, update_default_colnames +from .stringops import ( + is_complete_ucsc_string, + parse_region, + parse_region_string, + to_ucsc_string, +) __all__ = [ "arrops", - *specs.__all__, - *stringops.__all__, - *checks.__all__, - *construction.__all__, + "is_bedframe", + "is_cataloged", + "is_contained", + "is_covering", + "is_overlapping", + "is_sorted", + "is_tiling", + "is_viewframe", + "from_any", + "from_dict", + "from_list", + "from_series", + "make_viewframe", + "sanitize_bedframe", + "is_chrom_dtype", + "update_default_colnames", + "is_complete_ucsc_string", + "parse_region", + "parse_region_string", + "to_ucsc_string", ] diff --git a/bioframe/io/__init__.py b/bioframe/io/__init__.py index f5b1ccdb..78320b90 100644 --- a/bioframe/io/__init__.py +++ b/bioframe/io/__init__.py @@ -1,17 +1,34 @@ +from .assembly import assemblies_available, assembly_info +from .fileops import ( + load_fasta, + read_bam, + read_bigbed, + read_bigwig, + read_chromsizes, + read_pairix, + read_tabix, + read_table, + to_bigbed, + to_bigwig, +) +from .resources import UCSCClient, fetch_centromeres, fetch_chromsizes from .schemas import SCHEMAS -from . import fileops -from .fileops import * - -from . import resources -from .resources import * - -from . import assembly -from .assembly import * - __all__ = [ + "assemblies_available", + "assembly_info", + "read_table", + "read_chromsizes", + "read_tabix", + "read_pairix", + "read_bam", + "load_fasta", + "read_bigwig", + "to_bigwig", + "read_bigbed", + "to_bigbed", + "UCSCClient", + "fetch_centromeres", + "fetch_chromsizes", "SCHEMAS", - *fileops.__all__, - *resources.__all__, - *assembly.__all__, ] diff --git a/docs/conf.py b/docs/conf.py index fa413b5c..c90701b5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,51 +5,25 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Path setup -------------------------------------------------------------- - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -# -import os -import sys - -sys.path.insert(0, os.path.abspath("../")) - +# import sys +from datetime import datetime +from importlib.metadata import metadata +from pathlib import Path # autodoc_mock_imports = ["numpy", "pandas", "matplotlib", "requests"] # -- Project information ----------------------------------------------------- - -project = "bioframe" -copyright = "2020, Open2C" +# NOTE: If you installed your project in editable mode, this might be stale. +# If this is the case, reinstall it to refresh the metadata +info = metadata("bioframe") +project_name = info["Name"] author = "Open2C" - +copyright = f"{datetime.now():%Y}, {author}." +version = info["Version"] +urls = dict(pu.split(", ") for pu in info.get_all("Project-URL")) # The full version, including alpha/beta/rc tags -def _read(*parts, **kwargs): - import os - - filepath = os.path.join(os.path.dirname(__file__), *parts) - encoding = kwargs.pop("encoding", "utf-8") - with open(filepath, encoding=encoding) as fh: - text = fh.read() - return text - - -def get_version(): - import re - - version = re.search( - r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', - _read("..", "bioframe", "_version.py"), - re.MULTILINE, - ).group(1) - return version - - -version = get_version() -# The full version, including alpha/beta/rc tags. -release = version +release = info["Version"] # -- General configuration --------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index dc653eae..888e7ef3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,7 @@ build-backend = "hatchling.build" [project] name = "bioframe" +version = "0.6.3" description = "Operations and utilities for Genomic Interval Dataframes." license = {text = "MIT"} authors = [ @@ -34,7 +35,6 @@ classifiers = [ "Programming Language :: Python :: 3.11", ] readme = "README.md" -dynamic = ["version"] dependencies = [ "matplotlib", "numpy>=1.10", @@ -42,7 +42,8 @@ dependencies = [ "pyyaml", "requests", "typing-extensions ; python_version<'3.9'", - "importlib_resources ; python_version<'3.9'" + "importlib-metadata ; python_version<'3.8'", + "importlib-resources ; python_version<'3.9'", ] [project.optional-dependencies] @@ -72,18 +73,6 @@ documentation = "https://bioframe.readthedocs.io/en/latest" repository = "https://github.com/open2c/bioframe" changelog = "https://github.com/open2c/bioframe/blob/main/CHANGES.md" -[tool.hatch.version] -path = "bioframe/_version.py" - -[tool.hatch.envs.default] -features = ["dev", "test", "docs"] - -[tool.hatch.envs.default.scripts] -fix = "ruff --fix ." -lint = "ruff bioframe tests" -test = "pytest ." -docs = "sphinx-autobuild docs docs/_build/html" - [tool.isort] profile = "black" skip_gitignore = true @@ -93,11 +82,8 @@ known_first_party = "bioframe" target-version = "py37" exclude = [ ".venv", - "bioframe/__init__.py", - "bioframe/core/__init__.py", - "bioframe/io/__init__.py", ] -extend-select = [ +lint.extend-select = [ # "C", # mccabe complexity # "D", # pydocstyle "E", # style errors @@ -107,3 +93,18 @@ extend-select = [ "UP", # pyupgrade "W", # style warnings ] + +[tool.hatch.envs.default] +features = ["dev", "test", "docs"] + +[tool.hatch.envs.default.scripts] +fix = "ruff check --fix ." +lint = "ruff check bioframe tests" +test = "pytest ." +docs = "sphinx-autobuild docs docs/_build/html" + +[tool.hatch.envs.test] +features = ["dev", "test"] + +[[tool.hatch.envs.test.matrix]] +python = ["3.8", "3.9", "3.10", "3.11"]