diff --git a/.github/workflows/pypi-mathphys.yml b/.github/workflows/pypi-mathphys.yml index 5257a22..5cd64f8 100644 --- a/.github/workflows/pypi-mathphys.yml +++ b/.github/workflows/pypi-mathphys.yml @@ -17,7 +17,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install setuptools wheel twine build - name: Build and publish env: @@ -25,6 +25,6 @@ jobs: TWINE_PASSWORD: ${{ secrets.MATHPHYS_PYPI_TOKEN }} run: | git describe --tags | sed -e 's/^v//g' > mathphys/VERSION - python setup.py sdist bdist_wheel + python -m build twine upload dist/* cd .. diff --git a/Makefile b/Makefile index 2e816c4..4b3d53d 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ help: ## Show this help. @grep '##' Makefile| sed -e '/@/d' | sed -r 's,(.*?:).*##(.*),\1\2,g' dist: ## Build setuptools dist - python setup.py sdist bdist_wheel + python -m build distupload: ## Upload package dist to PyPi python -m twine upload --verbose dist/* diff --git a/mathphys/functions.py b/mathphys/functions.py index f7ba61d..40f07c3 100644 --- a/mathphys/functions.py +++ b/mathphys/functions.py @@ -1,18 +1,18 @@ """Useful functions.""" import os as _os import builtins as _builtins -import importlib as _importlib from collections import namedtuple as _namedtuple from functools import partial as _partial import pickle as _pickle import subprocess as _subprocess -import pkg_resources as _pkg_resources +# NOTE: Change to importlib.metadata once python3.6 is not supported anymore: +import importlib_metadata as _implib_meta from types import ModuleType as _ModuleType import gzip as _gzip try: import h5py as _h5py -except: +except ModuleNotFoundError: _h5py = None @@ -305,8 +305,8 @@ def get_path_from_package(package): pkg = package.__package__ else: raise ValueError('Invalid package type, must be str or module') - dist = _pkg_resources.get_distribution(pkg) - return dist.location, dist.version + dist = _implib_meta.distribution(pkg) + return str(dist.locate_file("")), dist.version def is_git_repo(path): diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..5a06ade --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,73 @@ +[build-system] +requires = ["setuptools>=44"] +build-backend = "setuptools.build_meta" + +[project] +name = "mathphys" +authors = [{ name = "lnls-fac" } ] +maintainers = [ + {name = "Ana Oliveira", email = "ana.clara@lnls.br"}, + {name = "Ximenes Resende", email = "xresende@gmail.com"}, + {name = "Fernando H. de Sá", email = "fernandohds564@gmail.com"}, + {name = "Murilo Barbosa Alves", email= "alvesb.murilo@gmail.com"} +] +description = "LNLS Math and Physics Utilities" +readme = "README.md" +dynamic = ["version", "dependencies"] +requires-python = ">=3.4" +classifiers = [ + "Intended Audience :: Science/Research", + "Programming Language :: Python", + "Topic :: Scientific/Engineering", +] +license = "MIT" +license-files= [ "LICENSE", ] + +[project.urls] +Homepage = "https://github.com/lnls-fac/mathphys" +Download = "https://github.com/lnls-fac/mathphys" +Repository = "https://github.com/lnls-fac/mathphys.git" +Issues = "https://github.com/lnls-fac/mathphys/issues" + +# --- Configurações específicas do Setuptools --- +[tool.setuptools] +include-package-data = true + +[tool.setuptools.dynamic] +version = { file = "VERSION" } +dependencies = { file = "requirements.txt" } + +[tool.setuptools.package-data] +mathphys = ["VERSION"] + +# --- linter and formatter configurations --- +[tool.ruff] +select = [ + "W", "E", "A", "B", "C90", "D", "I002", "N", "F", "G", "ARG", "S", "NPY"] +ignore = [ + "D203", "D204", "D213", "D215", "D400", "D401", "D404", "D406", "D407", + "D408", "D409", "D413", "E203", "E226"] +ignore-init-module-imports = true +preview = true +line-length = 79 +fix = true + +[tool.ruff.extend-per-file-ignores] +"__init__.py" = ["F401", "F821"] + +[tool.ruff.format] +skip-magic-trailing-comma = true + +[tool.ruff.lint.isort] +split-on-trailing-comma = false +combine-as-imports = true + +[tool.isort] +split_on_trailing_comma = false +combine_as_imports = true +combine_star = true +multi_line_output = "HANGING_INDENT" +order_by_type = false + +[tool.black] +line-length = 79 diff --git a/requirements.txt b/requirements.txt index f4e0a77..5fb8af6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +importlib-metadata numpy>=1.18,<=1.23 matplotlib>=3.1.2 h5py>=3.1.0 diff --git a/setup.py b/setup.py index bf38892..695d4de 100755 --- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ #!/usr/bin/env python-sirius """Setup module.""" +import pathlib from setuptools import setup -import pkg_resources def get_abs_path(relative): - return pkg_resources.resource_filename(__name__, relative) + return str(pathlib.Path(__file__).parent / relative) with open(get_abs_path("README.md"), "r") as _f: