Skip to content

Commit

Permalink
Move to pyproject and compatibility python 3.11/12
Browse files Browse the repository at this point in the history
  • Loading branch information
cokelaer committed Apr 28, 2024
1 parent 5eb343a commit 1951cfb
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 103 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ name: Tests
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
branches-ignore: []

jobs:
build-linux:
runs-on: ubuntu-latest
strategy:
max-parallel: 5
matrix:
python: [3.8, 3.9, "3.10", 3.11]
fail-fast: false

python: [3.8, 3.8, 3.9, '3.10', '3.10', '3.]

steps:
- uses: actions/checkout@v3
Expand All @@ -27,9 +24,8 @@ jobs:

- name: Install the package itself
run: |
pip install --upgrade pip
pip install .
pip install pytest pytest-cov coveralls pytest-xdist pytest-timeout
pip install poetry
poetry install --with dev
- name: Test with pytest
run: |
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Publish to PyPI
on:
on:
workflow_dispatch:
push:
tags:
Expand All @@ -11,20 +11,20 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@main
- name: Set up Python 3.7
uses: actions/setup-python@v1
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.8

- name: Install package
- name: Install package
run: |
pip install build
pip install build poetry
- name: Build source tarball
run: |
rm -rf dist;
python setup.py sdist
poetry build
- name: Publish distribution to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

files: '\.(py|rst|sh)$'
fail_fast: false

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
#- id: check-executables-have-shebangs
- id: check-ast

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
args: ["-j8", "--ignore=E203,E501,W503,E722", "--max-line-length=120", "--exit-zero"]

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args: ["--line-length=120"]
exclude: E501

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"] # solves conflicts between black and isort

2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ changelog
========= ================================================================================
Version Description
========= ================================================================================
1.1.0 * switch to pyproject. remove easydev dependency. compat for python 3.11 and
3.12
1.0.6 * Fix a matplotlib deprecation
* Fix RTD documentation
1.0.5 * remove Python3.6 and added Python3.10 to CI action
Expand Down
Empty file modified doc/make.bat
100644 → 100755
Empty file.
62 changes: 62 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "colormap"
version = "1.1.0"
description = "Commn utilities to ease development of Python packages"
authors = ["Thomas Cokelaer <[email protected]>"]
license = "BSD-3-Clause"
readme = "README.rst"
keywords = ["config", "decorators", "development"]

classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Education",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Scientific/Engineering :: Bio-Informatics",
"Topic :: Scientific/Engineering :: Information Analysis",
]

[project.urls]
Homepage = "https://colormap/dev.readthedocs.io"
Repository = "https://github.com/cokelaer/colormap"
Issues = "https://github.com/cokelaer/colormap/issues"
Documentation = "https://colormap.readthedocs.io"



[tool.poetry.dependencies]
python = "^3.9"
matplotlib = "^3.8.4"



[tool.poetry.group.dev.dependencies]
pytest = "^7.4.4"
pytest-cov = "^4.1.0"
pytest-xdist = "^3.5.0"
pytest-mock = "^3.12.0"
pytest-runner = "^6.0.1"
coveralls = "^3.3.1"
flaky = "^3.7.0"


[tool.poetry.group.doc.dependencies]
sphinx = ">3"
sphinx-rtd-theme = "^2.0.0"
sphinx-gallery = "^0.15.0"




2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

20 changes: 11 additions & 9 deletions src/colormap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@
#
##############################################################################
"""main colormap module"""
from __future__ import print_function
from __future__ import division
from importlib import metadata

import pkg_resources

try:
version = pkg_resources.require("colormap")[0].version
__version__ = version
except Exception:
version = ""
def get_package_version(package_name):
try:
version = metadata.version(package_name)
return version
except metadata.PackageNotFoundError:
return f"{package_name} not found"


version = get_package_version("colormap")


from .xfree86 import *
from . import colors
from .colors import *
from .get_cmap import *
from .xfree86 import *

c = Colormap()
colormap_names = c.colormaps + c.diverging_black
Expand Down
57 changes: 53 additions & 4 deletions src/colormap/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
"""
# matplotlib dependence is only inside Colormap class
import colorsys
from easydev.tools import check_param_in_list, swapdict, check_range
from colormap.xfree86 import XFree86_colors

from colormap.xfree86 import XFree86_colors

__all__ = [
"HEX",
Expand All @@ -48,6 +47,53 @@
]


def check_range(data, dmin, dmax):
if data < dmin or data > dmax:
raise ValueError(f"Value must be in the range [{dmin}-{dmax}]. You provided {data}")


def swapdict(dic, check_ambiguity=True):
"""Swap keys for values in a dictionary
::
>>> d = {'a':1}
>>> swapdict(d)
{1:'a'}
"""
# this version is more elegant but slightly slower : return {v:k for k,v in dic.items()}
if check_ambiguity:
assert len(set(dic.keys())) == len(set(dic.values())), "values is not a set. ambiguities for keys."
return dict(zip(dic.values(), dic.keys()))


def check_param_in_list(param, valid_values, name=None):
"""Checks that the value of param is amongst valid
:param param: a parameter to be checked
:param list valid_values: a list of values
::
check_param_in_list(1, [1,2,3])
check_param_in_list(mode, ["on", "off"])
"""
if isinstance(valid_values, list) is False:

raise TypeError(
"the valid_values second argument must be a list of valid values. {0} was provided.".format(valid_values)
)

if param not in valid_values:
if name:
msg = "Incorrect value provided for {} ({})".format(name, param)
else:
msg = "Incorrect value provided (%s)" % param
msg += " Correct values are %s" % valid_values
raise ValueError(msg)


def hex2web(hexa):
"""Convert hexadecimal string (6 digits) into *web* version (3 digits)
Expand Down Expand Up @@ -136,9 +182,11 @@ def rgb2hex(r, g, b, normalised=False):
r = int(r)
g = int(g)
b = int(b)

check_range(r, 0, 255)
check_range(g, 0, 255)
check_range(b, 0, 255)

return "#%02X%02X%02X" % (r, g, b)


Expand Down Expand Up @@ -943,6 +991,7 @@ def cmap(self, colors=None, reverse=False, N=256):
if reverse and colors.endswith("_r") is False:
colors += "_r"
from matplotlib import colormaps

return colormaps[colors]
# custom ones
elif colors in self.diverging_black:
Expand Down Expand Up @@ -1038,13 +1087,13 @@ def test_colormap(self, cmap=None):
if cmap is None:
cmap = self.get_cmap_heat()
import numpy as np
from pylab import clf, pcolor, colorbar, show, linspace, axis
from pylab import axis, clf, colorbar, linspace, pcolor, show

A, B = np.meshgrid(linspace(0, 10, 100), linspace(0, 10, 100))
clf()
pcolor((A - 5) ** 2 + (B - 5) ** 2, cmap=cmap)
colorbar()
show()
# show()
axis("off")

def plot_colormap(self, cmap_list=None):
Expand Down
Loading

0 comments on commit 1951cfb

Please sign in to comment.