diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 380ed62..2636e19 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,22 +1,28 @@ repos: - repo: https://github.com/PyCQA/isort - rev: 5.6.4 + rev: 5.9.3 hooks: - id: isort - repo: https://github.com/psf/black - rev: 20.8b1 + rev: 21.9b0 hooks: - id: black +- repo: https://github.com/PyCQA/pydocstyle + rev: 6.1.1 + hooks: + - id: pydocstyle + files: ^buildurl - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 + rev: 3.9.2 hooks: - id: flake8 + # additional_dependencies: [flake8-black, flake8-isort, flake8-docstrings] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.790 + rev: v0.910 hooks: - id: mypy - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.3.0 + rev: v4.0.1 hooks: - id: check-toml - id: check-yaml diff --git a/buildurl/__init__.py b/buildurl/__init__.py index 0afd83a..c49a58b 100644 --- a/buildurl/__init__.py +++ b/buildurl/__init__.py @@ -1,4 +1,4 @@ -"""Simple URL builder""" +"""Simple URL builder.""" __version__ = "4.0.0" diff --git a/buildurl/builder.py b/buildurl/builder.py index 6ea93de..fc330bf 100644 --- a/buildurl/builder.py +++ b/buildurl/builder.py @@ -1,3 +1,5 @@ +"""BuildURL's core.""" + from copy import deepcopy from typing import Any, Dict, List, Optional, Tuple, Union from urllib.parse import parse_qs, urlencode, urlsplit, urlunsplit @@ -31,6 +33,7 @@ class BuildURL: """ def __init__(self, base: str = "", force_trailing_slash: bool = False): + """Initialize a new instance of BuildURL.""" purl = urlsplit(base) # scheme://netloc/path;params?query#fragment @@ -68,7 +71,7 @@ def copy(self) -> "BuildURL": return deepcopy(self) def set_force_trailing_slash(self, enabled: bool = True) -> "BuildURL": - """Sets the `force_trailing_slash` attribute + """Set the `force_trailing_slash` attribute. Args: enabled: @@ -115,7 +118,6 @@ def add_path(self, *args: Path) -> "BuildURL": >>> print(url.get) https://example.com/never/stopping/to/play/with/paths """ - path_list = list() for path in args: if isinstance(path, str): @@ -166,7 +168,6 @@ def add_query(self, *args: Query, **kwargs) -> "BuildURL": >>> print(url.get) https://example.com?key=value&another=query&more=stuff&a=b&c=d&e=f """ - query_dict = dict() for query in args: if isinstance(query, str): @@ -250,7 +251,6 @@ def __itruediv__(self, path: Path) -> "BuildURL": >>> print(url.get) https://example.com/test/more/paths/again/and/again/ """ - self.add_path(path) return self @@ -274,7 +274,6 @@ def __truediv__(self, path: Path) -> "BuildURL": >>> print(new_url.get) https://example.com/testing """ - out = self.copy() out /= path return out @@ -300,7 +299,6 @@ def __iadd__(self, query: Query) -> "BuildURL": >>> print(url.get) https://example.com?key=value&another=query&more=stuff """ - self.add_query(query) return self @@ -324,7 +322,6 @@ def __add__(self, query: Query) -> "BuildURL": >>> print(new_url.get) https://example.com?test=it """ - out = self.copy() out += query return out @@ -340,7 +337,6 @@ def __repr__(self) -> str: >>> print(repr(url)) BuildURL(base='https://example.com/test?now=true', force_trailing_slash=False) """ - return f"{self.__class__.__name__}(base='{self.get}', force_trailing_slash={self.force_trailing_slash})" def __str__(self) -> str: @@ -359,7 +355,6 @@ def __str__(self) -> str: >>> print(url) https://example.com/test """ - return self.get def __len__(self) -> int: diff --git a/buildurl/py.typed b/buildurl/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/docs/conf.py b/docs/conf.py index ff8f0c8..8c990f7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,8 +1,9 @@ -# Configuration file for the Sphinx documentation builder. -# -# This file only contains a selection of the most common options. For a full -# list see the documentation: -# https://www.sphinx-doc.org/en/master/usage/configuration.html +"""Configuration file for the Sphinx documentation builder. + +This file only contains a selection of the most common options. For a full +list see the documentation: +https://www.sphinx-doc.org/en/master/usage/configuration.html +""" # -- Path setup -------------------------------------------------------------- diff --git a/requirements-dev.txt b/requirements-dev.txt index c3acd06..18a23e0 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,18 +1,20 @@ -black==20.8b1 -build==0.3.0 -coverage==5.4 -flake8==3.8.4 -flake8-black==0.2.1 +black==21.9b0 +build==0.7.0 +coverage==6.0.1 +flake8==3.9.2 +flake8-black==0.2.3 +flake8-docstrings==1.6.0 flake8-isort==4.0.0 -isort==5.7.0 -mypy==0.812 +isort==5.9.3 +mypy==0.910 mypy-extensions==0.4.3 -pre-commit==2.10.1 -pytest==6.2.2 -pytest-cov==2.11.1 -python-semantic-release==7.15.0 +pre-commit==2.15.0 +pydocstyle==6.1.1 +pytest==6.2.5 +pytest-cov==3.0.0 +python-semantic-release==7.19.2 recommonmark==0.7.1 semver==2.13.0 -Sphinx==3.5.1 -sphinx-rtd-theme==0.5.1 -sphinxcontrib-spelling==7.1.0 +Sphinx==4.2.0 +sphinx-rtd-theme==1.0.0 +sphinxcontrib-spelling==7.2.1 diff --git a/setup.cfg b/setup.cfg index 172532e..50e1fba 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,6 +4,8 @@ version = attr: buildurl.__version__ author = Micael Jarniac author_email = micael@jarniac.dev description = Simple URL builder +license = MIT +license_file = LICENSE long_description = file: README.md long_description_content_type = text/markdown url = https://github.com/MicaelJarniac/BuildURL @@ -11,12 +13,17 @@ project_urls = Bug Tracker = https://github.com/MicaelJarniac/BuildURL/issues classifiers = Programming Language :: Python :: 3 + Programming Language :: Python :: 3 :: Only License :: OSI Approved :: MIT License Operating System :: OS Independent [options] packages = find: python_requires = >=3.6 +zip_safe = no + +[options.package_data] +buildurl = py.typed [flake8] max-line-length = 88 @@ -26,6 +33,10 @@ ignore = E203, E266, E501, W503, F403, F401 [isort] profile = black +[pydocstyle] +convention = google +match_dir = buildurl + [semantic_release] changelog_capitalize = false version_variable = buildurl/__init__.py:__version__ diff --git a/setup.py b/setup.py index b908cbe..7385501 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +"""Project setup.""" + import setuptools setuptools.setup() diff --git a/tests/test_buildurl.py b/tests/test_buildurl.py index db40085..cf41b8a 100644 --- a/tests/test_buildurl.py +++ b/tests/test_buildurl.py @@ -179,5 +179,5 @@ def test_chaining(): url = BuildURL("https://example.com") url.add_path("one").add_path("two") assert url.get == "https://example.com/one/two" - url.add_query({"test": "more"}).add_path("three").add_query("testing=alot") - assert url.get == "https://example.com/one/two/three?test=more&testing=alot" + url.add_query({"test": "more"}).add_path("three").add_query("testing=a_lot") + assert url.get == "https://example.com/one/two/three?test=more&testing=a_lot"