Skip to content

chore: add Prettier action, cleanup workflow, format files #60

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 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*Issue #, if available:*

*Description of changes:*
_Issue #, if available:_

_Description of changes:_

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
70 changes: 39 additions & 31 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,51 @@
name: Python package

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
types: [opened, synchronize, ready_for_review]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r dev-requirements.txt
pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Lint with PyLint
run: pylint --rcfile=.pylintrc src/aws_secretsmanager_caching
- name: Check formatting with Ruff
uses: astral-sh/ruff-action@v3
- name: Test with pytest
run: |
pytest test/unit/
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
- name: Checkout
uses: actions/checkout@v4

- name: Check formatting with Ruff
uses: astral-sh/ruff-action@v3

- name: Prettier
uses: rutajdash/[email protected]
with:
file_pattern: "**/*.{md,yml}"

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r dev-requirements.txt
pip install -e .

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Lint with PyLint
run: pylint --rcfile=.pylintrc src/aws_secretsmanager_caching

- name: Test with pytest
run: pytest test/unit/

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ disable = I0011, # locally-disabled
# (visual studio) and html
output-format=colorized


[FORMAT]
# Maximum number of characters on a single line.
max-line-length=120
Expand Down
5 changes: 3 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Code of Conduct
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact

This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
[email protected] with any additional questions or comments.
45 changes: 25 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,63 @@
# Contributing Guidelines

Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
documentation, we greatly value feedback and contributions from our community.

Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
information to effectively respond to your bug report or contribution.


## Reporting Bugs/Feature Requests

We welcome you to use the GitHub issue tracker to report bugs or suggest features.

When filing an issue, please check [existing open](https://github.com/aws/aws-secretsmanager-caching-python/issues), or [recently closed](https://github.com/aws/aws-secretsmanager-caching-python/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
When filing an issue, please check [existing open](https://github.com/aws/aws-secretsmanager-caching-python/issues), or [recently closed](https://github.com/aws/aws-secretsmanager-caching-python/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:

* A reproducible test case or series of steps
* The version of our code being used
* Any modifications you've made relevant to the bug
* Anything unusual about your environment or deployment

- A reproducible test case or series of steps
- The version of our code being used
- Any modifications you've made relevant to the bug
- Anything unusual about your environment or deployment

## Contributing via Pull Requests

Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:

1. You are working against the latest source on the *master* branch.
1. You are working against the latest source on the _master_ branch.
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.

To send us a pull request, please:

1. Fork the repository.
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
3. Ensure local tests pass.
4. Commit to your fork using clear commit messages.
5. Send us a pull request, answering any default questions in the pull request interface.
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
3. Use Ruff to ensure consistent formatting for `.py` files, and Prettier for `.md` and `.yml` files (see [Formatting instructions](#formatting-instructions)).
4. Ensure local tests pass.
5. Commit to your fork using clear commit messages.
6. Send us a pull request, answering any default questions in the pull request interface.
7. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.

GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).

## Formatting instructions

- Install [Ruff](https://docs.astral.sh/ruff/installation/) and [Prettier](https://prettier.io/docs/install).
- If using VS Code, install the VS Code extensions for the above.
- Run `ruff format` and `prettier --write **/*.{md,yml}`, or configure VS Code to format on save using Ruff and Prettier.

## Finding contributions to work on
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws/aws-secretsmanager-caching-python/labels/help%20wanted) issues is a great place to start.

Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws/aws-secretsmanager-caching-python/labels/help%20wanted) issues is a great place to start.

## Code of Conduct
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
[email protected] with any additional questions or comments.

This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
[email protected] with any additional questions or comments.

## Security issue notifications
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.

If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.

## Licensing

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The AWS Secrets Manager Python caching client enables in-process caching of secr

To use this client you must have:

- Python 3.8 or newer. Use of Python versions 3.7 or older are not supported.
- Python 3.9 or newer. Use of Python versions 3.8 or older are not supported.
- An Amazon Web Services (AWS) account to access secrets stored in AWS Secrets Manager.

- **To create an AWS account**, go to [Sign In or Create an AWS Account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) and then choose **I am a new user.** Follow the instructions to create an AWS account.
Expand Down
42 changes: 21 additions & 21 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@
import os
import shutil

project = u'AWS Secrets Manager Python Caching Client'
project = "AWS Secrets Manager Python Caching Client"

# If you use autosummary, this ensures that any stale autogenerated files are
# cleaned up first.
if os.path.exists('_autosummary'):
if os.path.exists("_autosummary"):
print("cleaning up stale autogenerated files...")
shutil.rmtree('_autosummary')
shutil.rmtree("_autosummary")

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.coverage',
'sphinx.ext.doctest',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.coverage",
"sphinx.ext.doctest",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

source_suffix = '.rst' # The suffix of source filenames.
master_doc = 'index' # The master toctree document.
source_suffix = ".rst" # The suffix of source filenames.
master_doc = "index" # The master toctree document.

copyright = u'%s, Amazon.com' % datetime.now().year
copyright = "%s, Amazon.com" % datetime.now().year

# The full version, including alpha/beta/rc tags.
release = version('aws_secretsmanager_caching')
release = version("aws_secretsmanager_caching")

# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['_build', '_templates']
exclude_trees = ["_build", "_templates"]

pygments_style = 'sphinx'
pygments_style = "sphinx"

autoclass_content = "both"
autodoc_default_flags = ['show-inheritance', 'members', 'undoc-members']
autodoc_member_order = 'bysource'
autodoc_default_flags = ["show-inheritance", "members", "undoc-members"]
autodoc_member_order = "bysource"

html_theme = 'haiku'
html_static_path = ['_static']
htmlhelp_basename = '%sdoc' % project
html_theme = "haiku"
html_static_path = ["_static"]
htmlhelp_basename = "%sdoc" % project

# autosummary
autosummary_generate = True
1 change: 1 addition & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
line-length = 120
21 changes: 10 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
packages=find_packages(where="src", exclude=("test",)),
package_dir={"": "src"},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7'
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
keywords='secretsmanager secrets manager development cache caching client',
keywords="secretsmanager secrets manager development cache caching client",
use_scm_version=True,
python_requires='>=3.8',
install_requires=['botocore'],
setup_requires=['pytest-runner', 'setuptools-scm'],
tests_require=['pytest', 'pytest-cov', 'pytest-sugar', 'codecov']

python_requires=">=3.8",
install_requires=["botocore"],
setup_requires=["pytest-runner", "setuptools-scm"],
tests_require=["pytest", "pytest-cov", "pytest-sugar", "codecov"],
)
13 changes: 11 additions & 2 deletions src/aws_secretsmanager_caching/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""High level AWS Secrets Manager caching client."""

from aws_secretsmanager_caching.config import SecretCacheConfig
from aws_secretsmanager_caching.decorators import InjectKeywordedSecretString, InjectSecretString
from aws_secretsmanager_caching.decorators import (
InjectKeywordedSecretString,
InjectSecretString,
)
from aws_secretsmanager_caching.secret_cache import SecretCache

__all__ = ["SecretCache", "SecretCacheConfig", "InjectSecretString", "InjectKeywordedSecretString"]
__all__ = [
"SecretCache",
"SecretCacheConfig",
"InjectSecretString",
"InjectKeywordedSecretString",
]
7 changes: 6 additions & 1 deletion src/aws_secretsmanager_caching/cache/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
No guarantee is provided on the modules and APIs within this
namespace staying consistent. Directly reference at your own risk.
"""
from aws_secretsmanager_caching.cache.items import SecretCacheItem, SecretCacheObject, SecretCacheVersion

from aws_secretsmanager_caching.cache.items import (
SecretCacheItem,
SecretCacheObject,
SecretCacheVersion,
)
from aws_secretsmanager_caching.cache.lru import LRUCache

__all__ = ["SecretCacheObject", "SecretCacheItem", "SecretCacheVersion", "LRUCache"]
14 changes: 10 additions & 4 deletions src/aws_secretsmanager_caching/cache/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

class SecretCacheObject: # pylint: disable=too-many-instance-attributes
"""Secret cache object that handles the common refresh logic."""

# Jitter max for refresh now
FORCE_REFRESH_JITTER_SLEEP = 5000
__metaclass__ = ABCMeta
Expand Down Expand Up @@ -100,7 +101,7 @@ def __refresh(self):
except Exception as e: # pylint: disable=broad-except
self._exception = e
delay = self._config.exception_retry_delay_base * (
self._config.exception_retry_growth_factor ** self._exception_count
self._config.exception_retry_growth_factor**self._exception_count
)
self._exception_count += 1
delay = min(delay, self._config.exception_retry_delay_max)
Expand Down Expand Up @@ -132,7 +133,10 @@ def refresh_secret_now(self):
self._refresh_needed = True

# Generate a random number to have a sleep jitter to not get stuck in a retry loop
sleep = randint(int(self.FORCE_REFRESH_JITTER_SLEEP / 2), self.FORCE_REFRESH_JITTER_SLEEP + 1)
sleep = randint(
int(self.FORCE_REFRESH_JITTER_SLEEP / 2),
self.FORCE_REFRESH_JITTER_SLEEP + 1,
)

if self._exception is not None:
current_time_millis = int(datetime.now(timezone.utc).timestamp() * 1000)
Expand Down Expand Up @@ -240,8 +244,10 @@ def _get_version(self, version_stage):
version = self._versions.get(version_id)
if version:
return version.get_secret_value()
self._versions.put_if_absent(version_id, SecretCacheVersion(self._config, self._client, self._secret_id,
version_id))
self._versions.put_if_absent(
version_id,
SecretCacheVersion(self._config, self._client, self._secret_id, version_id),
)
return self._versions.get(version_id).get_secret_value()


Expand Down
3 changes: 1 addition & 2 deletions src/aws_secretsmanager_caching/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class SecretCacheConfig:

"""Advanced configuration for SecretCache clients.

:type max_cache_size: int
Expand Down Expand Up @@ -54,7 +53,7 @@ class SecretCacheConfig:
"exception_retry_delay_max": 3600,
"default_version_stage": "AWSCURRENT",
"secret_refresh_interval": 3600,
"secret_cache_hook": None
"secret_cache_hook": None,
}

def __init__(self, **kwargs):
Expand Down
Loading