Skip to content

Commit

Permalink
Merge pull request #17 from MicaelJarniac/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
MicaelJarniac authored Nov 18, 2021
2 parents 7e27e9e + 3029762 commit 81bd28a
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 36 deletions.
16 changes: 11 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion buildurl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Simple URL builder"""
"""Simple URL builder."""

__version__ = "4.0.0"

Expand Down
13 changes: 4 additions & 9 deletions buildurl/builder.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand All @@ -359,7 +355,6 @@ def __str__(self) -> str:
>>> print(url)
https://example.com/test
"""

return self.get

def __len__(self) -> int:
Expand Down
Empty file added buildurl/py.typed
Empty file.
11 changes: 6 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -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 --------------------------------------------------------------

Expand Down
30 changes: 16 additions & 14 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ version = attr: buildurl.__version__
author = Micael Jarniac
author_email = [email protected]
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
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
Expand All @@ -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__
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Project setup."""

import setuptools

setuptools.setup()
4 changes: 2 additions & 2 deletions tests/test_buildurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 81bd28a

Please sign in to comment.