Skip to content

Commit

Permalink
Use ruff for code-formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Feb 16, 2024
1 parent b31b36e commit 61f2baa
Show file tree
Hide file tree
Showing 27 changed files with 152 additions and 149 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,27 @@ jobs:
working-directory: ./robotframework-interactive/vscode-interpreter-webview
run: prettier --check src/**/*.{ts,tsx}

- name: Black check robocorp-code
- name: ruff format check robocorp-code
run: |
echo $PWD
ls -la
source ./.venv/bin/activate
black --check ./robocorp-code --exclude=vendored
ruff format --check ./robocorp-code --exclude=vendored
- name: Black check robotframework-ls
- name: ruff format check robotframework-ls
run: |
source ./.venv/bin/activate
black --check ./robotframework-ls --exclude=vendored --exclude=atest_v5
ruff format --check ./robotframework-ls --exclude=vendored --exclude=atest_v5
- name: Black check robotframework-interactive
- name: ruff format check robotframework-interactive
run: |
source ./.venv/bin/activate
black --check ./robotframework-interactive --exclude=vendored
ruff format --check ./robotframework-interactive --exclude=vendored
- name: Black check robocorp-python-ls-core
- name: ruff format check robocorp-python-ls-core
run: |
source ./.venv/bin/activate
black --check ./robocorp-python-ls-core --exclude=vendored --exclude=libs
ruff format --check ./robocorp-python-ls-core --exclude=vendored --exclude=libs
- name: mypy robocorp-code
run: |
Expand Down
6 changes: 3 additions & 3 deletions example-vscode/src/example_vscode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def import_robocorp_ls_core():
"Using vendored mode. Found: %s" % (vendored_folder,)
)
use_folder = vendored_folder
assert os.path.isdir(
use_folder
), "Expected: %s to exist and be a directory." % (use_folder,)
assert os.path.isdir(use_folder), (
"Expected: %s to exist and be a directory." % (use_folder,)
)

sys.path.append(use_folder)
import robocorp_ls_core
Expand Down
8 changes: 6 additions & 2 deletions robocorp-code/.settings/org.python.pydev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DATE_FIELD_FORMAT: yyyy-MM-dd
DATE_FIELD_NAME: __updated__
DELETE_UNUSED_IMPORTS: false
ENABLE_DATE_FIELD_ACTION: false
FORMATTER_STYLE: BLACK
FORMATTER_STYLE: RUFF
FORMAT_BEFORE_SAVING: true
FORMAT_ONLY_CHANGED_LINES: false
FROM_IMPORTS_FIRST: false
Expand All @@ -30,10 +30,14 @@ MYPY_ARGS: --follow-imports=silent --show-column-numbers --namespace-packages --
MYPY_FILE_LOCATION: ''
MYPY_USE_CONSOLE: true
PYDEV_TEST_RUNNER: '2'
PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n 0 --tb=native -vv --force-regen --assert=plain
PYDEV_TEST_RUNNER_DEFAULT_PARAMETERS: --capture=no -W ignore::DeprecationWarning -n
0 --tb=native -vv --force-regen --assert=plain
PYDEV_USE_PYUNIT_VIEW: true
RUFF_ARGS: ''
RUFF_FILE_LOCATION: ''
RUFF_FORMATTER_FILE_LOCATION: D:\bin\miniconda\envs\robocorp-action-server\Scripts\ruff.exe
RUFF_FORMATTER_LOCATION_OPTION: LOCATION_SEARCH
RUFF_PARAMETERS: ''
RUFF_USE_CONSOLE: false
SAVE_ACTIONS_ONLY_ON_WORKSPACE_FILES: true
SEARCH_MYPY_LOCATION: SEARCH
Expand Down
42 changes: 21 additions & 21 deletions robocorp-code/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion robocorp-code/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ robocorp-actions = "^0.0.7" # Just needed for testing.

numpy = "<2"
black = "^23.1.0"
ruff = "^0.0.255"
ruff = "^0.1.14"
mypy = "^1.1.1"
isort = { version = "^5.12.0", python = "^3.8" }
invoke = "^2.0"
Expand Down
6 changes: 3 additions & 3 deletions robocorp-code/src/robocorp_code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def import_robocorp_ls_core() -> None:
"Using vendored mode. Found: %s" % (vendored_folder,)
)
use_folder = vendored_folder
assert os.path.isdir(
use_folder
), "Expected: %s to exist and be a directory." % (use_folder,)
assert os.path.isdir(use_folder), (
"Expected: %s to exist and be a directory." % (use_folder,)
)

