diff --git a/.ci_support/release.py b/.ci_support/release.py index a3edb01..cb90330 100644 --- a/.ci_support/release.py +++ b/.ci_support/release.py @@ -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 @@ -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): @@ -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) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..23935ff --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/conda_subprocess/__init__.py b/conda_subprocess/__init__.py index 7705bcc..e74f09f 100644 --- a/conda_subprocess/__init__.py +++ b/conda_subprocess/__init__.py @@ -3,3 +3,10 @@ from . import _version __version__ = _version.get_versions()["version"] +__all__ = [ + Popen, + call, + check_call, + check_output, + run, +] diff --git a/conda_subprocess/interface.py b/conda_subprocess/interface.py index 1adcebe..de1fca2 100644 --- a/conda_subprocess/interface.py +++ b/conda_subprocess/interface.py @@ -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 diff --git a/setup.py b/setup.py index edb08a3..fcbb31f 100644 --- a/setup.py +++ b/setup.py @@ -5,4 +5,4 @@ setup( version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass(), -) \ No newline at end of file +) diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index cd12863..f7634ab 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -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])