Skip to content

Commit

Permalink
A little more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Jul 30, 2022
1 parent 60853cb commit ca7b216
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -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
Expand Down
75 changes: 68 additions & 7 deletions 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",
},
)
6 changes: 2 additions & 4 deletions 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
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions test.py
@@ -1,17 +1,22 @@
"""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/"
self.absolute_no = "/"
self.busted = "foobar"

def test_busted(self):
"""Test stuff that shouldn't work."""
func = storysniffer.guess
with self.assertRaises(ValueError):
storysniffer.guess(self.busted)
Expand All @@ -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))
Expand Down

0 comments on commit ca7b216

Please sign in to comment.