Skip to content
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

Style: aligned black with ruff settings, added pyupgrade #61

Closed
wants to merge 8 commits into from
Closed
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
45 changes: 0 additions & 45 deletions .gitlab-ci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies:
- httpx
- isodate
- mypy
- pydantic =1.10.10
- pydantic =1.10.12
- pytest
- pytest-asyncio
- pytest-cov
Expand Down
16 changes: 15 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]

[tool.ruff]
select = ["E", "F", "B", "I", "PLE"]
select = [
"E", # pycodestyle errrors
"F", # pyflakes
"B", # flake8-bugbear
"I", # isort
"PLE", # pylint errors
"UP", # pyUpgrade
"FLY", # flynt
]
ignore = ["B905", "B008", "B006"]
line-length = 120
src = ["src", "tests"]
Expand All @@ -17,6 +25,12 @@ exclude = ["src/diracx/client/"]
# Allow default arguments like, e.g., `data: List[str] = fastapi.Query(None)`.
extend-immutable-calls = ["fastapi.Depends", "fastapi.Query", "fastapi.Path", "fastapi.Body", "fastapi.Header"]

[tool.black]
line-length = 120

[tool.isort]
profile = "black"

[tool.mypy]
plugins = ["sqlalchemy.ext.mypy.plugin", "pydantic.mypy"]
exclude = ["^src/diracx/client", "^tests/", "^build/"]
Expand Down
10 changes: 4 additions & 6 deletions src/diracx/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
@app.async_command()
async def login(
vo: str,
group: Optional[str] = None,
property: Optional[list[str]] = Option(
group: Optional[str] = None, # noqa: UP007
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we do this at the file level with a comment explaining why?

# ruff: noqa: F841

https://beta.ruff.rs/docs/configuration/#error-suppression

property: Optional[list[str]] = Option( # noqa: UP007
None, help="Override the default(s) with one or more properties"
),
):
Expand Down Expand Up @@ -61,9 +61,7 @@
raise RuntimeError("Device authorization flow expired")

CREDENTIALS_PATH.parent.mkdir(parents=True, exist_ok=True)
expires = datetime.now(tz=timezone.utc) + timedelta(
seconds=response.expires_in - EXPIRES_GRACE_SECONDS
)
expires = datetime.now(tz=timezone.utc) + timedelta(seconds=response.expires_in - EXPIRES_GRACE_SECONDS)

Check warning on line 64 in src/diracx/cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/diracx/cli/__init__.py#L64

Added line #L64 was not covered by tests
credential_data = {
"access_token": response.access_token,
# TODO: "refresh_token":
Expand All @@ -82,7 +80,7 @@


@app.callback()
def callback(output_format: Optional[str] = None):
def callback(output_format: Optional[str] = None): # noqa: UP007
if "DIRACX_OUTPUT_FORMAT" not in os.environ:
output_format = output_format or "rich"
if output_format is not None:
Expand Down
12 changes: 2 additions & 10 deletions src/diracx/cli/internal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import json
from pathlib import Path

Expand Down Expand Up @@ -47,11 +45,7 @@ def generate_cs(
IdP=IdpConfig(URL=idp_url, ClientID=idp_client_id),
DefaultGroup=user_group,
Users={},
Groups={
user_group: GroupConfig(
JobShare=None, Properties=["NormalUser"], Quota=None, Users=[]
)
},
Groups={user_group: GroupConfig(JobShare=None, Properties=["NormalUser"], Quota=None, Users=[])},
)
config = Config(
Registry={vo: registry},
Expand Down Expand Up @@ -105,7 +99,5 @@ def add_user(
config_data = json.loads(config.json(exclude_unset=True))
yaml_path.write_text(yaml.safe_dump(config_data))
repo.index.add([yaml_path.relative_to(repo_path)])
repo.index.commit(
f"Added user {sub} ({preferred_username}) to vo {vo} and user_group {user_group}"
)
repo.index.commit(f"Added user {sub} ({preferred_username}) to vo {vo} and user_group {user_group}")
typer.echo(f"Successfully added user to {config_repo}", err=True)
8 changes: 2 additions & 6 deletions src/diracx/cli/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,5 @@
@app.async_command()
async def submit(jdl: list[FileText]):
async with Dirac(endpoint="http://localhost:8000") as api:
jobs = await api.jobs.submit_bulk_jobs(
[x.read() for x in jdl], headers=get_auth_headers()
)
print(
f"Inserted {len(jobs)} jobs with ids: {','.join(map(str, (job.job_id for job in jobs)))}"
)
jobs = await api.jobs.submit_bulk_jobs([x.read() for x in jdl], headers=get_auth_headers())
print(f"Inserted {len(jobs)} jobs with ids: {','.join(map(str, (job.job_id for job in jobs)))}")

Check warning on line 108 in src/diracx/cli/jobs.py

View check run for this annotation

Codecov / codecov/patch

src/diracx/cli/jobs.py#L107-L108

Added lines #L107 - L108 were not covered by tests
3 changes: 1 addition & 2 deletions src/diracx/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.9.5, generator: @autorest/python@6.4.11)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand All @@ -7,8 +6,8 @@
from ._client import Dirac

try:
from ._patch import __all__ as _patch_all
from ._patch import * # pylint: disable=unused-wildcard-import
from ._patch import __all__ as _patch_all
except ImportError:
_patch_all = []
from ._patch import patch_sdk as _patch_sdk
Expand Down
21 changes: 5 additions & 16 deletions src/diracx/client/_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.9.5, generator: @autorest/python@6.4.11)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand Down Expand Up @@ -40,28 +39,18 @@ def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self, *, endpoint: str = "", **kwargs: Any
) -> None:
self._config = DiracConfiguration(**kwargs)
self._client: PipelineClient = PipelineClient(
base_url=endpoint, config=self._config, **kwargs
)
self._client: PipelineClient = PipelineClient(base_url=endpoint, config=self._config, **kwargs)

client_models = {
k: v for k, v in _models.__dict__.items() if isinstance(v, type)
}
client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
self._serialize.client_side_validation = False
self.well_known = WellKnownOperations(
self._client, self._config, self._serialize, self._deserialize
)
self.well_known = WellKnownOperations(self._client, self._config, self._serialize, self._deserialize)
self.auth = AuthOperations( # pylint: disable=abstract-class-instantiated
self._client, self._config, self._serialize, self._deserialize
)
self.config = ConfigOperations(
self._client, self._config, self._serialize, self._deserialize
)
self.jobs = JobsOperations(
self._client, self._config, self._serialize, self._deserialize
)
self.config = ConfigOperations(self._client, self._config, self._serialize, self._deserialize)
self.jobs = JobsOperations(self._client, self._config, self._serialize, self._deserialize)

def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.
Expand Down
29 changes: 8 additions & 21 deletions src/diracx/client/_configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Code generated by Microsoft (R) AutoRest Code Generator (autorest: 3.9.5, generator: @autorest/python@6.4.11)
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand All @@ -20,30 +19,18 @@ class DiracConfiguration(Configuration): # pylint: disable=too-many-instance-at
"""

def __init__(self, **kwargs: Any) -> None:
super(DiracConfiguration, self).__init__(**kwargs)
super().__init__(**kwargs)

kwargs.setdefault("sdk_moniker", "dirac/{}".format(VERSION))
kwargs.setdefault("sdk_moniker", f"dirac/{VERSION}")
self._configure(**kwargs)

def _configure(self, **kwargs: Any) -> None:
self.user_agent_policy = kwargs.get(
"user_agent_policy"
) or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(
**kwargs
)
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get(
"logging_policy"
) or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get(
"http_logging_policy"
) or policies.HttpLoggingPolicy(**kwargs)
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.custom_hook_policy = kwargs.get(
"custom_hook_policy"
) or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(
**kwargs
)
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
self.authentication_policy = kwargs.get("authentication_policy")
4 changes: 1 addition & 3 deletions src/diracx/client/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"""
from typing import List

__all__: List[
str
] = [] # Add all objects you want publicly available to users at this package level
__all__: list[str] = [] # Add all objects you want publicly available to users at this package level


def patch_sdk():
Expand Down
Loading