Skip to content

Bump requests from 2.31.0 to 2.32.0 #26

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

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
64adfcc
tidy up
mikeAdamss Nov 28, 2023
2df182c
poetry not pipenv
mikeAdamss Nov 28, 2023
fd390c8
simplify table
mikeAdamss Nov 28, 2023
dde0974
fix table
mikeAdamss Nov 28, 2023
560a4ff
poetry not pipenv
mikeAdamss Nov 28, 2023
c6ab98f
sort out test runner
mikeAdamss Nov 28, 2023
889ac56
add missing coverage.rc
mikeAdamss Nov 28, 2023
5e99a23
tidy up comments
mikeAdamss Nov 28, 2023
90ac71a
remove bad type hint
mikeAdamss Nov 28, 2023
1538b81
All imports working
Moasib-Arif Dec 20, 2023
ac96694
Minor changes
Moasib-Arif Dec 20, 2023
06d8300
movedd pipfiles
Moasib-Arif Dec 20, 2023
01f9423
moved pipfiles
Moasib-Arif Dec 20, 2023
c6e435e
Minor changes
Moasib-Arif Jan 3, 2024
e34f671
Merge pull request #7 from GSS-Cogs/1-Installable
Moasib-Arif Jan 4, 2024
ff0fee8
Error test not working
Moasib-Arif Jan 4, 2024
efab255
merged into main
Moasib-Arif Jan 4, 2024
fe17166
minor chnages
Moasib-Arif Jan 4, 2024
9cc33fd
Working HTTP Client
Moasib-Arif Jan 5, 2024
628194b
Minor changes
Moasib-Arif Jan 5, 2024
2705d52
Added all the imports
Moasib-Arif Jan 8, 2024
6aaad33
updated pycurl
Moasib-Arif Jan 8, 2024
4b3b006
Minor changes
Moasib-Arif Jan 8, 2024
977bd4f
removed import
Moasib-Arif Jan 8, 2024
bae9186
Comments addressed
Moasib-Arif Jan 8, 2024
ecbd25e
Draft PR
SarahJohnsonONS Jan 9, 2024
fd4e86f
string and integer classes
NickPapONS Jan 11, 2024
bbcee5f
Http client uses requests library
Moasib-Arif Jan 15, 2024
4fe4e83
Made the Requested Changes
Moasib-Arif Jan 15, 2024
b1fcc3f
simple logging implementation
mikeAdamss Jan 15, 2024
8a1a7ee
add raw
mikeAdamss Jan 15, 2024
00c29ea
Merge pull request #8 from GSS-Cogs/3-HTTP-Client
Moasib-Arif Jan 17, 2024
514e3b8
Salck Notification Working
Moasib-Arif Jan 22, 2024
2813ec6
Added tests
Moasib-Arif Jan 22, 2024
b255396
Tests added
SarahJohnsonONS Jan 22, 2024
345ab01
Added timezone to `created_at` datetime
SarahJohnsonONS Jan 22, 2024
a878a81
Tidy up
SarahJohnsonONS Jan 22, 2024
5c8fe55
Made the requested changes
Moasib-Arif Jan 23, 2024
41d4c92
Fixed typo
SarahJohnsonONS Jan 24, 2024
d1eb522
Merge branch 'main' into #4-implement-logger
SarahJohnsonONS Jan 24, 2024
b11c30a
Setting up verified commits
SarahJohnsonONS Jan 25, 2024
5f79568
Merge pull request #9 from GSS-Cogs/#4-implement-logger
SarahJohnsonONS Jan 25, 2024
90848d8
Adding tests and more config work
NickPapONS Jan 29, 2024
3d57b8b
Merge pull request #10 from GSS-Cogs/5-Slack-Notification
Moasib-Arif Jan 30, 2024
dd309c6
Merge branch 'main' into #config-class
NickPapONS Feb 2, 2024
0a09940
Config and tests completed
NickPapONS Feb 2, 2024
98de26c
Addressing feedback
NickPapONS Feb 6, 2024
affdfdd
Fixing forgotten variable names
NickPapONS Feb 7, 2024
5b6105a
Fixing unit tests again
NickPapONS Feb 7, 2024
ff4e4c3
Forgot a test
NickPapONS Feb 7, 2024
497feba
validate_json_schema() function
SarahJohnsonONS Feb 7, 2024
1b1dcec
Addressing new feedback
NickPapONS Feb 8, 2024
0f38bf0
#21 Config class
NickPapONS Feb 8, 2024
e64697a
PR comments addressed
SarahJohnsonONS Feb 9, 2024
1fd2372
Merge branch 'main' into #17-validate-json
SarahJohnsonONS Feb 9, 2024
34b3202
Changes made
SarahJohnsonONS Feb 9, 2024
f265ae8
Merge pull request #23 from GSS-Cogs/#17-validate-json
SarahJohnsonONS Feb 9, 2024
09b6af5
dependabot[bot] May 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
python-version: '3.9'

