Skip to content

Import bbayles/what-url #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build and test

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore:
- '**.rst'
- 'docs/**'
push:
branches:
- main
paths-ignore:
- '**.rst'
- 'docs/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_test:
strategy:
matrix:
os: ["ubuntu-20.04", "macos-latest"]
python: ["3.8", "3.9", "3.10", "3.11"]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we install Ruff and test the linter as well in a different workflow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can split the workflow into different pieces, sure.

uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
make requirements
- name: Static analysis
if: "matrix.python == '3.8'"
run: |
make check
- name: Build packages
run: |
make package
- name: Repair wheels
if: "matrix.os == 'ubuntu-20.04'"
run: |
pip install -U auditwheel patchelf
auditwheel repair --plat manylinux_2_31_x86_64 --wheel-dir dist dist/ada_url-*linux*.whl
- name: Run tests
run: |
pip install -e .
make coverage
- name: Build docs with sphinx
if: "matrix.python == '3.8' && matrix.os == 'ubuntu-20.04'"
run: |
make docs
- name: Upload packages
uses: actions/upload-artifact@v3
with:
name: ada-url-packages
path: dist/*
142 changes: 142 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so
*.o

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# MacOS stuff
.DS_Store
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.PHONY: requirements
requirements:
python3 -m pip install -r requirements/development.txt

.PHONY: check
check:
black --check .
ruff .

.PHONY: format
format:
black .

.PHONY: coverage
coverage:
coverage run -m unittest
coverage report --show-missing --fail-under 99

.PHONY: test
test:
python -m unittest -v ${tests}

.PHONY: docs
docs:
sphinx-build -W -b html docs docs/_build/html

.PHONY: clean
clean:
rm -rf _build/
rm -rf _dist/
rm -rf ada_url.egg-info/
$(RM) ada_url/_ada_wrapper.abi3.so
$(RM) ada_url/ada.o

.PHONY: package
package:
$(CXX) -c "ada_url/ada.cpp" -fPIC -std="c++17" -O2 -o "ada_url/ada.o"
python -m build --no-isolation
twine check dist/*
49 changes: 49 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ada-url
========

This is ``ada_url``, a Python library for parsing and joining URLs.


Examples
--------

This package exposes a ``URL`` class that is intended to match the one described in the
`WHATWG URL spec <https://url.spec.whatwg.org/#url-class>`__.

.. code-block:: python

>>> import ada_url
>>> with ada_url.URL('https://example.org/path/../file.txt') as urlobj:
... urlobj.host = 'example.com'
... new_url = urlobj.href
>>> new_url
'https://example.com/file.txt'

It also provides some higher level functions for parsing and manipulating URLs.

.. code-block:: python

>>> import ada_url
>>> ada_url.check_url('https://example.org')
True
>>> ada_url.join_url(
'https://example.org/dir/child.txt', '../parent.txt'
)
'https://example.org/parent.txt'
>>> ada_url.normalize_url('https://example.org/dir/../parent.txt')
'https://example.org/parent.txt'
>>> ada_url.parse_url('https://user:[email protected]:80/api?q=1#2')
{
'href': 'https://user:[email protected]:80/api?q=1#2',
'username': 'user',
'password': 'pass',
'protocol': 'https:',
'host': 'example.org:80',
'port': '80',
'hostname': 'example.org',
'pathname': '/api',
'search': '?q=1',
'hash': '#2'
}
>>> ada_url.replace_url('http://example.org:80', protocol='https:')
'https://example.org/'
17 changes: 17 additions & 0 deletions ada_url/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from ada_url.ada_adapter import (
URL,
check_url,
join_url,
normalize_url,
parse_url,
replace_url,
)

__all__ = [
'URL',
'check_url',
'join_url',
'normalize_url',
'parse_url',
'replace_url',
]
Loading