Skip to content

Commit

Permalink
Merge pull request #6 from pyiron/ruff
Browse files Browse the repository at this point in the history
add ruff linter
  • Loading branch information
jan-janssen authored May 14, 2024
2 parents d74489c + 624b62d commit 78aaf58
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 26 deletions.
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:
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:
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:
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])

0 comments on commit 78aaf58

Please sign in to comment.