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 2 #74

Closed
wants to merge 5 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.

1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ repos:
hooks:
- id: ruff
args: ["--fix"]
exclude: ^(src/diracx/client/)

- repo: https://github.com/psf/black
rev: 23.7.0
Expand Down
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
@@ -1,3 +1,5 @@
# ruff: noqa: UP007 # because of https://github.com/tiangolo/typer/issues/533

from __future__ import annotations

import asyncio
Expand All @@ -23,9 +25,7 @@
async def login(
vo: str,
group: Optional[str] = None,
property: Optional[list[str]] = Option(
None, help="Override the default(s) with one or more properties"
),
property: Optional[list[str]] = Option(None, help="Override the default(s) with one or more properties"),
):
scopes = [f"vo:{vo}"]
if group:
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 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
20 changes: 5 additions & 15 deletions src/diracx/client/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,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
24 changes: 6 additions & 18 deletions src/diracx/client/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,12 @@ def __init__(self, **kwargs: Any) -> None:
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