Skip to content
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

Extract apiclient from dmutils #1

Merged
merged 11 commits into from
Dec 30, 2015
Merged

Conversation

allait
Copy link
Contributor

@allait allait commented Dec 29, 2015

Copy apiclient modules and tests from digitalmarketplace-utils

(https://github.com/alphagov/digitalmarketplace-utils/tree/63531bd4d2c1bed8774fef04aaf3ac8f71d341db)

Add dmutils.audit and audit types tests from digitalmarketplace-utils

Audit event types enum is used only for the API client calls, so it
makes sense to group it with the API client module.

Rewrite apiclient tests to avoid dmutils.request_id dependency

Tests for request headers were using the dmutils.request_id module
to set up the Request class with .request_id attribute. Since the
test is supposed to check that API client is setting the header on
the API request, we can configure the Flask request object directly
instead of relying on request_id.init_app.

Use dmapiclient package name instead of dmutils namespacing

Using dmutils namespace with namespace_packages requires removing
all code from dmutils.__init__, which is currently acting as an
import proxy for third-party packages. Removing __init__.py will
break app imports, which is the main reason for package namespacing.

Instead, we create a new package name dmapiclient, which allows us
to simplify the directory structure by removing the nested apiclient
package. The existing dmutils.apiclient import path can be preserved
by adding import dmapiclient as apiclient to dmutils/__init__.py.

Audit event types enum is used only for the API client calls, so it
makes sense to group it with the API client module.
Tests for request headers were using the `dmutils.request_id` module
to set up the Request class with `.request_id` attribute. Since the
test is supposed to check that API client is setting the header on
the API request, we can configure the Flask request object directly
instead of relying on `request_id.init_app`.
Using setuptools namespace_packages to keep the existing apiclient
import paths.

(https://pythonhosted.org/setuptools/setuptools.html#namespace-packages)

This makes any code in `dmutils/__init__.py` inaccessible from the
installed package, so we need to move the version tag to `dmutils.apiclient`.

Having a constant declaration above module-level imports triggers a pep8 warning
without `noqa`, even though `__version__` should be declared after the module docstring
(https://www.python.org/dev/peps/pep-0008/#version-bookkeeping).
Using dmutils namespace with namespace_packages requires removing
all code from `dmutils.__init__`, which is currently acting as an
import proxy for third-party packages. Removing `__init__.py` will
break app imports, which is the main reason for package namespacing.

Instead, we create a new package name `dmapiclient`, which allows us
to simplify the directory structure by removing the nested `apiclient`
package. The existing `dmutils.apiclient` import path can be preserved
by adding `import dmapiclient as apiclient` to `dmutils/__init__.py`.

## What's in here?

Digital Marketplace Data and Search API clients
Copy link
Contributor

Choose a reason for hiding this comment

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

This could do with a bit more info. Maybe just an example and links to the other relevant repos.

@robyoung
Copy link
Contributor

Other than the README point this looks ace 👍 🙏 (that's meant to be a high five)

@allait allait force-pushed the extract-apiclient-from-dmutils branch from 90584fb to c56a169 Compare December 30, 2015 14:51
@allait
Copy link
Contributor Author

allait commented Dec 30, 2015

Expanded the README a bit and added CHANGELOG.md for 1.0.0

allait added a commit that referenced this pull request Dec 30, 2015
@allait allait merged commit 48bb4a8 into master Dec 30, 2015
@allait allait deleted the extract-apiclient-from-dmutils branch December 30, 2015 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants