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

Move datadog_checks_base code into sub base package #2167

Merged
merged 6 commits into from
Sep 14, 2018

Conversation

nmuesch
Copy link
Collaborator

@nmuesch nmuesch commented Sep 4, 2018

What does this PR do?

Creates a base package in datadog_checks_base and moves the existing code into that package.

Also updates all the imports to include the new addition of .base.

Motivation

Since we use the datadog_checks namespace for all of our checks, they need to have the same __init__.py file. Currently the init file for the datadog_checks_base includes the version of the base package. When a new check gets installed, since the new check shares the namespace, the init file can be overwritten by the contents of the new check's file. There is additionally a warning about this in the python packaging docs - https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages

The solution here is to make the init file identical to the rest, and move the base code into its own sub package where the version lives in that packages init file.

Review checklist

  • PR has a meaningful title or PR has the no-changelog label attached
  • Feature or bugfix has tests
  • Git history is clean
  • If PR impacts documentation, docs team has been notified or an issue has been opened on the documentation repo

Additional Notes

We will need to do this for integrations-extras as well. This is the script I made/used to update the imports:

from __future__ import print_function
import fileinput
from os.path import join, expanduser
import os


INTEGRATIONS_CORE=expanduser('~/git/integrations-core')
INTEGRATIONS_EXTRAS=expanduser('~/git/integrations-extras')
OLD_IMPORT_PREFIX = 'datadog_checks.'
NEW_IMPORT_PREFIX = OLD_IMPORT_PREFIX+'base.'

files_updating = []

MOVED_IMPORTS = [
    'checks',
    'utils',
    'data',
    'stubs',
    'config',
    'errors',
    'log'
]

for root, dirs, files in os.walk(INTEGRATIONS_CORE):
    for file in files:
        if file.endswith(".py") or file.endswith(".md") or file.endswith(".txt"):
             files_updating.append(os.path.join(root, file))

for file in files_updating:
    f = fileinput.FileInput(file, inplace=True)
    for line in f:
        for replaceline in MOVED_IMPORTS:
            line = line.replace(OLD_IMPORT_PREFIX+replaceline,NEW_IMPORT_PREFIX+replaceline)
        print(line, end="")
    f.close()

@nmuesch nmuesch force-pushed the nick/make_dd_cheks_base_package branch from a244d34 to fcd00b9 Compare September 13, 2018 13:57
@ofek ofek mentioned this pull request Sep 14, 2018
@zippolyte
Copy link
Contributor

zippolyte commented Sep 17, 2018

Replacing Fixed with no-changelog since this was reverted. It appeared on my vSphere changelog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants