Skip to content

Commit

Permalink
Pre-commit fixes.
Browse files Browse the repository at this point in the history
Whitespace at eof, ruff pyupgrade, typos, formatting.
  • Loading branch information
thomasmarwitz committed Dec 10, 2024
1 parent 89eb01a commit 2e27908
Show file tree
Hide file tree
Showing 36 changed files with 135 additions and 140 deletions.
4 changes: 3 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
Thank you for pull request.
Below are a few things we ask you kindly to self-check before getting a review. Remove checks that are not relevant.
-->

Checklist
* [ ] Added a `docs/changes.rst` entry

- [ ] Added a `docs/changes.rst` entry
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ jobs:
environments: py38 # as in pyproject.toml
- name: Install repository
run: pixi run -e py38 postinstall
- name: Run mypy
run: pixi run -e py38 mypy minimalkv
34 changes: 17 additions & 17 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ name: "CodeQL"

on:
push:
branches: [ main ]
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [main]
schedule:
- cron: '31 21 * * 1'
- cron: "31 21 * * 1"

jobs:
analyze:
Expand All @@ -28,21 +28,21 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
language: ["python"]

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
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
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
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

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
63 changes: 31 additions & 32 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ name: "CodeQL"
on:
workflow_dispatch:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
branches: ["main"]
schedule:
- cron: '25 17 * * 5'
- cron: "25 17 * * 5"

