diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2bf0c2e..cf9056c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -61,11 +61,18 @@ jobs: python-version-file: 'pyproject.toml' cache: 'pip' + - name: Install Poetry + run: | + curl -sSL https://install.python-poetry.org | python3 - + echo "$HOME/.local/bin" >> $GITHUB_PATH # Add Poetry to PATH + + - name: Install dependencies + run: | + poetry install --without dev --no-interaction --no-root + - name: Run tests run: | - pip install --upgrade pip - pip install -e . - python -m pytest + poetry run pytest # Use Poetry to run your tests build: needs: [detectenv, run-tests] @@ -82,11 +89,18 @@ jobs: python-version-file: 'pyproject.toml' cache: 'pip' + - name: Install Poetry + run: | + curl -sSL https://install.python-poetry.org | python3 - + echo "$HOME/.local/bin" >> $GITHUB_PATH # Add Poetry to PATH + + - name: Install dependencies + run: | + poetry install --without dev,test --no-interaction --no-root # Install only main dependencies + - name: Build SDK run: | - pip install --upgrade pip - pip install -e . - python -m build + poetry build # Use Poetry to build the project - name: Release uses: ncipollo/release-action@v1 diff --git a/.gitignore b/.gitignore index 201b91a..ed6d915 100644 --- a/.gitignore +++ b/.gitignore @@ -97,6 +97,9 @@ __pypackages__/ # Test output test-output.xml +# Poetry +poetry.lock + # VS Code .vscode/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6b9e556 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: + - repo: https://github.com/psf/black + rev: 24.8.0 + hooks: + - id: black diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 22424ad..427aa72 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,12 @@ Here are some resources to help you get started with open source contributions: ### Contribution guidelines ### -* Create new branch from develop +* Clone the repository or Create new branch from develop +* Navigate to the project root directory +* Setup pre-commit hook + * poetry install - Installs all dependencies, including pre-commit + * poetry run pre-commit install - Installs pre-commit hooks +* Write code * Write tests * Create a PR * Code review diff --git a/pyproject.toml b/pyproject.toml index 98012e3..e4c07d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,32 +1,44 @@ -[project] +[tool.poetry] name = "omnia_timeseries" version = "1.3.13" -authors = [ - { name = "Equinor Omnia Industrial IoT Team", email = "omniaindiot@equinor.com" } -] description = "Official Python SDK for the Omnia Timeseries API" readme = "README.md" -requires-python = ">=3.8,<4.0" +authors = ["Equinor Omnia Industrial IoT Team "] +license = "LICENSE" -dependencies =[ -"requests", -"azure-identity >=1.19.0", -"azure-core", -"opentelemetry-instrumentation-requests >=0.48b0,<1.0.0", -"opentelemetry-api >=1.27.0,<2.0.0", -"cryptography >=43.0.1", -"pyjwt >=2.9.0" -] +[tool.poetry.dependencies] +python = ">=3.8,<4.0" +requests = ">=2.28.0,<3.0.0" +azure-identity = ">=1.19.0,<2.0.0" +azure-core = ">=1.30.0,<2.0.0" +opentelemetry-instrumentation-requests = ">=0.54b1,<1.0.0" +opentelemetry-api = ">=1.27.0,<2.0.0" +cryptography = ">=43.0.1,<45.0.0" +pyjwt = ">=2.9.0,<3.0.0" [tool.poetry.group.test.dependencies] -pytest = "*" -requests-mock = "*" +pytest = ">=7.4.0,<8.0.0" +requests-mock = ">=1.9.0,<2.0.0" [tool.poetry.group.dev.dependencies] +pre-commit = ">=3.0.0,<5.0.0" +black = ">=22.0,<26.0" -[project.urls] +[tool.poetry.urls] repository = "https://github.com/equinor/omnia-timeseries-python" +[tool.black] +line-length = 88 +target-version = ['py39'] +include = '\.pyi?$' +exclude = '^/src/version.py' +extend-exclude = ''' +( +^/foo.py +| .*_pb2.py +) +''' + [build-system] requires = ["poetry-core>=2.0,<3.0"] build-backend = "poetry.core.masonry.api" diff --git a/src/omnia_timeseries/http_client.py b/src/omnia_timeseries/http_client.py index ca44b6a..11f9b31 100644 --- a/src/omnia_timeseries/http_client.py +++ b/src/omnia_timeseries/http_client.py @@ -1,4 +1,4 @@ -from typing import Literal, Optional, TypedDict, Union, Dict, Any +from typing import Literal, List, Optional, Union, Dict, Any from azure.identity._internal.msal_credentials import MsalCredential import requests import logging @@ -31,7 +31,7 @@ def _request( request_type: RequestType, url: str, headers: Dict[str, Any], - payload: Optional[Union[TypedDict, dict, list]] = None, + payload: Optional[Union[Dict, Dict, List]] = None, params: Optional[Dict[str, Any]] = None, ) -> Union[Dict[str, Any], bytes]: @@ -40,7 +40,7 @@ def _request( ) if not response.ok: raise TimeseriesRequestFailedException(response) - if not "Accept" in headers or headers["Accept"] == "application/json": + if "Accept" not in headers or headers["Accept"] == "application/json": return response.json() else: return response.content @@ -56,7 +56,7 @@ def request( request_type: RequestType, url: str, accept: ContentType = "application/json", - payload: Optional[Union[TypedDict, dict, list]] = None, + payload: Optional[Union[Dict, Dict, List]] = None, params: Optional[Dict[str, Any]] = None, ) -> Any: