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

add ruff linter #6

Merged
merged 1 commit into from
May 14, 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
37 changes: 23 additions & 14 deletions .ci_support/release.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
def get_setup_version_and_pattern(setup_content):
depend_lst, version_lst = [], []
for l in setup_content:
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename the variable l to a more descriptive name for clarity.

-    for l in setup_content:
+    for line in setup_content:

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
for l in setup_content:
for line in setup_content:

if '==' in l:
lst = l.split('[')[-1].split(']')[0].replace(' ', '').replace('"', '').replace("'", '').split(',')
if "==" in l:
lst = (
l.split("[")[-1]
.split("]")[0]
.replace(" ", "")
.replace('"', "")
.replace("'", "")
.split(",")
)
for dep in lst:
if dep != '\n':
version_lst.append(dep.split('==')[1])
depend_lst.append(dep.split('==')[0])
if dep != "\n":
version_lst.append(dep.split("==")[1])
depend_lst.append(dep.split("==")[0])

version_high_dict = {d: v for d, v in zip(depend_lst, version_lst)}
return version_high_dict
Expand All @@ -16,14 +23,14 @@ def get_env_version(env_content):
read_flag = False
depend_lst, version_lst = [], []
for l in env_content:
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename the variable l to a more descriptive name for clarity.

-    for l in env_content:
+    for line in env_content:

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
for l in env_content:
for line in env_content:

if 'dependencies:' in l:
if "dependencies:" in l:
read_flag = True
elif read_flag:
lst = l.replace('-', '').replace(' ', '').replace('\n', '').split("=")
lst = l.replace("-", "").replace(" ", "").replace("\n", "").split("=")
if len(lst) == 2:
depend_lst.append(lst[0])
version_lst.append(lst[1])
return {d:v for d, v in zip(depend_lst, version_lst)}
return {d: v for d, v in zip(depend_lst, version_lst)}


def update_dependencies(setup_content, version_low_dict, version_high_dict):
Expand All @@ -35,27 +42,29 @@ def update_dependencies(setup_content, version_low_dict, version_high_dict):
version_combo_dict[dep] = dep + "==" + ver

setup_content_new = ""
pattern_dict = {d:d + "==" + v for d, v in version_high_dict.items()}
pattern_dict = {d: d + "==" + v for d, v in version_high_dict.items()}
for l in setup_content:
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename the variable l to a more descriptive name for clarity.

-    for l in setup_content:
+    for line in setup_content:

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
for l in setup_content:
for line in setup_content:

for k, v in pattern_dict.items():
if v in l:
l = l.replace(v, version_combo_dict[k])
setup_content_new +=l
setup_content_new += l
return setup_content_new


if __name__ == "__main__":
with open('pyproject.toml', "r") as f:
with open("pyproject.toml", "r") as f:
setup_content = f.readlines()

with open('environment.yml', "r") as f:
with open("environment.yml", "r") as f:
env_content = f.readlines()

setup_content_new = update_dependencies(
setup_content=setup_content[2:],
version_low_dict=get_env_version(env_content=env_content),
version_high_dict=get_setup_version_and_pattern(setup_content=setup_content[2:]),
version_high_dict=get_setup_version_and_pattern(
setup_content=setup_content[2:]
),
)

with open('pyproject.toml', "w") as f:
with open("pyproject.toml", "w") as f:
f.writelines("".join(setup_content[:2]) + setup_content_new)
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
name: ruff lint
args: ["--fix"]
files: ^conda_subprocess/
- id: ruff-format
name: ruff format
7 changes: 7 additions & 0 deletions conda_subprocess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
from . import _version

__version__ = _version.get_versions()["version"]
__all__ = [
Popen,
call,
check_call,
check_output,
run,
]
9 changes: 4 additions & 5 deletions conda_subprocess/interface.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import os
from subprocess import PIPE, TimeoutExpired, CalledProcessError, CompletedProcess

from conda_subprocess.process import Popen


# use presence of msvcrt to detect Windows-like platforms (see bpo-8110)
try:
import msvcrt
except ModuleNotFoundError:
_mswindows = False
else:
if os.name == "nt":
_mswindows = True
else:
_mswindows = False


# Copied from subprocess.py
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
setup(
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
)
)
25 changes: 19 additions & 6 deletions tests/test_conda_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,34 @@ def test_check_call(self):

def test_check_output(self):
if os.name == "nt":
self.assertEqual(check_output("python --version", prefix_path=self.env_path), b'Python 3.12.1\r\n')
self.assertEqual(
check_output("python --version", prefix_path=self.env_path),
b"Python 3.12.1\r\n",
)
else:
self.assertEqual(check_output("python --version", prefix_path=self.env_path), b'Python 3.12.1\n')
self.assertEqual(
check_output("python --version", prefix_path=self.env_path),
b"Python 3.12.1\n",
)

def test_check_output_universal_newlines(self):
self.assertEqual(check_output("python --version", prefix_path=self.env_path, universal_newlines=True), 'Python 3.12.1\n')
self.assertEqual(
check_output(
"python --version", prefix_path=self.env_path, universal_newlines=True
),
"Python 3.12.1\n",
)

def test_run(self):
self.assertEqual(run("python --version", prefix_path=self.env_path).returncode, 0)
self.assertEqual(
run("python --version", prefix_path=self.env_path).returncode, 0
)

def test_popen(self):
process = Popen("python --version", prefix_path=self.env_path, stdout=PIPE)
output = process.communicate()
if os.name == "nt":
self.assertEqual(output[0], b'Python 3.12.1\r\n')
self.assertEqual(output[0], b"Python 3.12.1\r\n")
else:
self.assertEqual(output[0], b'Python 3.12.1\n')
self.assertEqual(output[0], b"Python 3.12.1\n")
self.assertIsNone(output[1])
Loading