jobs:
analyze:
Expand All @@ -33,43 +33,42 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
language: ["python"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
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.
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
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.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, 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@v3

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, 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@v3
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER

--
--
The original storefact source had the following license:

Copyright (c) 2015-2017, Blue Yonder GmbH
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ minimalkv is `available on PyPI <http://pypi.python.org/pypi/minimalkv/>`_ and
can be installed through `pip <http://pypi.python.org/pypi/pip>`_::

pip install minimalkv

or via ``conda`` on `conda-forge <https://github.com/conda-forge/minimalkv-feedstock>`_::

conda install -c conda-forge minimalkv
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
image: fsouza/fake-gcs-server
container_name: fake-gcs-server
ports:
- 4443:4443
- 4443:4443
command: -scheme http
azure:
image: mcr.microsoft.com/azure-storage/azurite
Expand All @@ -18,25 +18,25 @@ services:
container_name: minio
ports:
- 9000:9000
- 9001:9001 # Debugging over Web GUI if needed
- 9001:9001 # Debugging over Web GUI if needed
environment:
MINIO_ACCESS_KEY: minio
MINIO_SECRET_KEY: miniostorage
mongodb:
image: mongo
container_name: mongodb
ports:
- 27017:27017
- 27017:27017
redis:
image: redis
container_name: redis
ports:
- 6379:6379
- 6379:6379
postgres:
image: postgres
container_name: postgreSQL
ports:
- 5432:5432
- 5432:5432
environment:
POSTGRES_USER: minimalkv_test
POSTGRES_PASSWORD: minimalkv_test
Expand Down
2 changes: 1 addition & 1 deletion docs/boto.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ The unit tests for S3 will be run by travis against a local minio instance, emul
Constructs a new boto based backend.

:param bucket: An instance of :class:`boto.s3.bucket.Bucket`,
:class:`boto.gs.bucket.Bucket` or similiar.
:class:`boto.gs.bucket.Bucket` or similar.
:param prefix: A string that will transparently prefixed to all handled
keys.
:param url_valid_time=0: When using
Expand Down
6 changes: 3 additions & 3 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Changelog
* Add a real AWS integration test for S3FSStore
* Add minio test for S3FSStore
* `verify` url param that can be passed to url when creating a `[h]s3://` store now really controls SSL verifaction
* Refactor tests to not skip Boto3Store / S3FSStore tests anymore if `boto` is unavailible
* Refactor tests to not skip Boto3Store / S3FSStore tests anymore if `boto` is unavailable

1.9.0
=====
Expand Down Expand Up @@ -41,7 +41,7 @@ Changelog
1.8.1
=====
* Drop `pkg_resources` and use `importlib.metadata` to access package version string.
* Add missing `region_name` in `s3fs` store creation to set required location contraint
* Add missing `region_name` in `s3fs` store creation to set required location constraint
during bucket creation.

1.8.0
Expand Down Expand Up @@ -184,7 +184,7 @@ Changelog

* Use ``BlockBlobService.list_blob_names`` in ``minimalkv.net.azurestore.AzureBlockBlobStore.iter_keys``.
This will only parse the names from Azure's XML response thus reducing CPU time
siginificantly for this function.
significantly for this function.
* They ``.keys()`` method on Python 3 now returns a list. This is in line with the documentation and the
behaviour on Python 2. It used to return a generator.

Expand Down
2 changes: 1 addition & 1 deletion docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ To run the tests, setup the Python environment and execute:
::

docker-compose up -d
pytest -n auto --dist loadfile
pytest -n auto --dist loadfile
4 changes: 2 additions & 2 deletions minimalkv/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
NOT_SET = "not_set"

VALID_NON_NUM = r"""\`\!"#$%&'()+,-.<=>?@[]^_{}~"""
VALID_KEY_REGEXP = "^[%s0-9a-zA-Z]+$" % re.escape(VALID_NON_NUM)
VALID_KEY_REGEXP = f"^[{re.escape(VALID_NON_NUM)}0-9a-zA-Z]+$"
"""This regular expression tests if a key is valid. Allowed are all
alphanumeric characters, as well as ``!"`#$%&'()+,-.<=>?@[]^_{}~``."""

VALID_KEY_RE = re.compile(VALID_KEY_REGEXP)
"""A compiled version of :data:`~minimalkv._constants.VALID_KEY_REGEXP`."""

VALID_NON_NUM_EXTENDED = VALID_NON_NUM + r"/ "
VALID_KEY_REGEXP_EXTENDED = "^[%s0-9a-zA-Z]+$" % re.escape(VALID_NON_NUM_EXTENDED)
VALID_KEY_REGEXP_EXTENDED = f"^[{re.escape(VALID_NON_NUM_EXTENDED)}0-9a-zA-Z]+$"
"""This regular expression tests if a key is valid when the extended keyspace mixin is used.
Allowed are all alphanumeric characters, as well as ``!"`#$%&'()+,-.<=>?@[]^_{}~/``. and spaces"""
VALID_KEY_RE_EXTENDED = re.compile(VALID_KEY_REGEXP_EXTENDED)
Expand Down
6 changes: 3 additions & 3 deletions minimalkv/_key_value_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from minimalkv._constants import VALID_KEY_RE
from minimalkv._mixins import UrlMixin

# Only here to keep backwards-compatability
# Only here to keep backwards-compatibility
key_type = str


Expand Down Expand Up @@ -143,7 +143,7 @@ def iter_prefixes(self, delimiter: str, prefix: str = "") -> Iterator[str]:
"""Iterate over unique prefixes in the store up to delimiter, starting with prefix.
If ``prefix`` contains ``delimiter``, return the prefix up to the first
occurence of delimiter after the prefix.
occurrence of delimiter after the prefix.
The default uses an naive key iteration. Some backends may implement more
efficient methods.
Expand Down Expand Up @@ -361,7 +361,7 @@ def _has_key(self, key: str) -> bool:
Parameters
----------
key : str
Key to check the existance of.
Key to check the existence of.
"""
return key in self.keys()

Expand Down
8 changes: 4 additions & 4 deletions minimalkv/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ def _valid_ttl(
return ttl_secs

if not isinstance(ttl_secs, (int, float)):
raise ValueError("Not a valid ttl_secs value: %r" % ttl_secs)
raise ValueError(f"Not a valid ttl_secs value: {ttl_secs}")

if ttl_secs < 0:
raise ValueError("ttl_secs must not be negative: %r" % ttl_secs)
raise ValueError(f"ttl_secs must not be negative: {ttl_secs}")

return ttl_secs

Expand Down Expand Up @@ -411,6 +411,6 @@ def _check_valid_key(self, key: Optional[str]) -> None:
"""
if key is not None:
if not isinstance(key, str):
raise ValueError("%r is not a valid key type" % key)
raise ValueError(f"{key} is not a valid key type")
elif not VALID_KEY_RE_EXTENDED.match(key) or key == "/":
raise ValueError("%r contains illegal characters" % key)
raise ValueError(f"{key} contains illegal characters")
12 changes: 3 additions & 9 deletions minimalkv/_store_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,8 @@ def _build_azure_url(
protocol = default_endpoints_protocol or "https"
if use_sas:
return (
"DefaultEndpointsProtocol={protocol};AccountName={account_name};"
"SharedAccessSignature={shared_access_signature}".format(
protocol=protocol,
account_name=account_name,
shared_access_signature=account_key,
)
f"DefaultEndpointsProtocol={protocol};AccountName={account_name};"
f"SharedAccessSignature={account_key}"
)
else:
return "DefaultEndpointsProtocol={protocol};AccountName={account_name};AccountKey={account_key}".format(
protocol=protocol, account_name=account_name, account_key=account_key
)
return f"DefaultEndpointsProtocol={protocol};AccountName={account_name};AccountKey={account_key}"
6 changes: 3 additions & 3 deletions minimalkv/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class CacheDecorator(StoreDecorator):
backing store. After their completion, the cache will be updated.
No cache maintainenace above this is done by the decorator. The caching
store itselfs decides how large to grow the cache and which data to keep,
store itself decides how large to grow the cache and which data to keep,
which data to throw away.
Parameters
----------
cache : KeyValueStore
The caching backend.
store : KeyValueStore
The backing store. This is the "authorative" backend.
The backing store. This is the "authoritative" backend.
"""

def __init__(self, cache: KeyValueStore, store: KeyValueStore):
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_file(self, key: str, file: Union[str, BinaryIO]) -> str:

# return from cache
return self.cache.get_file(key, file)
# if an IOError occured, file pointer may be dirty - cannot proceed
# if an IOError occurred, file pointer may be dirty - cannot proceed
# safely

def open(self, key: str) -> BinaryIO:
Expand Down
2 changes: 1 addition & 1 deletion minimalkv/crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get(self, key): # noqa D
hm.update(buf)

if not hm.digest() == hash:
raise VerificationException("Invalid hash on key %r" % key)
raise VerificationException(f"Invalid hash on key {key}")

return buf

Expand Down
2 changes: 1 addition & 1 deletion minimalkv/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class URLEncodeKeysDecorator(KeyTransformingDecorator):

def _map_key(self, key: str) -> str: # noqa D
if not isinstance(key, str):
raise ValueError("%r is not a unicode string" % key)
raise ValueError(f"{key} is not a unicode string")
quoted = quote_plus(key.encode("utf-8"))
if isinstance(quoted, bytes):
quoted = quoted.decode("utf-8")
Expand Down
2 changes: 1 addition & 1 deletion minimalkv/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def iter_prefixes(self, delimiter: str, prefix: str = "") -> Iterator[str]:
"""Iterate over unique prefixes in the store up to delimiter, starting with prefix.
If ``prefix`` contains ``delimiter``, return the prefix up to the first
occurence of delimiter after the prefix.
occurrence of delimiter after the prefix.
Parameters
----------
Expand Down
Loading

0 comments on commit 2e27908

Please sign in to comment.