sys.path.append(use_folder)
import robocorp_ls_core
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def print_tree(
for child in iter_in:
print(child, file=stream)

space = " " * ((child.depth * 4 + 2))
space = " " * (child.depth * 4 + 2)
control = child.control
print(f"{space}Properties:", file=stream)
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@ def _create_package_from_conda_yaml(
conda_deps.append(dep)

# Ok, at this point we should have the deps. Let's put them in the new format.
new_pip_deps = []
new_pypi_deps = []
for dep in pip_deps:
try:
if dep.startswith("--"):
continue
parsed = parse_requirement(dep)
if parsed is None:
continue
Expand All @@ -125,7 +127,7 @@ def _create_package_from_conda_yaml(
),
file=stream,
)
new_pip_deps.append(f"{parsed.name}={version}")
new_pypi_deps.append(f"{parsed.name}={version}")
break

for op, version in parsed.constraints[1:]:
Expand Down Expand Up @@ -173,7 +175,7 @@ def _create_package_from_conda_yaml(
log.exception(f"Error collecting version info from: {dep}")

new_dependencies = {
"dependencies": {"conda-forge": new_conda_deps, "pip": new_pip_deps}
"dependencies": {"conda-forge": new_conda_deps, "pypi": new_pypi_deps}
}

post_install = contents.get("rccPostInstall")
Expand Down Expand Up @@ -267,6 +269,8 @@ def create_hash(contents: str) -> str:
def create_conda_contents_from_package_yaml_contents(
package_yaml: Path, package_yaml_contents: dict
) -> dict:
from ..termcolors import bold_yellow

def _get_in_dict(
dct: dict,
entry: str,
Expand Down Expand Up @@ -308,7 +312,16 @@ def _validate_name(name):
post_install = _get_in_dict(
package_yaml_contents, "post-install", list, required=False
)
pip = _get_in_dict(python_deps, "pip", list)

# This is an error
pip = _get_in_dict(python_deps, "pip", list, required=False)
if pip:
raise ActionPackageError(
f"'pip' entry not found in 'dependencies.pip' should be renamed to 'pypi' (in {package_yaml})."
)

# The user could get everything from 'conda'
pypi = _get_in_dict(python_deps, "pypi", list, required=False) or []

converted_conda_entries: list = []
found_truststore = False
Expand All @@ -319,22 +332,32 @@ def _validate_name(name):
found_truststore = True
converted_conda_entries.append(entry)

if "pip" not in found_names:
raise ActionPackageError(
f"'pip' entry not found in 'environment.conda-forge' (in {package_yaml})."
)

if "python" not in found_names:
raise ActionPackageError(
f"'python' entry not found in 'environment.conda-forge' (in {package_yaml})."
f"'python' entry not found in 'dependencies.conda-forge' (in {package_yaml})."
)

converted_pip_entries: list = []
for entry in pip:
for entry in pypi:
if entry.replace(" ", "") == "--use-feature=truststore":
log.info(
bold_yellow(
"--use-feature=truststore flag does not need to "
"be specified (it is automatically used when a "
'"robocorp-trustore" or "trustore" dependency is added).'
)
)
found_truststore = True
continue

if entry.startswith("--"):
raise ActionPackageError(f"Unexpected entry in pypi: {entry}")

name, entry = convert_pip_entry(package_yaml, entry)
_validate_name(name)
if name in ("truststore", "robocorp-truststore"):
found_truststore = True

converted_pip_entries.append(entry)

if found_truststore:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import weakref
from typing import Dict, Iterator, List, Optional, Sequence, Union

from ._deps_protocols import (PyPiInfoTypedDict, ReleaseData, Versions,
VersionStr)
from ._deps_protocols import PyPiInfoTypedDict, ReleaseData, Versions, VersionStr

log = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,7 @@ def update_class_to_generate_init(class_to_generate):
"""
%(init_body)s
self.kwargs = kwargs
''' % dict(
args=args, init_body=init_body, docstring=docstring
)
''' % dict(args=args, init_body=init_body, docstring=docstring)

class_to_generate["init"] = _indent_lines(class_to_generate["init"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def import_robocorp_ls_core() -> None:
# should be alongside it).
use_folder = src_folder
log_contents.append("Using vendored mode. Found: %s" % (use_folder,))
assert os.path.isdir(
use_folder
), "Expected: %s to exist and be a directory." % (use_folder,)
assert os.path.isdir(use_folder), (
"Expected: %s to exist and be a directory." % (use_folder,)
)

sys.path.append(use_folder)
import robocorp_ls_core
Expand Down
7 changes: 3 additions & 4 deletions robotframework-interactive/src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ def collect_vendored_files():
rel_file = os.path.join(rel_dir, file_name)
ret.append(rel_file)

assert (
len(ret) == 1
), "Did not collect robot_interactive_console.robot file properly. Found: %s" % (
ret,
assert len(ret) == 1, (
"Did not collect robot_interactive_console.robot file properly. Found: %s"
% (ret,)
)
return ret

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,7 @@ def _do_eval(self, debugger_impl):
*** Test Cases ***
Evaluation
%s
""" % (
self.expression,
)
""" % (self.expression,)
model = get_model(s)
ast_utils.set_localization_info_in_model(model, LocalizationInfo("en"))
usage_info = list(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ def _is_long_iter(self, obj, level=0):
size = None
if size is not None and size > self.maxcollection[level]:
return True
return any(
(self._is_long_iter(item, level + 1) for item in obj)
) # noqa
return any((self._is_long_iter(item, level + 1) for item in obj)) # noqa
return any(
i > self.maxcollection[level] or self._is_long_iter(item, level + 1)
for i, item in enumerate(obj)
Expand Down Expand Up @@ -380,9 +378,7 @@ def _repr_obj(self, obj, level, limit_inner, limit_outer):
obj_repr = object.__repr__(obj)
except Exception:
try:
obj_repr = (
"<no repr available for " + type(obj).__name__ + ">"
) # noqa
obj_repr = "<no repr available for " + type(obj).__name__ + ">" # noqa
except Exception:
obj_repr = "<no repr available for object>"

Expand Down
6 changes: 3 additions & 3 deletions robotframework-ls/src/robotframework_ls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def import_robocorp_ls_core():
"Using vendored mode. Found: %s" % (vendored_folder,)
)
use_folder = vendored_folder
assert os.path.isdir(
use_folder
), "Expected: %s to exist and be a directory." % (use_folder,)
assert os.path.isdir(use_folder), (
"Expected: %s to exist and be a directory." % (use_folder,)
)

sys.path.append(use_folder)
import robocorp_ls_core
Expand Down
Loading

0 comments on commit 61f2baa

Please sign in to comment.