diff --git a/.flake8 b/.flake8 new file mode 100755 index 0000000..461b267 --- /dev/null +++ b/.flake8 @@ -0,0 +1,8 @@ +[flake8] +application_import_names = uriregistry, tests +exclude = .venv, + .tox, + __pycache__, +import-order-style = pycharm +max-line-length = 90 +ignore = E402, E405, W503, F403, F405 \ No newline at end of file diff --git a/.github/workflows/uriregistry.yaml b/.github/workflows/uriregistry.yaml new file mode 100644 index 0000000..df0fd93 --- /dev/null +++ b/.github/workflows/uriregistry.yaml @@ -0,0 +1,42 @@ +name: Uriregistry backend tests + +on: + workflow_dispatch: + + pull_request: + paths: + - uriregistry/** + - .github/workflows/uriregistry.yaml + - scripts/** + - pyproject.toml + - requirements*.txt + - tests/** + + push: + branches: + - main +env: + PYTHON_VERSION: '3.11' + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Install python requirements + env: + HATCH_BUILD_NO_HOOKS: true + working-directory: ./ + run: | + pip --version + pip install pip-tools + pip-sync requirements-dev.txt + pip install -e . + + - name: Python tests + run: pytest tests --exitfirst --capture=no -vvv --full-trace diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f08a0e2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,25 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + types: [python] + - id: trailing-whitespace + types: [python] +- repo: https://github.com/psf/black + rev: 24.3.0 + hooks: + - id: black + types: [python] + args: [--preview] + exclude: docs, tests +- repo: https://github.com/PyCQA/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + additional_dependencies: + - flake8-import-order==0.18.2 + - flake8-bugbear==24.2.6 + types: [python] + exclude: docs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3c1e57b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: python -python: - - "3.8" -env: - - LC_ALL=en_US.utf-8 -install: - - pip install -r requirements-dev.txt #fix versions - - python setup.py develop -script: - - py.test --cov uriregistry --cov-report term-missing tests -after_success: - - coveralls diff --git a/CHANGES.md b/CHANGES.md new file mode 100644 index 0000000..f55eb1b --- /dev/null +++ b/CHANGES.md @@ -0,0 +1,39 @@ +0.4.0 (04-07-2024) +================== + +- pyproj - gh actions - async workers (#102) + +0.3.1 (16-08-2022) +================== + +- Avoid \"max\_workers must be greater than 0\"-Exception in case no + applications are listed in the configurarion (\#97) + +0.3.0 (21-02-2022) +================== + +- Improved performance (\#8) +- Pyramid 2.0 upgrade (\#85) + +0.2.0 (07-12-2020) +================== + +- Library update(\#69) +- Py3 compatibel maken (\#66) + +0.1.2 (08-06-2017) +================== + +- Make compatible with Python 3.5 +- Update pyramid\_urireferencer to 0.6.0 (\#9) + +0.1.1 (04-08-2015) +================== + +- Update pyramid\_urireferencer to 0.4.0 + +0.1.0 (11-06-2015) +================== + +- Initial version +- Works with pyramid\_urireferencer 0.2.0. diff --git a/CHANGES.rst b/CHANGES.rst deleted file mode 100644 index 839f52b..0000000 --- a/CHANGES.rst +++ /dev/null @@ -1,33 +0,0 @@ -0.3.1 (16-08-2022) ------------------- - -- Avoid "max_workers must be greater than 0"-Exception in case no applications are listed in the configurarion (#97) - -0.3.0 (21-02-2022) ------------------- - -- Improved performance (#8) -- Pyramid 2.0 upgrade (#85) - -0.2.0 (07-12-2020) ------------------- - -- Library update(#69) -- Py3 compatibel maken (#66) - -0.1.2 (08-06-2017) ------------------- - -- Make compatible with Python 3.5 -- Update pyramid_urireferencer to 0.6.0 (#9) - -0.1.1 (04-08-2015) ------------------- - -- Update pyramid_urireferencer to 0.4.0 - -0.1.0 (11-06-2015) ------------------- - -- Initial version -- Works with pyramid_urireferencer 0.2.0. diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 85c1b8a..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include *.txt *.ini *.cfg *.rst *.yaml -prune tests diff --git a/README.md b/README.md new file mode 100644 index 0000000..67dfa27 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +UriRegistry +=========== + +[![image](https://badge.fury.io/py/uriregistry.png)](http://badge.fury.io/py/uriregistry) +[![image](https://readthedocs.org/projects/uriregistry/badge/?version=latest)](https://readthedocs.org/projects/uriregistry/?badge=latest) +[![image](https://travis-ci.org/OnroerendErfgoed/uriregistry.png?branch=master)](https://travis-ci.org/OnroerendErfgoed/uriregistry) +[![image](https://coveralls.io/repos/OnroerendErfgoed/uriregistry/badge.png?branch=master)](https://coveralls.io/r/OnroerendErfgoed/uriregistry) + +This project aims to provide a central location for keeping track of +different resources through their URI\'s. It has been designed to answer +one simple question: in which applications is a certain resource (ie. a +URI) being used? diff --git a/README.rst b/README.rst deleted file mode 100644 index d6797d2..0000000 --- a/README.rst +++ /dev/null @@ -1,16 +0,0 @@ -UriRegistry -=========== - -.. image:: https://badge.fury.io/py/uriregistry.png - :target: http://badge.fury.io/py/uriregistry -.. image:: https://readthedocs.org/projects/uriregistry/badge/?version=latest - :target: https://readthedocs.org/projects/uriregistry/?badge=latest - -.. image:: https://travis-ci.org/OnroerendErfgoed/uriregistry.png?branch=master - :target: https://travis-ci.org/OnroerendErfgoed/uriregistry -.. image:: https://coveralls.io/repos/OnroerendErfgoed/uriregistry/badge.png?branch=master - :target: https://coveralls.io/r/OnroerendErfgoed/uriregistry - -This project aims to provide a central location for keeping track of different -resources through their URI's. It has been designed to answer one simple -question: in which applications is a certain resource (ie. a URI) being used? diff --git a/docs/source/conf.py b/docs/source/conf.py index 098b7f1..49a2d69 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -17,66 +17,66 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('../../')) +sys.path.insert(0, os.path.abspath("../../")) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinxcontrib.plantuml', - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.ifconfig', - 'sphinx.ext.viewcode', - 'sphinxcontrib.httpdomain' + "sphinxcontrib.plantuml", + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.todo", + "sphinx.ext.coverage", + "sphinx.ext.ifconfig", + "sphinx.ext.viewcode", + "sphinxcontrib.httpdomain", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # PlantUML config -plantuml = 'java -jar plantuml.jar' -plantuml_latex_output_format = 'pdf' -plantuml_output_format = 'png' +plantuml = "java -jar plantuml.jar" +plantuml_latex_output_format = "pdf" +plantuml_output_format = "png" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'UriRegistry' -copyright = '2014-2020, Onroerend Erfgoed' +project = "UriRegistry" +copyright = "2014-2020, Onroerend Erfgoed" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '0.3.1' +version = "0.3.1" # The full version, including alpha/beta/rc tags. -release = '0.3.1' +release = "0.3.1" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -84,154 +84,157 @@ # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'alabaster' +html_theme = "alabaster" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'UriRegistrydoc' +htmlhelp_basename = "UriRegistrydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'UriRegistry.tex', 'UriRegistry Documentation', - 'Onroerend Erfgoed', 'manual'), + ( + "index", + "UriRegistry.tex", + "UriRegistry Documentation", + "Onroerend Erfgoed", + "manual", + ), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- @@ -239,12 +242,11 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'uriregistry', 'UriRegistry Documentation', - ['Onroerend Erfgoed'], 1) + ("index", "uriregistry", "UriRegistry Documentation", ["Onroerend Erfgoed"], 1) ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -253,19 +255,25 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'UriRegistry', 'UriRegistry Documentation', - 'Onroerend Erfgoed', 'UriRegistry', "Where's my uri?", - 'Miscellaneous'), + ( + "index", + "UriRegistry", + "UriRegistry Documentation", + "Onroerend Erfgoed", + "UriRegistry", + "Where's my uri?", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4dbceca --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,71 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +version = "0.4.0" +name = "uriregistry" +dynamic = ["readme"] +authors = [ + { name = "Flanders Heritage Agency", email = "ict@onroerenderfgoed.be" }, +] +description = "A central URI registry that tracks where a certain URI is being used." +requires-python = ">=3.10,<3.13" +keywords = ["web", "wsgi", "pyramid", "SKOS", "thesaurus", "vocabulary"] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Programming Language :: Python", + "Framework :: Pyramid", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +] +dependencies = [ + "pyramid==2.0.2", + "pyramid_urireferencer==0.8.0", + "pyyaml==6.0.1", + "requests==2.32.3" +] + +[project.urls] +History = "https://github.com/OnroerendErfgoed/uriregistry/blob/master/CHANGES.rst" +Tracker = "https://github.com/OnroerendErfgoed/uriregistry/issues" +Source = "https://github.com/OnroerendErfgoed/uriregistry" +Documentation = "https://uriregistry.readthedocs.io/en/latest/" + +[project.optional-dependencies] +dev = [ + "black==24.4.2", + "coveralls==4.0.1", + "flake8-import-order==0.18.2", + "flake8==7.1.0", + "httpretty==1.1.4", + "pre-commit==3.7.1", + "pyramid_debugtoolbar==4.12.1", + "pytest-cov==5.0.0", + "pytest==8.2.2", + "sphinx==7.3.7", + "sphinxcontrib-httpdomain==1.8.1", + "sphinxcontrib-plantuml==0.30", + "waitress==3.0.0", + "webtest==3.0.0" +] + +[project.entry-points."paste.app_factory"] +main = "uriregistry:main" + +## +# Build tool specific +## +[tool.hatch.build.targets.wheel] +# In the wheel we want to have uriregistry in the root as python module. +only-include = [ + "/uriregistry", +] + +[tool.hatch.metadata] +# This allows us to use github links as dependencies +allow-direct-references = true + diff --git a/requirements-dev.txt b/requirements-dev.txt index 9bc1ae4..f8a6a95 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,20 +1,157 @@ -# Runtime requirements ---requirement requirements.txt - -# Documentation -Sphinx==4.3.2 -sphinxcontrib-httpdomain==1.8.0 -sphinxcontrib-plantuml==0.22 - -waitress==2.0.0 -pyramid_debugtoolbar==4.9 - -#testing -pytest==6.2.5 -pytest-cov==3.0.0 -webtest==3.0.0 +alabaster==0.7.16 + # via sphinx +babel==2.15.0 + # via sphinx +beautifulsoup4==4.12.3 + # via webtest +black==24.4.2 +certifi==2024.6.2 + # via requests +cfgv==3.4.0 + # via pre-commit +charset-normalizer==3.3.2 + # via requests +click==8.1.7 + # via black +coverage==7.5.3 + # via + # coveralls + # pytest-cov +coveralls==4.0.1 +distlib==0.3.8 + # via virtualenv +docopt==0.6.2 + # via coveralls +docutils==0.21.2 + # via sphinx +filelock==3.15.1 + # via virtualenv +flake8==7.1.0 +flake8-import-order==0.18.2 httpretty==1.1.4 -coveralls==3.3.1 - -# Wheel -wheel==0.37.1 +hupper==1.12.1 + # via pyramid +identify==2.5.36 + # via pre-commit +idna==3.7 + # via requests +imagesize==1.4.1 + # via sphinx +iniconfig==2.0.0 + # via pytest +jinja2==3.1.4 + # via sphinx +mako==1.3.5 + # via pyramid-mako +markupsafe==2.1.5 + # via + # jinja2 + # mako +mccabe==0.7.0 + # via flake8 +mypy-extensions==1.0.0 + # via black +nodeenv==1.9.1 + # via pre-commit +packaging==24.1 + # via + # black + # pytest + # sphinx +pastedeploy==3.1.0 + # via plaster-pastedeploy +pathspec==0.12.1 + # via black +plaster==1.1.2 + # via + # plaster-pastedeploy + # pyramid +plaster-pastedeploy==1.0.1 + # via pyramid +platformdirs==4.2.2 + # via + # black + # virtualenv +pluggy==1.5.0 + # via pytest +pre-commit==3.7.1 +pycodestyle==2.12.0 + # via + # flake8 + # flake8-import-order +pyflakes==3.2.0 + # via flake8 +pygments==2.18.0 + # via + # pyramid-debugtoolbar + # sphinx +pyramid==2.0.2 + # via + # pyramid-debugtoolbar + # pyramid-mako + # pyramid-urireferencer +pyramid-debugtoolbar==4.12.1 +pyramid-mako==1.1.0 + # via pyramid-debugtoolbar +pyramid-urireferencer==0.8.0 +pytest==8.2.2 + # via pytest-cov +pytest-cov==5.0.0 +pyyaml==6.0.1 + # via pre-commit +requests==2.32.3 + # via + # coveralls + # pyramid-urireferencer + # sphinx +setuptools==70.1.0 + # via + # flake8-import-order + # pyramid + # zope-deprecation + # zope-interface +six==1.16.0 + # via + # pyramid-urireferencer + # sphinxcontrib-httpdomain +snowballstemmer==2.2.0 + # via sphinx +soupsieve==2.5 + # via beautifulsoup4 +sphinx==7.3.7 + # via + # sphinxcontrib-httpdomain + # sphinxcontrib-plantuml +sphinxcontrib-applehelp==1.0.8 + # via sphinx +sphinxcontrib-devhelp==1.0.6 + # via sphinx +sphinxcontrib-htmlhelp==2.0.5 + # via sphinx +sphinxcontrib-httpdomain==1.8.1 +sphinxcontrib-jsmath==1.0.1 + # via sphinx +sphinxcontrib-plantuml==0.30 +sphinxcontrib-qthelp==1.0.7 + # via sphinx +sphinxcontrib-serializinghtml==1.1.10 + # via sphinx +translationstring==1.4 + # via pyramid +urllib3==2.2.2 + # via requests +venusian==3.1.0 + # via pyramid +virtualenv==20.26.2 + # via pre-commit +waitress==3.0.0 + # via webtest +webob==1.8.7 + # via + # pyramid + # webtest +webtest==3.0.0 +zope-deprecation==5.0 + # via pyramid +zope-interface==6.4.post2 + # via pyramid diff --git a/requirements.txt b/requirements.txt index fa6b277..445087a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,41 @@ -requests==2.27.0 -pyramid==2.0 - -PyYAML==5.4.1 - -pyramid_urireferencer==0.8.0 +certifi==2024.6.2 + # via requests +charset-normalizer==3.3.2 + # via requests +hupper==1.12.1 + # via pyramid +idna==3.7 + # via requests +pastedeploy==3.1.0 + # via plaster-pastedeploy +plaster==1.1.2 + # via + # plaster-pastedeploy + # pyramid +plaster-pastedeploy==1.0.1 + # via pyramid +pyramid==2.0.2 + # via pyramid-urireferencer +pyramid-urireferencer==0.8.0 +pyyaml==6.0.1 +requests==2.32.3 + # via pyramid-urireferencer +setuptools==70.1.0 + # via + # pyramid + # zope-deprecation + # zope-interface +six==1.16.0 + # via pyramid-urireferencer +translationstring==1.4 + # via pyramid +urllib3==2.2.2 + # via requests +venusian==3.1.0 + # via pyramid +webob==1.8.7 + # via pyramid +zope-deprecation==5.0 + # via pyramid +zope-interface==6.4.post2 + # via pyramid diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 2a9acf1..0000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[bdist_wheel] -universal = 1 diff --git a/setup.py b/setup.py deleted file mode 100644 index f006780..0000000 --- a/setup.py +++ /dev/null @@ -1,44 +0,0 @@ -import os - -from setuptools import setup, find_packages - -here = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(here, 'README.rst')) as f: - README = f.read() -with open(os.path.join(here, 'CHANGES.rst')) as f: - CHANGES = f.read() - -requires = [ - 'pyramid', - 'pyramid_urireferencer', - 'requests', - 'PyYAML' - ] - -setup(name='uriregistry', - version='0.3.1', - description='A central URI registry that tracks where a certain URI is being used.', - long_description=README + '\n\n' + CHANGES, - classifiers=[ - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Programming Language :: Python", - "Programming Language :: Python :: 3.8", - "Framework :: Pyramid", - "Topic :: Internet :: WWW/HTTP", - "Topic :: Internet :: WWW/HTTP :: WSGI :: Application", - ], - author='Flanders Heritage Agency', - author_email='ict@onroerenderfgoed.be', - url='http://uriregistry.readthedocs.org', - license='GPLv3', - keywords='web wsgi pyramid uri', - packages=find_packages(), - include_package_data=True, - zip_safe=False, - test_suite='uriregistry', - install_requires=requires, - entry_points="""\ - [paste.app_factory] - main = uriregistry:main - """, - ) diff --git a/tests/conftest.py b/tests/conftest.py index 7920d63..c2c6a97 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,36 +2,40 @@ from uriregistry.registry import UriRegistry + @pytest.fixture(scope="session") def registryconfig(): cfg = { - 'uri_templates': [ + "uri_templates": [ + { + "match_uri": r"http://id.erfgoed.net/foobar/\d+", + "applications": ["http://localhost:5555", "http://localhost:2222"], + }, + { + "match_uri": r"http://id.erfgoed.net/bar/\w+", + "applications": ["http://localhost:5555"], + }, { - 'match_uri': r'http://id.erfgoed.net/foobar/\d+', - 'applications': ['http://localhost:5555', 'http://localhost:2222'] - }, { - 'match_uri': r'http://id.erfgoed.net/bar/\w+', - 'applications': ['http://localhost:5555'] - }, { - 'match_uri': r'http://id.erfgoed.net/foo/.+', - 'applications': ['http://localhost:2222'] - } + "match_uri": r"http://id.erfgoed.net/foo/.+", + "applications": ["http://localhost:2222"], + }, ], - 'applications': [ + "applications": [ { - 'name': 'app1', - 'uri': 'http://localhost:5555', - 'service_url': 'http://localhost:5555/references' - }, { - 'name': 'app2', - 'uri': 'http://localhost:2222', - 'service_url': 'http://localhost:2222/references' - } - ] + "name": "app1", + "uri": "http://localhost:5555", + "service_url": "http://localhost:5555/references", + }, + { + "name": "app2", + "uri": "http://localhost:2222", + "service_url": "http://localhost:2222/references", + }, + ], } return cfg @pytest.fixture(scope="session") def uriregistry(registryconfig): - return UriRegistry(registryconfig['applications'], registryconfig['uri_templates']) + return UriRegistry(registryconfig["applications"], registryconfig["uri_templates"]) diff --git a/tests/test.yaml b/tests/test.yaml index 7a38aa2..4c588b2 100644 --- a/tests/test.yaml +++ b/tests/test.yaml @@ -1,21 +1,21 @@ applications: - - uri: http://localhost:5555 - name: app1 - service_url: http://localhost:5555/references - - uri: http://localhost:2222 - name: app2 - service_url: http://localhost:2222/references + - uri: http://localhost:5555 + name: app1 + service_url: http://localhost:5555/references + - uri: http://localhost:2222 + name: app2 + service_url: http://localhost:2222/references uri_templates: - - match_uri: http://id.erfgoed.net/foobar/\d+ - applications: - - http://localhost:5555 - - http://localhost:2222 - - match_uri: http://id.erfgoed.net/bar/\w+ - applications: - - http://localhost:5555 - - match_uri: http://id.erfgoed.net/foo/.+ - applications: - - http://localhost:2222 - - match_uri: http://id.erfgoed.net/ba(l|k)/\d+ - applications: - - http://localhost:5555 + - match_uri: http://id.erfgoed.net/foobar/\d+ + applications: + - http://localhost:5555 + - http://localhost:2222 + - match_uri: http://id.erfgoed.net/bar/\w+ + applications: + - http://localhost:5555 + - match_uri: http://id.erfgoed.net/foo/.+ + applications: + - http://localhost:2222 + - match_uri: http://id.erfgoed.net/ba(l|k)/\d+ + applications: + - http://localhost:5555 diff --git a/tests/test_functional.py b/tests/test_functional.py index be338b7..83f3870 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -1,41 +1,43 @@ import os import pytest - from webtest import TestApp @pytest.fixture() def app(): settings = { - 'uriregistry.config': os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test.yaml') + "uriregistry.config": os.path.join( + os.path.dirname(os.path.realpath(__file__)), "test.yaml" + ) } from uriregistry import main + return TestApp(main({}, **settings)) class TestFunctional: def test_home(self, app): - res = app.get('/') - assert res.status == '200 OK' + res = app.get("/") + assert res.status == "200 OK" def test_get_features_without_uri(self, app): - res = app.get('/references', status=400) - assert res.status == '400 Bad Request' + res = app.get("/references", status=400) + assert res.status == "400 Bad Request" def test_get_features_with_uri(self, app): - res = app.get('/references?uri=http://id.erfgoed.net/foo/1') - assert res.status == '200 OK' - assert 'application/json' in res.headers['Content-Type'] + res = app.get("/references?uri=http://id.erfgoed.net/foo/1") + assert res.status == "200 OK" + assert "application/json" in res.headers["Content-Type"] def test_get_features_with_or_regex(self, app): - res = app.get('/references?uri=http://id.erfgoed.net/bal/789') - assert res.status == '200 OK' + res = app.get("/references?uri=http://id.erfgoed.net/bal/789") + assert res.status == "200 OK" data_bal = res.json - assert len(data_bal['applications']) == 1 - res = app.get('/references?uri=http://id.erfgoed.net/bak/232') - assert res.status == '200 OK' + assert len(data_bal["applications"]) == 1 + res = app.get("/references?uri=http://id.erfgoed.net/bak/232") + assert res.status == "200 OK" data_bak = res.json - assert len(data_bak['applications']) == 1 - assert data_bal['applications'] == data_bak['applications'] + assert len(data_bak["applications"]) == 1 + assert data_bal["applications"] == data_bak["applications"] diff --git a/tests/test_general.py b/tests/test_general.py index 82b458c..6a6e906 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -1,22 +1,26 @@ import os -from uriregistry import ( - _parse_settings, - _load_configuration -) +from uriregistry import _load_configuration +from uriregistry import _parse_settings class TestGeneral: def test_parse_settings(self): settings = { - 'uriregistry.config': os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test.yaml') + "uriregistry.config": os.path.join( + os.path.dirname(os.path.realpath(__file__)), "test.yaml" + ) } args = _parse_settings(settings) - assert 'config' in args - assert args['config'] == os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test.yaml') + assert "config" in args + assert args["config"] == os.path.join( + os.path.dirname(os.path.realpath(__file__)), "test.yaml" + ) def test_load_configuration(self): - cfg = _load_configuration(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test.yaml')) - assert 'uri_templates' in cfg - assert 'applications' in cfg + cfg = _load_configuration( + os.path.join(os.path.dirname(os.path.realpath(__file__)), "test.yaml") + ) + assert "uri_templates" in cfg + assert "applications" in cfg diff --git a/tests/test_models.py b/tests/test_models.py index 6d17fdc..165bf3b 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -4,21 +4,21 @@ class TestUri: def test_numeric_matches(self): - u = UriTemplate(r'http://id.erfgoed.net/foobar/\d+$', []) - assert u.matches('http://id.erfgoed.net/foobar/1') - assert u.matches('http://id.erfgoed.net/foobar/12') - assert u.matches('http://id.erfgoed.net/foobar/123456789') - assert not u.matches('http://id.erfgoed.net/foo/a') - assert not u.matches('http://id.erfgoed.net/bar/a') - assert not u.matches('http://id.erfgoed.net/foobar/a') - assert not u.matches('http://id.erfgoed.net/foobar') - assert not u.matches('http://id.erfgoed.net/foobar/1a') + u = UriTemplate(r"http://id.erfgoed.net/foobar/\d+$", []) + assert u.matches("http://id.erfgoed.net/foobar/1") + assert u.matches("http://id.erfgoed.net/foobar/12") + assert u.matches("http://id.erfgoed.net/foobar/123456789") + assert not u.matches("http://id.erfgoed.net/foo/a") + assert not u.matches("http://id.erfgoed.net/bar/a") + assert not u.matches("http://id.erfgoed.net/foobar/a") + assert not u.matches("http://id.erfgoed.net/foobar") + assert not u.matches("http://id.erfgoed.net/foobar/1a") def test_alphanumeric_matches(self): - u = UriTemplate(r'http://id.erfgoed.net/foobar/\w+$', []) - assert u.matches('http://id.erfgoed.net/foobar/a') - assert u.matches('http://id.erfgoed.net/foobar/at') - assert u.matches('http://id.erfgoed.net/foobar/baz') - assert u.matches('http://id.erfgoed.net/foobar/1') - assert not u.matches('http://id.erfgoed.net/foobar') - assert not u.matches('http://id.erfgoed.net/foobar/1-a') + u = UriTemplate(r"http://id.erfgoed.net/foobar/\w+$", []) + assert u.matches("http://id.erfgoed.net/foobar/a") + assert u.matches("http://id.erfgoed.net/foobar/at") + assert u.matches("http://id.erfgoed.net/foobar/baz") + assert u.matches("http://id.erfgoed.net/foobar/1") + assert not u.matches("http://id.erfgoed.net/foobar") + assert not u.matches("http://id.erfgoed.net/foobar/1-a") diff --git a/tests/test_registry.py b/tests/test_registry.py index 20c21dc..1cc42a2 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -7,18 +7,18 @@ class TestRegistry: def test_get_applications_no_match(self, uriregistry): - apps = uriregistry.get_applications('http://nudge.nudge.wink.wink') + apps = uriregistry.get_applications("http://nudge.nudge.wink.wink") assert len(apps) == 0 def test_get_applications_numeric_matches(self, uriregistry): - apps = uriregistry.get_applications('http://id.erfgoed.net/foobar/1') + apps = uriregistry.get_applications("http://id.erfgoed.net/foobar/1") assert len(apps) == 2 - apps = uriregistry.get_applications('http://id.erfgoed.net/foo/a') + apps = uriregistry.get_applications("http://id.erfgoed.net/foo/a") assert len(apps) == 1 def test_get_applications_alphanumeric_matches(self, uriregistry): - apps = uriregistry.get_applications('http://id.erfgoed.net/foobar/a') + apps = uriregistry.get_applications("http://id.erfgoed.net/foobar/a") assert len(apps) == 0 @@ -44,14 +44,18 @@ class TestGetAndBuild: def test_get_uri_registry(self, registryconfig): r = MockRegistry() - UR = UriRegistry(registryconfig['applications'], registryconfig['uri_templates']) + UR = UriRegistry( + registryconfig["applications"], registryconfig["uri_templates"] + ) r.registerUtility(UR, IUriRegistry) UR2 = get_uri_registry(r) assert UR == UR2 def test_build_uri_registry_already_exists(self, registryconfig): r = MockRegistry() - UR = UriRegistry(registryconfig['applications'], registryconfig['uri_templates']) + UR = UriRegistry( + registryconfig["applications"], registryconfig["uri_templates"] + ) r.registerUtility(UR, IUriRegistry) UR2 = _build_uri_registry(r, registryconfig) assert UR == UR2 diff --git a/tests/test_registry_error.cfg b/tests/test_registry_error.cfg index cb77045..18f91eb 100644 --- a/tests/test_registry_error.cfg +++ b/tests/test_registry_error.cfg @@ -1,32 +1,32 @@ -{wrong: [ - { - "id": "1", - "base_uri": "http://id.erfgoed.net/foobar", - "applications": ["1", "2"] - }, - { - "id": "2", - "base_uri": "http://id.erfgoed.net/bar/", - "applications": ["1"] - }, - { - "id": "3", - "base_uri": "http://id.erfgoed.net/foo/", - "applications": ["2"] - } - ], -'notation': [ - { - "id": "1", - "name": "app1", - "url": "http://localhost:5555", - "uri": "http://localhost:5555" - }, - { - "id": "2", - "name": "app2", - "url": "http://localhost:2222", - "uri": "http://localhost:2222" - } - ] +{wrong : [ + { + "id": "1", + "base_uri": "http://id.erfgoed.net/foobar", + "applications": ["1", "2"] + }, + { + "id": "2", + "base_uri": "http://id.erfgoed.net/bar/", + "applications": ["1"] + }, + { + "id": "3", + "base_uri": "http://id.erfgoed.net/foo/", + "applications": ["2"] + } + ], +'notation' : [ + { + "id": "1", + "name": "app1", + "url": "http://localhost:5555", + "uri": "http://localhost:5555" + }, + { + "id": "2", + "name": "app2", + "url": "http://localhost:2222", + "uri": "http://localhost:2222" + } + ] } \ No newline at end of file diff --git a/tests/test_utils.py b/tests/test_utils.py index 45b07f5..150ad5d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,6 @@ -from uriregistry.models import Application from pyramid_urireferencer.models import ApplicationResponse +from uriregistry.models import Application from uriregistry.utils import query_application @@ -8,10 +8,12 @@ class TestUtils: def test_get_application_response(self): uri = "http://id.erfgoed.net/foobar/2" - app = Application('http://www.app.net', "app_name", "http://www.app.net/references") + app = Application( + "http://www.app.net", "app_name", "http://www.app.net/references" + ) r = query_application(app, uri) assert isinstance(r, ApplicationResponse) assert r.uri == app.uri assert r.service_url == app.service_url assert r.title == app.title - assert r.success == False + assert r.success is False diff --git a/tests/test_views.py b/tests/test_views.py index dc1615b..9da2798 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -1,10 +1,9 @@ import pytest - from pyramid import testing -from pyramid.response import Response from pyramid.httpexceptions import HTTPBadRequest - -from pyramid_urireferencer.models import RegistryResponse, ApplicationResponse +from pyramid.response import Response +from pyramid_urireferencer.models import ApplicationResponse +from pyramid_urireferencer.models import RegistryResponse @pytest.fixture @@ -16,6 +15,7 @@ class TestViews: def test_home(self, pyramid_request): from uriregistry.views import RegistryView + v = RegistryView(pyramid_request) res = v.home() assert isinstance(res, Response) @@ -23,14 +23,16 @@ def test_home(self, pyramid_request): def test_get_references_no_uri(self, pyramid_request, uriregistry): pyramid_request.uri_registry = uriregistry from uriregistry.views import RegistryView + v = RegistryView(pyramid_request) with pytest.raises(HTTPBadRequest): - res = v.get_references() + v.get_references() def test_get_references_uri(self, pyramid_request, uriregistry): pyramid_request.uri_registry = uriregistry - pyramid_request.params = {'uri': 'http://id.erfgoed.net/foo/1'} + pyramid_request.params = {"uri": "http://id.erfgoed.net/foo/1"} from uriregistry.views import RegistryView + v = RegistryView(pyramid_request) res = v.get_references() assert isinstance(res, RegistryResponse) @@ -41,20 +43,30 @@ def test_get_references_uri(self, pyramid_request, uriregistry): def test_get_registry_response(): from uriregistry.views import _get_registry_response + uri = "http://id.erfgoed.net/foobar/2/" - app_response_success_ref = ApplicationResponse("app2_name", "http://uri/app2", "http://url/app2", True, True, 2, []) - app_response_success_ref2 = ApplicationResponse("app2_name", "http://uri/app2", "http://url/app2", True, True, 3, - []) - app_response_nosuccess = ApplicationResponse("app2_name", "http://uri/app2", "http://url/app2", False, None, None, - None) - app_response_nosuccess2 = ApplicationResponse("app2_name", "http://uri/app2", "http://url/app2", False, None, None, - None) - app_response_success_noref = ApplicationResponse("app2_name", "http://uri/app2", "http://url/app2", True, False, - None, None) - app_response_success_noref2 = ApplicationResponse("app2_name", "http://uri/app2", "http://url/app2", True, False, - None, None) - - r = _get_registry_response([app_response_success_ref, app_response_success_ref2], uri) + app_response_success_ref = ApplicationResponse( + "app2_name", "http://uri/app2", "http://url/app2", True, True, 2, [] + ) + app_response_success_ref2 = ApplicationResponse( + "app2_name", "http://uri/app2", "http://url/app2", True, True, 3, [] + ) + app_response_nosuccess = ApplicationResponse( + "app2_name", "http://uri/app2", "http://url/app2", False, None, None, None + ) + app_response_nosuccess2 = ApplicationResponse( + "app2_name", "http://uri/app2", "http://url/app2", False, None, None, None + ) + app_response_success_noref = ApplicationResponse( + "app2_name", "http://uri/app2", "http://url/app2", True, False, None, None + ) + app_response_success_noref2 = ApplicationResponse( + "app2_name", "http://uri/app2", "http://url/app2", True, False, None, None + ) + + r = _get_registry_response( + [app_response_success_ref, app_response_success_ref2], uri + ) assert isinstance(r, RegistryResponse) assert len(r.applications) == 2 assert r.query_uri == uri @@ -70,7 +82,9 @@ def test_get_registry_response(): assert not r.success assert r.count == 2 - r = _get_registry_response([app_response_success_noref, app_response_success_noref2], uri) + r = _get_registry_response( + [app_response_success_noref, app_response_success_noref2], uri + ) assert isinstance(r, RegistryResponse) assert len(r.applications) == 2 assert r.query_uri == uri @@ -78,7 +92,9 @@ def test_get_registry_response(): assert r.success assert r.count == 0 - r = _get_registry_response([app_response_success_noref, app_response_success_noref2], uri) + r = _get_registry_response( + [app_response_success_noref, app_response_success_noref2], uri + ) assert isinstance(r, RegistryResponse) assert len(r.applications) == 2 assert r.query_uri == uri diff --git a/tim_test.py b/tim_test.py new file mode 100644 index 0000000..272b848 --- /dev/null +++ b/tim_test.py @@ -0,0 +1,26 @@ +# Requirements +import json + +req = [ + "requests==2.32.3", + "pyramid==2.0.2", + "pyyaml==6.0.1", + "pyramid_urireferencer==0.8.0", +] + +# Dev Requirements +dev_req = [ + "sphinx==7.3.7", + "sphinxcontrib-httpdomain==1.8.1", + "sphinxcontrib-plantuml==0.30", + "waitress==3.0.0", + "pyramid_debugtoolbar==4.12.1", + "pytest==8.2.2", + "pytest-cov==5.0.0", + "webtest==3.0.0", + "httpretty==1.1.4", + "coveralls==4.0.1", +] + +print(json.dumps(sorted(req), indent=4, sort_keys=True)) +print(json.dumps(sorted(dev_req), indent=4, sort_keys=True)) diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 0bb3e3b..0000000 --- a/tox.ini +++ /dev/null @@ -1,18 +0,0 @@ -[tox] -envlist = py27, py33, py34, py35, cover - -[testenv] -commands = - pip install -r requirements-dev.txt - python setup.py develop - py.test tests -setenv = - LC_ALL = en_US.utf-8 - -[testenv:cover] -basepython = - python2.7 -commands = - pip install -r requirements-dev.txt - python setup.py develop - py.test --cov uriregistry --cov-report term-missing tests diff --git a/uriregistry/__init__.py b/uriregistry/__init__.py index e5993f1..3a02b08 100644 --- a/uriregistry/__init__.py +++ b/uriregistry/__init__.py @@ -1,11 +1,13 @@ -import os -import yaml import logging +import os +import yaml from pyramid.config import Configurator -from .models import Application, UriTemplate -from .registry import get_uri_registry, _build_uri_registry +from .models import Application # NoQa +from .models import UriTemplate # NoQa +from .registry import _build_uri_registry # NoQa +from .registry import get_uri_registry # NoQa log = logging.getLogger(__name__) @@ -19,22 +21,25 @@ def _parse_settings(settings): log.debug(settings) - prefix = 'uriregistry' + prefix = "uriregistry" defaults = { - 'config': os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'sample.yaml')) + "config": os.path.abspath( + os.path.join(os.path.dirname(__file__), "..", "sample.yaml") + ) } urireg_settings = defaults.copy() - for short_key_name in ('config',): - key_name = f'{prefix}.{short_key_name}' + for short_key_name in ("config",): + key_name = f"{prefix}.{short_key_name}" if key_name in settings: - urireg_settings[short_key_name] = \ - settings.get(key_name, defaults.get(short_key_name, None)) + urireg_settings[short_key_name] = settings.get( + key_name, defaults.get(short_key_name, None) + ) for short_key in urireg_settings: - long_key = f'{prefix}.{short_key}' + long_key = f"{prefix}.{short_key}" settings[long_key] = urireg_settings[short_key] return urireg_settings @@ -47,7 +52,7 @@ def _load_configuration(path): :param str path: Path to the config file in YAML format. :returns: A :class:`dict` with the config options. """ - log.debug('Loading uriregistry config from %s.' % path) + log.debug("Loading uriregistry config from %s." % path) f = open(path) content = yaml.full_load(f.read()) log.debug(content) @@ -66,19 +71,20 @@ def main(global_config, **settings): urireg_settings = _parse_settings(config.registry.settings) - registryconfig = _load_configuration(urireg_settings['config']) + registryconfig = _load_configuration(urireg_settings["config"]) _build_uri_registry(config.registry, registryconfig) - config.add_directive('get_uri_registry', get_uri_registry) - config.add_request_method(get_uri_registry, 'uri_registry', reify=True) + config.add_directive("get_uri_registry", get_uri_registry) + config.add_request_method(get_uri_registry, "uri_registry", reify=True) from pyramid_urireferencer.renderers import json_renderer - config.add_renderer('json', json_renderer) - config.add_static_view('static', 'static', cache_max_age=3600) - config.add_route('home', '/') - config.add_route('references', '/references') + config.add_renderer("json", json_renderer) + + config.add_static_view("static", "static", cache_max_age=3600) + config.add_route("home", "/") + config.add_route("references", "/references") config.scan() return config.make_wsgi_app() diff --git a/uriregistry/registry.py b/uriregistry/registry.py index e33ed7e..f77d2f3 100644 --- a/uriregistry/registry.py +++ b/uriregistry/registry.py @@ -13,13 +13,17 @@ class UriRegistry: Central registry that tracks uris and the applications they are being used in. """ - def __init__(self, applications=[], uris=[]): - self.applications = [Application(app['uri'], app['name'], app['service_url']) for app in applications] + def __init__(self, applications=[], uris=[]): # NoQa + self.applications = [ + Application(app["uri"], app["name"], app["service_url"]) + for app in applications + ] self.uris = [ UriTemplate( - u['match_uri'], - [app for app in self.applications if app.uri in u['applications']] - ) for u in uris + u["match_uri"], + [app for app in self.applications if app.uri in u["applications"]], + ) + for u in uris ] def get_applications(self, uri): @@ -47,8 +51,7 @@ def _build_uri_registry(registry, registryconfig): return uri_registry uri_registry = UriRegistry( - registryconfig['applications'], - registryconfig['uri_templates'] + registryconfig["applications"], registryconfig["uri_templates"] ) registry.registerUtility(uri_registry, IUriRegistry) @@ -63,7 +66,7 @@ def get_uri_registry(registry): :rtype: :class:`uriregistry.registry.UriRegistry` """ # Argument might be a config or request - regis = getattr(registry, 'registry', None) + regis = getattr(registry, "registry", None) if regis is None: regis = registry return regis.queryUtility(IUriRegistry) diff --git a/uriregistry/utils.py b/uriregistry/utils.py index 9036a62..546a2ff 100644 --- a/uriregistry/utils.py +++ b/uriregistry/utils.py @@ -1,6 +1,6 @@ import logging -import requests +import requests from pyramid_urireferencer.models import ApplicationResponse log = logging.getLogger(__name__) @@ -15,9 +15,13 @@ def query_application(app, uri): :rtype pyramid_urireferencer.models.ApplicationResponse: """ try: - r = requests.get(app.service_url, params={'uri': uri}) + r = requests.get(app.service_url, params={"uri": uri}) a = ApplicationResponse.load_from_json(r.json()) return a - except Exception as e: - log.error(f'Could not check if uri {uri} is known to app {app.title} (uri: {app.uri})') - return ApplicationResponse(app.title, app.uri, app.service_url, False, None, None, None) + except Exception: + log.error( + f"Could not check if uri {uri} is known to app {app.title} (uri: {app.uri})" + ) + return ApplicationResponse( + app.title, app.uri, app.service_url, False, None, None, None + ) diff --git a/uriregistry/views.py b/uriregistry/views.py index 3e69739..3b45c5d 100644 --- a/uriregistry/views.py +++ b/uriregistry/views.py @@ -22,14 +22,14 @@ class RestView(ApplicationView): class RegistryView(RestView): - @view_config(route_name='references', renderer='json', accept='application/json') + @view_config(route_name="references", renderer="json", accept="application/json") def get_references(self): """ Collect the references for a URI and relay them to the client. """ - uri = self.request.params.get('uri', None) + uri = self.request.params.get("uri", None) if not uri: - raise HTTPBadRequest('Please include a URI parameter.') + raise HTTPBadRequest("Please include a URI parameter.") applications = self.request.uri_registry.get_applications(uri) if not applications: @@ -40,12 +40,12 @@ def get_references(self): return _get_registry_response(application_responses, uri) - @view_config(route_name='home', request_method='GET') + @view_config(route_name="home", request_method="GET") def home(self): """ The root information page """ - return Response(service_info, content_type='text/plain', status_int=200) + return Response(service_info, content_type="text/plain", status_int=200) service_info = """UriRegistry: what are my uri's up to?""" @@ -55,7 +55,7 @@ def _get_registry_response(application_responses, uri): """ Generate the final response by aggregating all the application responses. - :param list application_responses: All :class:`pyramid_urireferencer.models.ApplicationResponse` instances. + :param list application_responses: All ApplicationResponse instances. :param str uri: Uri that was evaluated :param str base_uri: Base uri of the uri that was evaluated :return: :class:`pyramid_urireferencer.models.RegistryResponse` with all \