diff --git a/.github/workflows/ci_install-pkg.yml b/.github/workflows/ci_install-pkg.yml index 193dc07..95dccf3 100644 --- a/.github/workflows/ci_install-pkg.yml +++ b/.github/workflows/ci_install-pkg.yml @@ -19,8 +19,6 @@ jobs: - name: Check package run: | - pip install check-manifest - check-manifest python setup.py check --metadata --strict - name: Create package diff --git a/MANIFEST.in b/MANIFEST.in index cf448b8..712f2e7 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,18 +1,7 @@ -# Manifest syntax https://docs.python.org/2/distutils/sourcedist.html -graft wheelhouse +# Manifest syntax https://setuptools.pypa.io/en/latest/deprecated/distutils/commandref.html#sdist-cmd -recursive-exclude __pycache__ *.py[cod] *.orig - -# Include the README -include *.md - -# Include the license file -include LICENSE - -recursive-include torchsampler *.py - -# Include the Requirements -include requirements.txt +# FIXME: switching to a src/ layout would obviate the need for this file entirely. +# see https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#src-layout # Exclude build configs exclude *.yml @@ -20,5 +9,3 @@ exclude *.yaml prune .github prune example* -prune temp* -prune test* diff --git a/requirements.txt b/requirements.txt index 6b4e9db..b09bf97 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ torch>=1.3 torchvision>=0.5 pandas +# only needed by __about__.py, which is deprecated: +importlib_metadata; python_version<'3.8' diff --git a/setup.cfg b/setup.cfg index 152f83b..946216e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,5 @@ [metadata] license_file = LICENSE -description-file = README.md [flake8] max-line-length = 120 diff --git a/setup.py b/setup.py index 456dc49..589ece4 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,9 @@ """A setuptools based setup module.""" -import sys from pathlib import Path from setuptools import setup -try: - from torchsampler import __about__ as about -except ImportError: - # alternative https://stackoverflow.com/a/67692/4521646 - sys.path.append("torchsampler") - import __about__ as about - PATH_HERE = Path(__file__).parent with open(PATH_HERE / 'requirements.txt', encoding='utf-8') as fp: @@ -20,16 +12,18 @@ setup( name='torchsampler', - version=about.__version__, - url=about.__homepage__, - author=about.__author__, - author_email=about.__author_email__, - license=about.__license__, - description=about.__doc__, + use_scm_version=True, + url="https://github.com/ufoym/imbalanced-dataset-sample", + author="Ming, et al.", + author_email="a@ufoym.com", + license="MIT", + description="A (PyTorch) imbalanced dataset sampler for oversampling low classes" + "and undersampling high frequent ones.", long_description=long_description, long_description_content_type='text/markdown', packages=['torchsampler'], keywords='sampler,pytorch,dataloader', + setup_requires=['setuptools_scm'], install_requires=requirements, python_requires='>=3.6', include_package_data=True, diff --git a/torchsampler/__about__.py b/torchsampler/__about__.py index bd953c7..cef1e9e 100644 --- a/torchsampler/__about__.py +++ b/torchsampler/__about__.py @@ -1,10 +1,31 @@ -__version__ = "0.1.1" -__author__ = "Ming, et al." -__author_email__ = "a@ufoym.com" -__license__ = "MIT" -__homepage__ = "https://github.com/ufoym/imbalanced-dataset-sampler" -__doc__ = "A (PyTorch) imbalanced dataset sampler for oversampling low frequent classes" \ - " and undersampling high frequent ones." +import sys + +if sys.version_info < (3, 8): + from importlib_metadata import distribution, PackageNotFoundError +else: + from importlib.metadata import distribution, PackageNotFoundError + +import warnings + +warnings.warn( + "Use importlib.metadata.distribution('torchsampler').metadata instead of torchsampler.__about__.", + category=DeprecationWarning +) + +try: + _m = distribution('torchsampler').metadata + __version__ = _m['version'] + __author__ = _m['author'] + __author_email__ = _m['author-email'] + __license__ = _m['license'] + __homepage__ = _m['homepage'] + __doc__ = _m['summary'] + del _m +except PackageNotFoundError: + # package is not installed (i.e. we're probably in the build process itself) + pass + +del sys, distribution, PackageNotFoundError, warnings __all__ = [ "__author__",