Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • P Python SDK
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 1
    • Issues 1
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Open Subsurface Data Universe SoftwareOpen Subsurface Data Universe Software
  • Platform
  • System
  • SDKs
  • Python SDK
  • Issues
  • #15
Closed
Open
Issue created Nov 03, 2022 by Yan Sushchynski (EPAM)@Yan_SushchynskiMaintainer

ADR: Static code analysis for Python libraries

Context

Python is a dynamically typed language, so developers don't need to worry about types. This works well if a project is small and a few developers work on it.

However, once the project gets bigger, and involves a lot of engineers, understanding how code works becomes the cornerstone of the further development. Python has type annotations designed to help developers to understand code. Now, these type annotations in our Python libraries are kind of hints for developers and their IDEs, but following them is not mandatory, and they can be simply ignored.

As a result, we face issues when some methods are called with arguments with wrong types. And these bugs unexpectedly show in runtime under certain conditions. It is not so rare to get the following runtime error: AttributeError: 'dict' object has no attribute 'to_JSON'

However, these bugs could be easily catch with any static analyzer.

Decision

Add a static analysis step for type checking to CI/CD pipelines right before unit-tests. The step will be run on the container with preinstalled tools for Python static analysis (e.g., pytype or mypy).

At first, we are going to add static analysis to the following libraries:

  1. https://community.opengroup.org/osdu/platform/system/sdks/common-python-sdk/-/tree/master/osdu_api - excluding CSP-specific code from osdu_api/providers;
  2. https://community.opengroup.org/osdu/platform/data-flow/ingestion/osdu-ingestion-lib;
  3. https://community.opengroup.org/osdu/platform/data-flow/ingestion/osdu-airflow-lib.

Further, we can cover other Python libraries with static analysis.

Consequences

Pros:

  1. It will be much easier to catch subtle bugs without writing extra unit-tests;
  2. Developers will be forced to follow type annotations that will make code more readable and understandable.

Cons:

  1. The existing code should be refactored to pass static analysis validations;
  2. Some developers might find obeying these new rules too strict.
Edited Nov 03, 2022 by Yan Sushchynski (EPAM)
Assignee
Assign to
Time tracking