Skip to content

Commit

Permalink
improve ruff settings
Browse files Browse the repository at this point in the history
  • Loading branch information
07pepa committed Aug 16, 2024
1 parent 86cbc28 commit 4c8593f
Show file tree
Hide file tree
Showing 132 changed files with 1,708 additions and 1,246 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ contact_links:
url: 'https://github.com/roman-right/beanie/discussions/new?category=feature-request'
about: >
If you think we should add a new feature to Beanie, please start a discussion, once it attracts
wider support, it can be migrated to an issue
wider support, it can be migrated to an issue
12 changes: 8 additions & 4 deletions .github/scripts/handlers/gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def get_commits_after_tag(self, tag: str) -> List[str]:
["git", "log", f"{tag}..HEAD", "--pretty=format:%H"],
stdout=subprocess.PIPE,
text=True,
check=False,
)
return result.stdout.split()

Expand All @@ -53,7 +54,10 @@ def get_pr_for_commit(self, commit_sha: str) -> PullRequest:
)

def build_markdown_for_many_prs(self) -> str:
markdown = f"\n## [{self.new_version}] - {datetime.now().strftime('%Y-%m-%d')}\n"
markdown = (
f"\n## [{self.new_version}] - "
f"{datetime.now().strftime('%Y-%m-%d')}\n"
)
for pr in self.prs:
markdown += (
f"### {pr.title.capitalize()}\n"
Expand All @@ -65,7 +69,7 @@ def build_markdown_for_many_prs(self) -> str:

def commit_changes(self):
self.run_git_command(
["git", "config", "--global", "user.name", "github-actions[bot]"]
["git", "config", "--global", "user.name", "github-actions[bot]"],
)
self.run_git_command(
[
Expand All @@ -74,11 +78,11 @@ def commit_changes(self):
"--global",
"user.email",
"github-actions[bot]@users.noreply.github.com",
]
],
)
self.run_git_command(["git", "add", "."])
self.run_git_command(
["git", "commit", "-m", f"Bump version to {self.new_version}"]
["git", "commit", "-m", f"Bump version to {self.new_version}"],
)
self.run_git_command(["git", "tag", self.new_version])
self.git_push()
Expand Down
7 changes: 4 additions & 3 deletions .github/scripts/handlers/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self):
self.changelog = self.ROOT_PATH / "docs" / "changelog.md"

self.current_version = self.parse_version_from_pyproject(
self.pyproject
self.pyproject,
)
self.pypi_version = self.get_version_from_pypi()

Expand All @@ -62,7 +62,7 @@ def parse_version_from_pyproject(pyproject: Path) -> SemVer:

def get_version_from_pypi(self) -> SemVer:
response = requests.get(
f"https://pypi.org/pypi/{self.PACKAGE_NAME}/json"
f"https://pypi.org/pypi/{self.PACKAGE_NAME}/json",
)
if response.status_code == 200:
return SemVer(response.json()["info"]["version"])
Expand All @@ -82,7 +82,8 @@ def update_file_versions(self, files_to_update):
for file_path in files_to_update:
content = file_path.read_text()
content = content.replace(
str(self.pypi_version), str(self.current_version)
str(self.pypi_version),
str(self.current_version),
)
file_path.write_text(content)

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/close_inactive_issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
days-before-issue-stale: 30
days-before-pr-stale: 45
days-before-issue-close: 14
days-before-pr-close: 14
days-before-pr-close: 14
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
- name: install dependencies
run: pip3 install .[doc]
- name: publish docs
run: bash scripts/publish_docs.sh
run: bash scripts/publish_docs.sh
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-publish-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
env:
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.FLIT_PASSWORD }}
run: flit publish
run: flit publish
7 changes: 2 additions & 5 deletions .github/workflows/github-actions-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: 3.11
- uses: pre-commit/action@v3.0.0
- uses: pre-commit/action@v3.0.1
run-tests:
strategy:
fail-fast: false
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
mongodb-version: [ 4.4, 5.0 ]
pydantic-version: [ "1.10.15", "2.7" ]
exclude:
- python-version: "3.7"
pydantic-version: "2.7"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
37 changes: 35 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.5.0
rev: v0.6.0
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
rev: v1.11.1
hooks:
- id: mypy
additional_dependencies:
- types-click
- types-toml
exclude: ^tests/
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies:
- tomli

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-builtin-literals
- id: check-xml
- id: check-toml
- id: check-json
- id: check-yaml
args:
- --unsafe
- id: end-of-file-fixer
exclude: \.py$ #already done by ruff
- id: trailing-whitespace
exclude: \.py$ #already done by ruff
- id: fix-byte-order-marker
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
- id: detect-private-key
- id: check-vcs-permalinks
- id: forbid-submodules
- id: mixed-line-ending
exclude: \.py$ #already done by ruff
# make code friendly to windows programmers we do not want to have maximal compatibility
- id: check-case-conflict
#- id: check-illegal-windows-names not available yet
14 changes: 0 additions & 14 deletions .pypirc

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Product(Document):

