Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Bump black from 24.1.1 to 24.2.0 #24

Merged
merged 4 commits into from
Feb 23, 2024
Merged
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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# black 2024 style update
f76b5cc505cb984beafcf7101b15e62949153e44
12 changes: 10 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
lint:
name: Run black/pylint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

tests:
- name: Run black
uses: psf/black@stable

tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -63,6 +71,6 @@ jobs:
run: |
pip install 'pymongo<4'

- name: Run linter and software tests
- name: Run software tests
run: |
python -m unittest -vvv
14 changes: 8 additions & 6 deletions crate/migr8/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_args():


def parse_input_numbers(s: str):
""" Parse an input string for numbers and ranges.
"""Parse an input string for numbers and ranges.

Supports strings like '0 1 2', '0, 1, 2' as well as ranges such as
'0-2'.
Expand All @@ -103,7 +103,7 @@ def parse_input_numbers(s: str):


def extract_to_file(args):
""" Extract a schema (or set of schemas) from MongoDB collections to a
"""Extract a schema (or set of schemas) from MongoDB collections to a
a JSON file.
"""

Expand All @@ -115,7 +115,7 @@ def extract_to_file(args):


def gather_collections(database):
""" Gather a list of collections to use from a MongoDB database, based
"""Gather a list of collections to use from a MongoDB database, based
on user input.
"""

Expand All @@ -140,13 +140,15 @@ def gather_collections(database):
filtered_collections.append(c)

# MongoDB 2 does not understand `include_system_collections=False`.
filtered_collections = [item for item in filtered_collections if not item.startswith("system.")]
filtered_collections = [
item for item in filtered_collections if not item.startswith("system.")
]

return filtered_collections


def extract(args):
""" Extract schemas from MongoDB collections.
"""Extract schemas from MongoDB collections.

This asks the user for which collections they would like to extract,
iterates over these collections and returns a dictionary of schemas for
Expand Down Expand Up @@ -205,7 +207,7 @@ def translate(schema):


def translate_from_file(args):
""" Reads in a JSON file and extracts the schema from it."""
"""Reads in a JSON file and extracts the schema from it."""

with open(args.infile) as f:
schema = json.load(f)
Expand Down
4 changes: 2 additions & 2 deletions crate/migr8/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def convert(d):


def export(collection):
""" Exports a MongoDB collection's documents to standard JSON and then
outputs it to stdout.
"""Exports a MongoDB collection's documents to standard JSON and then
outputs it to stdout.
"""
for document in collection.find():
bson_json = bsonjs.dumps(document.raw)
Expand Down
8 changes: 3 additions & 5 deletions crate/migr8/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@


def extract_schema_from_collection(collection: Collection, partial: bool):
""" Extracts a schema definition from a collection.
"""Extracts a schema definition from a collection.

If the extraction is partial, only the first document in the collection is
used to create the schema.
Expand Down Expand Up @@ -105,8 +105,7 @@ def extract_schema_from_collection(collection: Collection, partial: bool):


def extract_schema_from_document(document: dict, schema: dict):
""" Extracts and updates schema definition from a given document.
"""
"""Extracts and updates schema definition from a given document."""

for k, v in document.items():
if k not in schema:
Expand Down Expand Up @@ -135,8 +134,7 @@ def extract_schema_from_document(document: dict, schema: dict):


def extract_schema_from_array(array: list, schema: dict):
""" Extracts and updates a schema definition for a list.
"""
"""Extracts and updates a schema definition for a list."""

for item in array:
t = get_type(item)
Expand Down
18 changes: 8 additions & 10 deletions crate/migr8/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@


def translate_object(schema):
""" Translates an object field schema definition into a CrateDB dynamic
"""Translates an object field schema definition into a CrateDB dynamic
object column.
"""

Expand All @@ -70,13 +70,13 @@ def translate_object(schema):
else:
columns[index] = column[0]
return OBJECT.format(
object_type=object_type, definition=",\n".join([c for c in columns]),
object_type=object_type,
definition=",\n".join([c for c in columns]),
)


def translate_array(schema):
""" Translates an array field schema definition into a CrateDB array column.
"""
"""Translates an array field schema definition into a CrateDB array column."""

subtype, comment = determine_type(schema)
if comment:
Expand All @@ -86,8 +86,7 @@ def translate_array(schema):


def determine_type(schema):
""" Determine the type of a specific field schema.
"""
"""Determine the type of a specific field schema."""

types = schema.get("types", [])
type = max(types, key=lambda item: types[item]["count"])
Expand All @@ -105,7 +104,7 @@ def determine_type(schema):


def proportion_string(types: list) -> str:
""" Converts a list of types into a string explaining the proportions of
"""Converts a list of types into a string explaining the proportions of
each type.
"""

Expand All @@ -118,8 +117,7 @@ def proportion_string(types: list) -> str:


def indent_sql(query: str) -> str:
""" Indents an SQL query based on opening and closing brackets.
"""
"""Indents an SQL query based on opening and closing brackets."""

indent = 0
lines = query.split("\n")
Expand All @@ -134,7 +132,7 @@ def indent_sql(query: str) -> str:


def translate(schemas):
""" Translate a schema definition for a set of MongoDB collection schemas.
"""Translate a schema definition for a set of MongoDB collection schemas.

This results in a set of CrateDB compatible CREATE TABLE expressions
corresponding to the set of MongoDB collection schemas.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def read(path):
],
extras_require={
"testing": [
"black==24.1.1",
"black==24.2.0",
"flake8==7.0.0",
"isort==5.13.2",
]
Expand Down