- name: Install pipenv
run: pip install pipenv
run: pip install poetry

- name: Install test dependencies
run: pipenv sync --dev
run: poetry install

- name: Run Pytest
run: pipenv run pytest --cov-report term-missing --cov=src --cov-config=./tests/coverage.rc ./tests/
run: poetry run pytest --cov-report term-missing --cov=src --cov-config=./tests/coverage.rc ./tests/
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.coverage
.venv
.DS_Store
*.pyc
.vscode
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"python.testing.pytestArgs": [
"tests",
"dpytools"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"test_*.py"
],
}
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

fmt: ## (Format) - runs black and isort against the codebase (auto triggered on pre-commit)
pipenv run black ./src/*
pipenv run isort ./src/*
fmt: ## (Format) - runs black and isort against the codebase
poetry run black ./dpytools/*
poetry run isort ./dpytools/*

lint: ## Run the ruff python linter (auto triggered on pre-commit)
pipenv run ruff ./src/*
lint: ## Run the ruff python linter
poetry run ruff ./dpytools/*

test: ## Run pytest and check test coverage (auto triggered on pre-push)
pipenv run pytest --cov-report term-missing --cov=src --cov-config=./tests/coverage.rc
test: ## Run pytest and check test coverage
poetry run pytest --cov-report term-missing --cov=dpytools
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@ Simple reusable python resources for digital publishing.

## Installation

**TODO**
Follow these steps to install the package on your local machine:

1. **Install the package**

Open your terminal and run the following command:

```bash
pip install git+https://github.com/GSS-Cogs/dp-python-tools.git
```


## Usage

The following clients, helpers etc are availible upon installation of this package.

| Name | Import | Description |
| ----- | ---------------- | ------ |
| [config](./dpytools/config/README.md) | `from dpytools import Config` | A simple validating configuration class |
| Name | Description |
| ----- | ---------------- |
| [Config](./dpytools/config/README.md) | A simple validating configuration class |
**TODO** - all helpers and clients to appear in this list.

The usage instructions please see the readme in the appropriate sub directory, this can also be access by clicking the link in the "name" column above.

## Development

All commits that make it to PR should have black and ruff already ran against them, you can do this via `make fmt`.
`
All commits that make it to PR should have black and ruff already ran against them, you can do this via `make fmt` and you can lint via `make lint`.

For a full list of functionality provided by the makefile just run a naked `make`.

### Repository Organization

Each client, helper etc should be a sub directory of `./dpytools`. Separation between these sub codebaes should be maintained as much as possible aginst the day where we want to break some or all of these tools out into separate repositories.
Each client, helper etc should be a sub directory of `./dpytools`. Separation between these sub codebases should be maintained as much as possible aginst the day where we want to break some or all of these tools out into separate repositories.
5 changes: 0 additions & 5 deletions dpytools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from http.http import HttpClient
from config.config import Config
from logger.logger import logger
from slack.slack import SlackNotifier
from sns.sns import Subscription, publish
94 changes: 71 additions & 23 deletions dpytools/config/config.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,87 @@
from typing import Dict
from __future__ import annotations

from properties.base import BaseProperty
import os
from typing import Any, Dict, List

from .properties.base import BaseProperty
from .properties.intproperty import IntegerProperty
from .properties.string import StringProperty


class Config:
def __init__(self):
self._properties_to_validate: List[BaseProperty] = []

@staticmethod
def from_env(config_dict: Dict[str, BaseProperty]):
# TODO = read in and populate property classes as
# per the example in the main readme.
# You need to populate with dot notation in mind so:
#
# StringProperty("fieldname", "fieldvalue")
#
# should be accessed on Config/self, so:
#
# value = config.fieldvalue.value
# i.e
# config.fieldvalue = StringProperty("fieldname", "fieldvalue")
#
# Worth looking at the __setattr_ dunder method and a loop
# for how to do this.
#
# Do track the BaseProperty's that you add ready for
# assert_valid_config call.
...
def from_env(config_dict: Dict[str, Dict[str, Any]]) -> Config:
config = Config()

for env_var_name, value in config_dict.items():
value_for_property = os.environ.get(env_var_name, None)
assert (
value_for_property is not None
), f'Required envionrment value "{env_var_name}" could not be found.'

if value["class"] == StringProperty:
if value["kwargs"]:
regex = value["kwargs"].get("regex")
min_len = value["kwargs"].get("min_len")
max_len = value["kwargs"].get("max_len")
else:
regex = None
min_len = None
max_len = None

stringprop = StringProperty(
_name=value["property"],
_value=value_for_property,
regex=regex,
min_len=min_len,
max_len=max_len,
)

prop_name = value["property"]
setattr(config, prop_name, stringprop)
config._properties_to_validate.append(stringprop)

elif value["class"] == IntegerProperty:
if value["kwargs"]:
min_val = value["kwargs"].get("min_val")
max_val = value["kwargs"].get("max_val")
else:
min_val = None
max_val = None

intprop = IntegerProperty(
_name=value["property"],
_value=value_for_property,
min_val=min_val,
max_val=max_val,
)

prop_name = value["property"]
setattr(config, prop_name, intprop)
config._properties_to_validate.append(intprop)

else:
prop_type = value["class"]
raise TypeError(
f"Unsupported property type specified via 'property' field, got {prop_type}. Should be of type StringProperty or IntegerProperty"
)

return config

def assert_valid_config(self):
"""
Assert that then Config class has the properties that
provided properties.
"""
for property in self._properties_to_validate:
property.type_is_valid()
property.secondary_validation()

self._properties_to_validate = []

# For each of the properties you imbided above, run
# self.type_is_valid()
# self.secondary_validation()


3 changes: 2 additions & 1 deletion dpytools/config/properties/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from string import StringProperty
from .intproperty import IntegerProperty
from .string import StringProperty
38 changes: 25 additions & 13 deletions dpytools/config/properties/base.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
from abc import ABCMeta, abstractmethod
from dataclasses import dataclass
from typing import Any, Union, Tuple, Optional
from typing import Any


@dataclass
class BaseProperty(meta=ABCMeta):
name: str
value: Any
class BaseProperty(metaclass=ABCMeta):
_name: str
_value: Any

@property
def name(self):
return self._name

# TODO: getter
# allow someone to get the property
@name.setter
def name(self, value):
raise ValueError(
f"Trying to change name property to value {value} but you cannot change a property name after instantiation."
)

# TODO: setter
# categorically disallow anyone from
# changing a property after the class
# has been instantiated.
# Refuse to do it, and log an error.
@property
def value(self):
return self._value

@value.setter
def value(self, value):
raise ValueError(
f"Trying to change value to {value} but you cannot change a property value after instantiation."
)

@abstractmethod
def type_is_valid(self):
"""
Validate that the property looks like
its of the correct type
its of the correct type
"""
...

Expand All @@ -32,4 +44,4 @@ def secondary_validation(self):
Non type based validation you might want to
run against a configuration value.
"""
...
...
40 changes: 40 additions & 0 deletions dpytools/config/properties/intproperty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from dataclasses import dataclass
from typing import Optional

from .base import BaseProperty


@dataclass
class IntegerProperty(BaseProperty):
min_val: Optional[int]
max_val: Optional[int]

def type_is_valid(self):
"""
Validate that the property looks like
its of the correct type
"""
try:
int(self._value)
except Exception as err:
raise Exception(
f"Cannot cast {self._name} value {self._value} to integer."
) from err

def secondary_validation(self):
"""
Non type based validation you might want to
run against a configuration value of this kind.
"""
if not self._value:
raise ValueError(f"Integer value for {self._name} does not exist.")

if self.min_val and self._value < self.min_val:
raise ValueError(
f"Integer value for {self._name} is lower than allowed minimum."
)

if self.max_val and self._value > self.max_val:
raise ValueError(
f"Integer value for {self._name} is higher than allowed maximum."
)
40 changes: 27 additions & 13 deletions dpytools/config/properties/string.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
import re
from dataclasses import dataclass
from typing import Optional

from base import BaseProperty
from .base import BaseProperty


@dataclass
class StringProperty(BaseProperty):
regex: Optional[str]
min_len: Optional[int]
max_len: Optional[int]

def type_is_valid(self) -> Optional[Exception]:
def type_is_valid(self):
"""
Validate that the property looks like
its of the correct type
its of the correct type
"""
try:
str(self.value)
str(self._value)
except Exception as err:
raise Exception(f"Cannot cast {self.name} value {self.value} to string.") from err
raise Exception(
f"Cannot cast {self.name} value {self._value} to string."
) from err

def secondary_validation_passed(self) -> Optional[Exception]:
def secondary_validation(self):
"""
Non type based validation you might want to
run against a configuration value of this kind.
"""
if len(self.value) == 0:

if len(self._value) == 0:
raise ValueError(f"Str value for {self.name} is an empty string")

if self.regex:
# TODO - confirm the value matches the regex
...
regex_search = re.search(self.regex, self._value)
if not regex_search:
raise ValueError(
f"Str value for {self.name} does not match the given regex."
)

if self.min_len:
# TODO - confirm the string matches of exceeds the minimum length
...
if len(self._value) < self.min_len:
raise ValueError(
f"Str value for {self.name} is shorter than minimum length {self.min_len}"
)

if self.max_len:
# TODO - confirm the value matches or is less than the max length
...
if len(self._value) > self.max_len:
raise ValueError(
f"Str value for {self.name} is longer than maximum length {self.max_len}"
)
Loading
Loading