# This is an asynchronous example, so we will access it from an async function
async def example():
# Beanie uses Motor async client under the hood
# Beanie uses Motor async client under the hood
client = AsyncIOMotorClient("mongodb://user:pass@host:27017")

# Initialize beanie with the Product document class
Expand All @@ -81,11 +81,11 @@ async def example():
# Beanie documents work just like pydantic models
tonybar = Product(name="Tony's", price=5.95, category=chocolate)
# And can be inserted into the database
await tonybar.insert()
await tonybar.insert()

# You can find documents with pythonic syntax
product = await Product.find_one(Product.price < 10)

# And update them
await product.set({Product.name:"Gold bar"})

Expand All @@ -103,7 +103,7 @@ if __name__ == "__main__":
### Example Projects

- **[fastapi-cosmos-beanie](https://github.com/tonybaloney/ants-azure-demos/tree/master/fastapi-cosmos-beanie)** - FastAPI + Beanie ODM + Azure Cosmos Demo Application by [Anthony Shaw](https://github.com/tonybaloney)
- **[fastapi-beanie-jwt](https://github.com/flyinactor91/fastapi-beanie-jwt)** -
- **[fastapi-beanie-jwt](https://github.com/flyinactor91/fastapi-beanie-jwt)** -
Sample FastAPI server with JWT auth and Beanie ODM by [Michael duPont](https://github.com/flyinactor91)
- **[Shortify](https://github.com/IHosseini083/Shortify)** - URL shortener RESTful API (FastAPI + Beanie ODM + JWT & OAuth2) by [
Iliya Hosseini](https://github.com/IHosseini083)
Expand Down
6 changes: 3 additions & 3 deletions assets/logo/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions assets/logo/white_bg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 17 additions & 10 deletions beanie/executors/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@ def __init__(self, **kwargs):
kwargs.get("distance")
or self.get_env_value("distance")
or self.get_from_toml("distance")
or 0
or 0,
)
self.connection_uri = str(
kwargs.get("connection_uri")
or self.get_env_value("connection_uri")
or self.get_from_toml("connection_uri")
or self.get_from_toml("connection_uri"),
)
self.database_name = str(
kwargs.get("database_name")
or self.get_env_value("database_name")
or self.get_from_toml("database_name")
or self.get_from_toml("database_name"),
)
self.path = Path(
kwargs.get("path")
or self.get_env_value("path")
or self.get_from_toml("path")
or self.get_from_toml("path"),
)
self.allow_index_dropping = bool(
kwargs.get("allow_index_dropping")
or self.get_env_value("allow_index_dropping")
or self.get_from_toml("allow_index_dropping")
or False
or False,
)
self.use_transaction = bool(kwargs.get("use_transaction"))

Expand Down Expand Up @@ -81,7 +81,7 @@ def get_env_value(field_name) -> Any:
)
else:
value = os.environ.get(
f"BEANIE_{field_name.upper()}"
f"BEANIE_{field_name.upper()}",
) or os.environ.get(f"beanie_{field_name.lower()}")
return value

Expand Down Expand Up @@ -109,7 +109,8 @@ async def run_migrate(settings: MigrationSettings):
DBHandler.set_db(settings.connection_uri, settings.database_name)
root = await MigrationNode.build(settings.path)
mode = RunningMode(
direction=settings.direction, distance=settings.distance
direction=settings.direction,
distance=settings.distance,
)
await root.run(
mode=mode,
Expand Down Expand Up @@ -148,7 +149,11 @@ async def run_migrate(settings: MigrationSettings):
help="MongoDB connection URI",
)
@click.option(
"-db", "--database_name", required=False, type=str, help="DataBase name"
"-db",
"--database_name",
required=False,
type=str,
help="DataBase name",
)
@click.option(
"-p",
Expand All @@ -161,14 +166,16 @@ async def run_migrate(settings: MigrationSettings):
"--allow-index-dropping/--forbid-index-dropping",
required=False,
default=False,
help="if allow-index-dropping is set, Beanie will drop indexes from your collection",
help="if allow-index-dropping is set, "
"Beanie will drop indexes from your collection",
)
@click.option(
"--use-transaction/--no-use-transaction",
required=False,
default=True,
help="Enable or disable the use of transactions during migration. "
"When enabled (--use-transaction), Beanie uses transactions for migration, "
"When enabled (--use-transaction), "
"Beanie uses transactions for migration, "
"which necessitates a replica set. When disabled (--no-use-transaction), "
"migrations occur without transactions.",
)
Expand Down
Loading

0 comments on commit 4c8593f

Please sign in to comment.