diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..4ffcf24 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,32 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: unconfirmed +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Run command '...' +3. Scroll down to '...' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**System (please complete the following information):** +- `VOLTTRON SQL Historian` version: [e.g. 0.2.1] +- Python version: [e.g. 3.8] +- OS: [Windows/Linux] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..4fe86d5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: feature +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/auto-assign-project.yml b/.github/workflows/auto-assign-project.yml new file mode 100644 index 0000000..8427606 --- /dev/null +++ b/.github/workflows/auto-assign-project.yml @@ -0,0 +1,22 @@ +name: Add bugs to bugs project + +on: + issues: + types: + - opened + +jobs: + add-to-project: + name: Add issue to project + runs-on: ubuntu-latest + steps: + - uses: actions/add-to-project@v0.3.0 + with: + # You can target a repository in a different organization + # to the issue + project-url: https://github.com/orgs/eclipse-volttron/projects/3 + # project-url: https://github.com/orgs//projects/ + # github-token: ${{ secrets.ADD_TO_PROJECT_PAT }} + github-token: ${{ secrets.AUTO_PROJECT_PAT }} + # labeled: bug, needs-triage + # label-operator: OR \ No newline at end of file diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml new file mode 100644 index 0000000..e64de06 --- /dev/null +++ b/.github/workflows/code-analysis.yml @@ -0,0 +1,70 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ main, develop, releases ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ main, develop, releases ] + schedule: + - cron: '34 10 * * 4' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 \ No newline at end of file diff --git a/.github/workflows/deploy-pre-release.yml b/.github/workflows/deploy-pre-release.yml new file mode 100644 index 0000000..518fbe1 --- /dev/null +++ b/.github/workflows/deploy-pre-release.yml @@ -0,0 +1,125 @@ +name: Deploy Pre-Release Artifacts + +on: + push: + branches: + - develop + +defaults: + run: + shell: bash + +env: + LANG: en_US.utf-8 + LC_ALL: en_US.utf-8 + PYTHON_VERSION: '3.10' + PROJECT_NAME: volttron-lib-sql-historian + POETRY_VERSION: '1.2.2' + +jobs: + + deploy-pre-release: + runs-on: ubuntu-22.04 + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + + #---------------------------------------------- + # check-out repo and set-up python + #---------------------------------------------- + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Python ${{ env.PYTHON_VERSION }} + id: setup-python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + #---------------------------------------------- + # ----- install & configure poetry ----- + #---------------------------------------------- + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: ${{ env.POETRY_VERSION }} + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + + #---------------------------------------------- + # load cached venv if cache exists + #---------------------------------------------- + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} + + #---------------------------------------------- + # install dependencies if cache does not exist + #---------------------------------------------- + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root + + #---------------------------------------------- + # install your root project, if required + #---------------------------------------------- + - name: Install library + run: | + poetry install --no-interaction + + #---------------------------------------------- + # bump version number for patch + #---------------------------------------------- + - name: Bump Version + run: | + # current_tag is the last tagged release in the repository. From there + # we need to remove the v from the beginning of the tag. + if ! $(git tag -l "v*" = ''); then + # uses -V which is version sort to keep it monotonically increasing. + current_tag=$(git tag -l "v*" | grep --invert-match '-' | sort --reverse -V | sed -n 1p) + else + current_tag=v0.1.0 + fi + + current_tag=${current_tag#?} + + # current_tag is now the version we want to set our poetry version so + # that we can bump the version + poetry version ${current_tag} + poetry version prerelease --no-interaction + + NEW_TAG=v$(poetry version --short) + + # Finally because we want to be able to use the variable in later + # steps we set a NEW_TAG environmental variable + echo "NEW_TAG=$(echo ${NEW_TAG})" >> $GITHUB_ENV + + #--------------------------------------------------------------- + # create build artifacts to be included as part of release + #--------------------------------------------------------------- + - name: Create build artifacts + run: | + poetry build -vvv + + - uses: ncipollo/release-action@v1 + with: + artifacts: "dist/*.gz,dist/*.whl" + artifactErrorsFailBuild: true + generateReleaseNotes: true + commit: ${{ github.ref }} + prerelease: true + tag: ${{ env.NEW_TAG }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish pre-release to pypi + if: github.repository == "eclipse-volttron/${{env.PROJECT_NAME}}" + run: | + poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} + poetry publish diff --git a/.github/workflows/downstream-test-response.yml b/.github/workflows/downstream-test-response.yml new file mode 100644 index 0000000..8ad1116 --- /dev/null +++ b/.github/workflows/downstream-test-response.yml @@ -0,0 +1,24 @@ +name: Respond to downstream test runs as part of downstream testing + + +on: + repository_dispatch: + # To add more test responses from volttron modular repos, + # put the name of the event type in the list below. + # The name of the event type should come from Workflow + # that is triggering this workflow. + # For example, 'VOLTTRON/volttron-listener-agent` repo has a workflow + # called downstream-testing-dispatch.yml that will send a repository + # dispatch to this repo using with an event type called "listener-downstream-testing-response" + types: [listener-downstream-testing-response] + +jobs: + test-response: + runs-on: ubuntu-22.04 + + steps: + - name: Repository Dispatch Triggered + run: | + echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + echo "Event '${{ github.event.action }}' received from '${{ github.event.client_payload.repository }}'" + echo "Payload from downstream workflow: '${{ toJson(github.event.client_payload) }}'" \ No newline at end of file diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml new file mode 100644 index 0000000..b378626 --- /dev/null +++ b/.github/workflows/publish-to-pypi.yml @@ -0,0 +1,40 @@ +--- +# Documentation located +# https://github.com/marketplace/actions/publish-python-poetry-package +name: Publish to PyPi + +on: + release: + types: [published] + +defaults: + run: + shell: bash + +env: + LANG: en_US.utf-8 + LC_ALL: en_US.utf-8 + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} + +jobs: + + publish_to_pypi: + + runs-on: ubuntu-22.04 + + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Build and publish to pypi + uses: JRubics/poetry-publish@v1.7 + with: + # These are only needed when using test.pypi + #repository_name: testpypi + #repository_url: https://test.pypi.org/legacy/ + pypi_token: ${{ secrets.PYPI_TOKEN }} + ignore_dev_requirements: "yes" diff --git a/.github/workflows/run-downstream-tests.yml b/.github/workflows/run-downstream-tests.yml new file mode 100644 index 0000000..dddaa2f --- /dev/null +++ b/.github/workflows/run-downstream-tests.yml @@ -0,0 +1,88 @@ +name: Start downstream tests + +on: + push: + branches: + - main + pull_request: + branches: + - develop + +env: + LANG: en_US.utf-8 + LC_ALL: en_US.utf-8 + PYTHON_VERSION: '3.10' + EVENT_TYPE: downstream-testing + +jobs: + initiate_downstream_testing: + strategy: + matrix: + # To add more Volttron modular repos that need to be tested against a version of volttron-core, + # add the name of repo to the list below. + # The name of the repo takes the following form: / + # For example, to add the OpenADR agent repo, use the following name: + # VOLTTRON/volttron-openadr-ven + repo: [ eclipse-volttron/volttron-sqlite-historian ] + # , 'VOLTTRON/volttron-openadr-ven' ] + + runs-on: ubuntu-22.04 + + steps: + - run: env + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + + #---------------------------------------------- + # check-out repo and set-up python + #---------------------------------------------- + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Python ${{ env.PYTHON_VERSION }} + id: setup-python + uses: actions/setup-python@v2 + with: + python-version: ${{ env.PYTHON_VERSION }} + + #---------------------------------------------- + # ----- install & configure poetry ----- + #---------------------------------------------- + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + + #---------------------------------------------- + # install your root project, if required + #---------------------------------------------- + - name: Install library + run: poetry install --no-interaction + + - name: Create build artifacts + run: | + poetry build -vvv + + - name: Check if wheels were built + run: | + ls -lh dist + + - name: Upload wheels as artifact + uses: actions/upload-artifact@v2 + with: + name: dist + path: dist + + - run: echo "Workflow run_id ${{ github.run_id }}" + + - name: Repository Dispatch + uses: peter-evans/repository-dispatch@v1.1.3 + with: + token: ${{ secrets.ACTION_HOOK_TOKEN }} + repository: ${{ matrix.repo }} + event-type: ${{ env.EVENT_TYPE }} + client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}", "repository": "${{ github.repository }}", "api_url": "${{ github.api_url }}", "run_id": "${{ github.run_id }}" }' \ No newline at end of file diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..444eb91 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,96 @@ +name: Run Pytests + +on: + push: + paths: + - '**.py' + - '**.yaml' + - '**.yml' + - '**.toml' + pull_request: + types: + - opened + - synchronize + - reopened + paths: + - '**.py' + +defaults: + run: + shell: bash + +env: + LANG: en_US.utf-8 + LC_ALL: en_US.utf-8 + PYTHON_VERSION: '3.10' + PROJECT_NAME: volttron-lib-base-historian + +jobs: + + run-tests: + strategy: + matrix: + os: [ubuntu-20.04, ubuntu-22.04] + python: ['3.8', '3.9', '3.10'] + + runs-on: ${{ matrix.os }} + + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + + #---------------------------------------------- + # check-out repo and set-up python + #---------------------------------------------- + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python }} + id: setup-python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + + #---------------------------------------------- + # ----- install & configure poetry ----- + #---------------------------------------------- + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.2.2 + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + +# #---------------------------------------------- +# # load cached venv if cache exists +# #---------------------------------------------- +# - name: Load cached venv +# id: cached-poetry-dependencies +# uses: actions/cache@v2.1.7 +# with: +# path: .venv +# key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} +# #---------------------------------------------- +# # install dependencies if cache does not exist +# #---------------------------------------------- +# - name: Install dependencies +# if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' +# run: poetry install --no-interaction --no-root + + #---------------------------------------------- + # install your root project, and run tests. + #---------------------------------------------- + - name: Check file existence + id: check_files + uses: andstor/file-existence-action@v2 + with: + files: tests + + - name: Install library and run tests + if: steps.check_files.outputs.files_exists == 'true' + run: | + poetry install --no-interaction + poetry add --group dev pytest-github-actions-annotate-failures + poetry run pytest --cov=src tests/ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..00ac7c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,138 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +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/ + +# 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 +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.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/ + +.idea/ + +*secret +config_*.json +.DS_Store +AUTHORS +ChangeLog +poetry.lock diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4140453 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,50 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks + +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: check-yaml + - id: check-json + - id: check-toml + - id: check-xml + - id: forbid-new-submodules + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-merge-conflict + - id: no-commit-to-branch # blocks main commits. To bypass do git commit --allow-empty + - id: pretty-format-json + +# For more information about mypy, see https://github.com/pre-commit/mirrors-mypy +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.910-1 + hooks: + - id: mypy + exclude: ^(docs/|example-plugin/|tests/fixtures|tests/conftest.py) + files: ^src/ + +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.2.0 + hooks: + - id: pretty-format-toml + args: [--autofix] + - id: pretty-format-yaml + args: [--autofix] + exclude: .copier-answer.yml + +# For more information about YAPF, see https://github.com/google/yapf +- repo: https://github.com/craig8/mirrors-yapf + rev: b84f670025671a341d0afd2b06b877b195d65c0f # Use the sha / tag you want to point at + hooks: + - id: yapf + name: yapf + description: A formatter for Python files. + entry: yapf + language: python + types: [python] + +- repo: https://github.com/python-poetry/poetry + rev: 1.2.2 + hooks: + - id: poetry-check diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9464da7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,216 @@ +Copyright 2022 Battelle Memorial Institute + +Licensed under the Apache License, Version 2.0 (the "License"); you may not +use this file except in compliance with the License. You may obtain a copy +of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +License for the specific language governing permissions and limitations +under the License. + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 73690f9..76f8011 100644 --- a/README.md +++ b/README.md @@ -1,117 +1,48 @@ -# VOLTTRON SQL Historian +[![pypi version](https://img.shields.io/pypi/v/volttron-lib-sql-historian.svg)](https://pypi.org/project/volttron-lib-sql-historian/) +![Passing?](https://github.com/VOLTTRON/volttron-lib-sql-historian/actions/workflows/run-tests.yml/badge.svg) -[![ci](https://github.com/VOLTTRON/volttron-sql-historian/workflows/ci/badge.svg)](https://github.com/VOLTTRON/volttron-sql-historian/actions?query=workflow%3Aci) -[![documentation](https://img.shields.io/badge/docs-mkdocs%20material-blue.svg?style=flat)](https://VOLTTRON.github.io/volttron-sql-historian/) -[![pypi version](https://img.shields.io/pypi/v/volttron-sql-historian.svg)](https://pypi.org/project/volttron-sql-historian/) +Generic SQL Historian library that can be used to implement a historian agent with a relational database backend. +This library cannot be installed as a VOLTTRON agent as is. Only a concrete database implementation package such as +[sqlite-historian](https://github.com/eclipse-volttron/volttron-sqlitehistorian) that depends on this library can be +installed as a VOLTTRON agent. +## Requirements -None + - Python >= 3.8 -## Prerequisites +## Installation -* Python 3.8 -* Poetry +This library can be installed using ```pip install volttron-lib-sql-historian```. However, this is not necessary. Any +historian agent that uses this library will automatically install it as part of its installation. For example, +installing [SQLiteHistorian](https://github.com/eclipse-volttron/volttron-sqlitehistorian) will automatically install +volttron-lib-sql-historian -### Python -VOLTTRON SQL Historian requires Python 3.8 or above. +## Development +Please see the following for contributing guidelines [contributing](https://github.com/eclipse-volttron/volttron-core/blob/develop/CONTRIBUTING.md). -To install Python 3.8, we recommend using [pyenv](https://github.com/pyenv/pyenv). +Please see the following helpful guide about [developing modular VOLTTRON agents](https://github.com/eclipse-volttron/volttron-core/blob/develop/DEVELOPING_ON_MODULAR.md) -```bash -# install pyenv -git clone https://github.com/pyenv/pyenv ~/.pyenv +To create a new relational database based historian by extending this library, subclass +[DBDriver](https://github.com/eclipse-volttron/volttron-lib-sql-historian/blob/develop/src/historian/sql/basedb.py#L79). +The subclass should be in a module historian..functs.py for it to be dynamically loaded +by the base DBDriver. Please refer to [SQLiteHistorian](https://github.com/eclipse-volttron/volttron-sqlitehistorian) as +an example -# setup pyenv (you should also put these three lines in .bashrc or similar) -export PATH="${HOME}/.pyenv/bin:${PATH}" -export PYENV_ROOT="${HOME}/.pyenv" -eval "$(pyenv init -)" +# Disclaimer Notice -# install Python 3.8 -pyenv install 3.8.10 +This material was prepared as an account of work sponsored by an agency of the +United States Government. Neither the United States Government nor the United +States Department of Energy, nor Battelle, nor any of their employees, nor any +jurisdiction or organization that has cooperated in the development of these +materials, makes any warranty, express or implied, or assumes any legal +liability or responsibility for the accuracy, completeness, or usefulness or any +information, apparatus, product, software, or process disclosed, or represents +that its use would not infringe privately owned rights. -# make it available globally -pyenv global system 3.8.10 -``` - -### Poetry - -This project uses `poetry` to install and manage dependencies. To install poetry, -follow these [instructions](https://python-poetry.org/docs/master/#installation). - - - -## Installation and Virtual Environment Setup - -If you want to install all your dependencies, including dependencies to help with developing your agent, run this command: - -```poetry install``` - -If you want to install only the dependencies needed to run your agent, run this command: - -```poetry install --no-dev``` - -Set the environment to be in your project directory: - -```poetry config virtualenvs.in-project true``` - -Activate the virtual environment: - -```poetry shell``` - - -## Git Setup - -1. To use git to manage version control, create a new git repository in your local agent project. - -``` -git init -``` - -2. Then create a new repo in your Github or Gitlab account. Copy the URL that points to that new repo in -your Github or Gitlab account. This will be known as our 'remote'. - -3. Add the remote (i.e. the new repo URL from your Github or Gitlab account) to your local repository. Run the following command: - -```git remote add origin ``` - -When you push to your repo, note that the default branch is called 'main'. - - -## Optional Configurations - -## Precommit - -Install pre-commit hooks: - -```pre-commit install``` - -To run pre-commit on all your files, run this command: - -```pre-commit run --all-files``` - -If you have precommit installed and you want to ignore running the commit hooks -every time you run a commit, include the `--no-verify` flag in your commit. The following -is an example: - -```git commit -m "Some message" --no-verify``` - -# Documentation - -To build the docs, navigate to the 'docs' directory and build the documentation: - -```shell -cd docs -make html -``` - -After the documentation is built, view the documentation in html form in your browser. -The html files will be located in `~/docs/build/html`. - -**PROTIP: To open the landing page of your documentation directly from the command line, run the following command:** - -```shell -open /docs/build/html/index.html -``` - -This will open the documentation landing page in your default browsert (e.g. Chrome, Firefox). +Reference herein to any specific commercial product, process, or service by +trade name, trademark, manufacturer, or otherwise does not necessarily +constitute or imply its endorsement, recommendation, or favoring by the United +States Government or any agency thereof, or Battelle Memorial Institute. The +views and opinions of authors expressed herein do not necessarily state or +reflect those of the United States Government or any agency thereof. diff --git a/config b/config deleted file mode 100644 index 0966014..0000000 --- a/config +++ /dev/null @@ -1,10 +0,0 @@ -{ - # VOLTTRON config files are JSON with support for python style comments. - "setting1": 2, # Integers - "setting2": "some/random/topic2", #Strings - "setting3": true, # Booleans: remember that in JSON true and false are not capitalized. - "setting4": false, - "setting5": 5.1, # Floating point numbers. - "setting6": [1,2,3,4], #Lists - "setting7": {"setting7a": "a", "setting7b": "b"} #Objects -} diff --git a/docs/source/conf.py b/docs/source/conf.py index 59a00f8..bc4b17e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,3 +1,27 @@ +# -*- coding: utf-8 -*- {{{ +# ===----------------------------------------------------------------------=== +# +# Installable Component of Eclipse VOLTTRON +# +# ===----------------------------------------------------------------------=== +# +# Copyright 2022 Battelle Memorial Institute +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# ===----------------------------------------------------------------------=== +# }}} + # Configuration file for the Sphinx documentation builder. # -- Project information diff --git a/pyproject.toml b/pyproject.toml index e938768..b7fcd4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,22 +1,28 @@ +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" +git-changelog = ">=0.5.0" +httpx = ">=0.16.1" +jinja2-cli = ">=0.7.0" +toml = ">=0.10.2" + [tool.poetry] -name = "volttron-sql-historian" -version = "0.1.0" -description = "None" -authors = ["VOLTTRON "] +name = "volttron-lib-sql-historian" +version = "0.2.0-rc" +description = "A library for supporting sql based historians." +authors = ["VOLTTRON Team "] license = "Apache License 2.0" readme = "README.md" -repository = "https://github.com/VOLTTRON/volttron-sql-historian" -homepage = "https://github.com/VOLTTRON/volttron-sql-historian" +repository = "https://github.com/eclipse-volttron/volttron-lib-sql-historian" +homepage = "https://github.com/eclipse-volttron/volttron-lib-sql-historian" keywords = [] -packages = [ { include = "volttron", from = "src" } ] +packages = [ { include = "historian", from = "src" } ] [tool.poetry.dependencies] python = ">=3.8,<4.0" -# TODO: uncomment when volttron 0.1.0 is available -# volttron = "^0.1.0" +volttron-lib-base-historian = "^0.2.0rc0" -[tool.poetry.dev-dependencies] -# formatting, quality, tests +[tool.poetry.group.dev.dependencies] pytest = "^6.2.5" mock = "^4.0.3" pre-commit = "^2.17.0" @@ -26,10 +32,15 @@ isort = "^5.10.1" safety = "^1.10.3" mypy = "^0.942" coverage = "^6.3.2" +pytest-cov = "^3.0.0" Sphinx = "^4.5.0" sphinx-rtd-theme = "^1.0.0" -volttron-base-historian = {path = "../volttron-base-historian", develop = true} -volttron-testing = {path = "../volttron-testing", develop = true} + +[tool.yapf] +based_on_style = "pep8" +spaces_before_comment = 4 +column_limit = 99 +split_before_logical_operator = true [tool.yapfignore] ignore_patterns = [ @@ -38,22 +49,3 @@ ignore_patterns = [ "dist/**", "docs/**" ] - -[tool.yapf] -based_on_style = "pep8" -spaces_before_comment = 4 -column_limit = 99 -split_before_logical_operator = true - -[tool.poetry.scripts] -volttron-sql-historian = "volttron.historian.sql.agent:main" - -[build-system] -requires = ["poetry-core>=1.0.0"] -build-backend = "poetry.core.masonry.api" - -# tasks -git-changelog = ">=0.5.0" -httpx = ">=0.16.1" -jinja2-cli = ">=0.7.0" -toml = ">=0.10.2" diff --git a/src/historian/sql/__init__.py b/src/historian/sql/__init__.py new file mode 100644 index 0000000..f7b8e51 --- /dev/null +++ b/src/historian/sql/__init__.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- {{{ +# ===----------------------------------------------------------------------=== +# +# Installable Component of Eclipse VOLTTRON +# +# ===----------------------------------------------------------------------=== +# +# Copyright 2022 Battelle Memorial Institute +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# ===----------------------------------------------------------------------=== +# }}} + +""" +VOLTTRON SQL Historian package. + +None + +""" + +from typing import List +from historian.sql.basedb import DbDriver + +__all__: List[str] = [ + "DbDriver", +] # noqa: WPS410 (the only __variable__ we use) diff --git a/src/volttron/historian/sql/basedb.py b/src/historian/sql/basedb.py similarity index 92% rename from src/volttron/historian/sql/basedb.py rename to src/historian/sql/basedb.py index 4430a4c..9418352 100644 --- a/src/volttron/historian/sql/basedb.py +++ b/src/historian/sql/basedb.py @@ -1,42 +1,27 @@ # -*- coding: utf-8 -*- {{{ -# vim: set fenc=utf-8 ft=python sw=4 ts=4 sts=4 et: +# ===----------------------------------------------------------------------=== # -# Copyright 2022, Battelle Memorial Institute. +# Installable Component of Eclipse VOLTTRON # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# ===----------------------------------------------------------------------=== # -# http://www.apache.org/licenses/LICENSE-2.0 +# Copyright 2022 Battelle Memorial Institute # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 # -# This material was prepared as an account of work sponsored by an agency of -# the United States Government. Neither the United States Government nor the -# United States Department of Energy, nor Battelle, nor any of their -# employees, nor any jurisdiction or organization that has cooperated in the -# development of these materials, makes any warranty, express or -# implied, or assumes any legal liability or responsibility for the accuracy, -# completeness, or usefulness or any information, apparatus, product, -# software, or process disclosed, or represents that its use would not infringe -# privately owned rights. Reference herein to any specific commercial product, -# process, or service by trade name, trademark, manufacturer, or otherwise -# does not necessarily constitute or imply its endorsement, recommendation, or -# favoring by the United States Government or any agency thereof, or -# Battelle Memorial Institute. The views and opinions of authors expressed -# herein do not necessarily state or reflect those of the -# United States Government or any agency thereof. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. # -# PACIFIC NORTHWEST NATIONAL LABORATORY operated by -# BATTELLE for the UNITED STATES DEPARTMENT OF ENERGY -# under Contract DE-AC05-76RL01830 +# ===----------------------------------------------------------------------=== # }}} - import contextlib import importlib import logging diff --git a/src/volttron/historian/sql/historian.py b/src/historian/sql/historian.py similarity index 89% rename from src/volttron/historian/sql/historian.py rename to src/historian/sql/historian.py index 9a4608a..360a18d 100644 --- a/src/volttron/historian/sql/historian.py +++ b/src/historian/sql/historian.py @@ -1,49 +1,34 @@ # -*- coding: utf-8 -*- {{{ -# vim: set fenc=utf-8 ft=python sw=4 ts=4 sts=4 et: +# ===----------------------------------------------------------------------=== # -# Copyright 2022, Battelle Memorial Institute. +# Installable Component of Eclipse VOLTTRON # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# ===----------------------------------------------------------------------=== # -# http://www.apache.org/licenses/LICENSE-2.0 +# Copyright 2022 Battelle Memorial Institute # -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 # -# This material was prepared as an account of work sponsored by an agency of -# the United States Government. Neither the United States Government nor the -# United States Department of Energy, nor Battelle, nor any of their -# employees, nor any jurisdiction or organization that has cooperated in the -# development of these materials, makes any warranty, express or -# implied, or assumes any legal liability or responsibility for the accuracy, -# completeness, or usefulness or any information, apparatus, product, -# software, or process disclosed, or represents that its use would not infringe -# privately owned rights. Reference herein to any specific commercial product, -# process, or service by trade name, trademark, manufacturer, or otherwise -# does not necessarily constitute or imply its endorsement, recommendation, or -# favoring by the United States Government or any agency thereof, or -# Battelle Memorial Institute. The views and opinions of authors expressed -# herein do not necessarily state or reflect those of the -# United States Government or any agency thereof. +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. # -# PACIFIC NORTHWEST NATIONAL LABORATORY operated by -# BATTELLE for the UNITED STATES DEPARTMENT OF ENERGY -# under Contract DE-AC05-76RL01830 +# ===----------------------------------------------------------------------=== # }}} - import logging import sys import threading from volttron import utils -from volttron.historian.base import BaseHistorian -from volttron.historian.sql import sqlutils +from historian.base import BaseHistorian +from historian.sql import sqlutils #from volttron.utils. import doc_inherit __version__ = "4.0.0" diff --git a/src/historian/sql/sqlutils.py b/src/historian/sql/sqlutils.py new file mode 100644 index 0000000..ffe8379 --- /dev/null +++ b/src/historian/sql/sqlutils.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- {{{ +# ===----------------------------------------------------------------------=== +# +# Installable Component of Eclipse VOLTTRON +# +# ===----------------------------------------------------------------------=== +# +# Copyright 2022 Battelle Memorial Institute +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# ===----------------------------------------------------------------------=== +# }}} + +import inspect +import logging + +from volttron import utils +from historian.sql import DbDriver + +utils.setup_logging() +_log = logging.getLogger(__name__) + + +def get_dbfuncts_class(database_type): + mod_name = database_type + "functs" + mod_name_path = f"historian.{database_type}.{mod_name}" + loaded_mod = __import__(mod_name_path, fromlist=[mod_name]) + for _, cls in inspect.getmembers(loaded_mod): + # Ensure class is not the root dbdriver + if (inspect.isclass(cls) and issubclass(cls, DbDriver) + and cls is not DbDriver): + break + else: + raise Exception('Invalid module named {}'.format(mod_name_path)) + _log.debug('Historian using module: {}'.format(cls.__name__)) + return cls diff --git a/src/volttron/historian/sql/__init__.py b/src/volttron/historian/sql/__init__.py deleted file mode 100644 index 956e251..0000000 --- a/src/volttron/historian/sql/__init__.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- {{{ -# vim: set fenc=utf-8 ft=python sw=4 ts=4 sts=4 et: -# -# Copyright 2022, Battelle Memorial Institute. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This material was prepared as an account of work sponsored by an agency of -# the United States Government. Neither the United States Government nor the -# United States Department of Energy, nor Battelle, nor any of their -# employees, nor any jurisdiction or organization that has cooperated in the -# development of these materials, makes any warranty, express or -# implied, or assumes any legal liability or responsibility for the accuracy, -# completeness, or usefulness or any information, apparatus, product, -# software, or process disclosed, or represents that its use would not infringe -# privately owned rights. Reference herein to any specific commercial product, -# process, or service by trade name, trademark, manufacturer, or otherwise -# does not necessarily constitute or imply its endorsement, recommendation, or -# favoring by the United States Government or any agency thereof, or -# Battelle Memorial Institute. The views and opinions of authors expressed -# herein do not necessarily state or reflect those of the -# United States Government or any agency thereof. -# -# PACIFIC NORTHWEST NATIONAL LABORATORY operated by -# BATTELLE for the UNITED STATES DEPARTMENT OF ENERGY -# under Contract DE-AC05-76RL01830 -# }}} -""" -VOLTTRON SQL Historian package. - -None - -""" - -from typing import List -from volttron.historian.sql.basedb import DbDriver - -__all__: List[str] = [ - "DbDriver", -] # noqa: WPS410 (the only __variable__ we use) diff --git a/src/volttron/historian/sql/sqlutils.py b/src/volttron/historian/sql/sqlutils.py deleted file mode 100644 index 4f7d83d..0000000 --- a/src/volttron/historian/sql/sqlutils.py +++ /dev/null @@ -1,60 +0,0 @@ -# -*- coding: utf-8 -*- {{{ -# vim: set fenc=utf-8 ft=python sw=4 ts=4 sts=4 et: -# -# Copyright 2022, Battelle Memorial Institute. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# This material was prepared as an account of work sponsored by an agency of -# the United States Government. Neither the United States Government nor the -# United States Department of Energy, nor Battelle, nor any of their -# employees, nor any jurisdiction or organization that has cooperated in the -# development of these materials, makes any warranty, express or -# implied, or assumes any legal liability or responsibility for the accuracy, -# completeness, or usefulness or any information, apparatus, product, -# software, or process disclosed, or represents that its use would not infringe -# privately owned rights. Reference herein to any specific commercial product, -# process, or service by trade name, trademark, manufacturer, or otherwise -# does not necessarily constitute or imply its endorsement, recommendation, or -# favoring by the United States Government or any agency thereof, or -# Battelle Memorial Institute. The views and opinions of authors expressed -# herein do not necessarily state or reflect those of the -# United States Government or any agency thereof. -# -# PACIFIC NORTHWEST NATIONAL LABORATORY operated by -# BATTELLE for the UNITED STATES DEPARTMENT OF ENERGY -# under Contract DE-AC05-76RL01830 -# }}} -import inspect -import logging - -from volttron import utils -from volttron.historian.sql import DbDriver - -utils.setup_logging() -_log = logging.getLogger(__name__) - - -def get_dbfuncts_class(database_type): - mod_name = database_type + "functs" - mod_name_path = f"volttron.historian.{database_type}.{mod_name}" - loaded_mod = __import__(mod_name_path, fromlist=[mod_name]) - for _, cls in inspect.getmembers(loaded_mod): - # Ensure class is not the root dbdriver - if (inspect.isclass(cls) and issubclass(cls, DbDriver) - and cls is not DbDriver): - break - else: - raise Exception('Invalid module named {}'.format(mod_name_path)) - _log.debug('Historian using module: {}'.format(cls.__name__)) - return cls