diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2a7b244..89b7272 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,6 +34,9 @@ repos: rev: 3.9.2 hooks: - id: flake8 + additional_dependencies: + - flake8-docstrings + - flake8-bugbear - repo: https://github.com/asottile/pyupgrade rev: v2.31.0 diff --git a/setup.py b/setup.py index d7a9f1d..9067a72 100644 --- a/setup.py +++ b/setup.py @@ -1,18 +1,79 @@ +"""Package and distribute the library.""" +import os + from setuptools import setup -install_requires = [ - "six>=1.7.2", - "tldextract==1.4", -] + +def read(fname): + """Read in file.""" + with open(os.path.join(os.path.dirname(__file__), fname)) as f: + return f.read() + + +def version_scheme(version): + """ + Version scheme hack for setuptools_scm. + + Appears to be necessary to due to the bug documented here: https://github.com/pypa/setuptools_scm/issues/342 + + If that issue is resolved, this method can be removed. + """ + import time + + from setuptools_scm.version import guess_next_version + + if version.exact: + return version.format_with("{tag}") + else: + _super_value = version.format_next_version(guess_next_version) + now = int(time.time()) + return _super_value + str(now) + + +def local_version(version): + """ + Local version scheme hack for setuptools_scm. + + Appears to be necessary to due to the bug documented here: https://github.com/pypa/setuptools_scm/issues/342 + + If that issue is resolved, this method can be removed. + """ + return "" + setup( name="storysniffer", - version="0.0.3", description="Inspect a URL and estimate if it links to news story", + long_description=read("README.md"), + long_description_content_type="text/markdown", author="Ben Welsh", - author_email="ben.welsh@gmail.com", + author_email="b@palewi.re", url="https://github.com/pastpages/storysniffer", license="MIT", packages=("storysniffer",), - install_requires=install_requires, + install_requires=("tldextract",), + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Framework :: Django", + "Framework :: Django :: 3", + "Framework :: Django :: 4", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + setup_requires=["setuptools_scm"], + use_scm_version={"version_scheme": version_scheme, "local_scheme": local_version}, + project_urls={ + "Documentation": "https://palewi.re/docs/storysniffer/", + "Source": "https://github.com/datadesk/storysniffer/", + "Tracker": "https://github.com/datadesk/storysniffer/issues", + }, ) diff --git a/storysniffer/__init__.py b/storysniffer/__init__.py index 3c2e4a5..cc16439 100644 --- a/storysniffer/__init__.py +++ b/storysniffer/__init__.py @@ -1,3 +1,4 @@ +"""Inspect a URL and estimate if it links to news story.""" import os import re from urllib.parse import urlparse @@ -63,10 +64,7 @@ def guess(url: str) -> bool: - """ - Returns a boolean estimating the likelihood that - the provided URL links to a news story. - """ + """Return a boolean estimating the likelihood that the provided URL links to a news story.""" # Throw an error if the URL doesn't match acceptable patterns if not URL_REGEX.search(url): raise ValueError("Provided url does not match acceptable URL patterns") diff --git a/test.py b/test.py index 9e6b986..3fba2c3 100644 --- a/test.py +++ b/test.py @@ -1,10 +1,14 @@ +"""Test the module.""" import unittest import storysniffer class SniffTest(unittest.TestCase): + """Run basic tests.""" + def setUp(self): + """Configure common settings.""" self.yes = "http://www.washingtonpost.com/investigations/us-intelligence-mining-data-from-nine-us-internet-companies-in-broad-secret-program/2013/06/06/3a0c0da8-cebf-11e2-8845-d970ccb04497_story.html" self.absolute_yes = "/investigations/us-intelligence-mining-data-from-nine-us-internet-companies-in-broad-secret-program/2013/06/06/3a0c0da8-cebf-11e2-8845-d970ccb04497_story.html" self.no = "http://www.cnn.com/" @@ -12,6 +16,7 @@ def setUp(self): self.busted = "foobar" def test_busted(self): + """Test stuff that shouldn't work.""" func = storysniffer.guess with self.assertRaises(ValueError): storysniffer.guess(self.busted) @@ -20,6 +25,7 @@ def test_busted(self): self.assertFalse(func(self.absolute_no)) def test_guess(self): + """Test guesses.""" func = storysniffer.guess self.assertTrue(func(self.yes)) self.assertFalse(func(self.no))