From 67308794626946a5df1bbc760d71e25f260ce782 Mon Sep 17 00:00:00 2001 From: William Fondrie Date: Mon, 15 Apr 2024 16:10:52 -0700 Subject: [PATCH] Used Ruff to reformat --- .github/workflows/black.yml | 24 --------------------- .github/workflows/lint.yml | 30 ++++++++++++++++++++++++++ CHANGELOG.md | 28 +++++++++++++----------- ppx/__init__.py | 1 + ppx/config.py | 4 +++- ppx/factory.py | 13 +++++------ ppx/ftp.py | 1 + ppx/massive.py | 19 +++++++++------- ppx/ppx.py | 27 ++++++++++++++++------- ppx/pride.py | 1 + ppx/project.py | 5 ++++- setup.py | 1 + tests/conftest.py | 1 + tests/system_tests/test_cli.py | 1 + tests/unit_tests/test_cloud.py | 1 + tests/unit_tests/test_config.py | 1 + tests/unit_tests/test_download.py | 1 + tests/unit_tests/test_find_project.py | 1 + tests/unit_tests/test_list_projects.py | 1 + tests/unit_tests/test_massive.py | 1 + tests/unit_tests/test_pride.py | 5 ++++- tests/unit_tests/test_utils.py | 1 + 22 files changed, 106 insertions(+), 62 deletions(-) delete mode 100644 .github/workflows/black.yml create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index 7f09683..0000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Lint - -on: [push, pull_request] - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Setup Python 3.8 - uses: actions/setup-python@v2 - with: - python-version: "3.8" - - - name: Run black - uses: psf/black@stable - - - name: Check for debugging print statements - run: | - if grep -rq "print(" ppx; then - echo "Found the following print statements:" - grep -r "print(" ppx - exit 1 - fi diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..b8d7438 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Lint + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install Ruff + run: | + python -m pip install --upgrade pip + pip install ruff + + - name: Lint with Ruff + run: | + ruff check . --output-format=github + + - name: Check formatting with Ruff + run: | + ruff format --check . diff --git a/CHANGELOG.md b/CHANGELOG.md index 362086f..dbc79cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog for ppx ## [1.4.0] +### Changed +- Linting and formatting is now performed with Ruff. + ### Fixed - Fixed MassIVE FTP URLs using the MassIVE PROXI API. - Fixed PRIDE FTP URLs... again. @@ -8,7 +11,7 @@ ## [1.3.0] - 2022-04-39 ### Added -- Support for cloud provider destinations. Thanks @sooheon! +- Support for cloud provider destinations. Thanks @sooheon! ## [1.2.6] - 2022-03-16 ### Fixed @@ -47,25 +50,25 @@ ## [1.2.0] - 2021-09-14 ### Added -- New `timeout` parameter for most functions and classes. This specifies the +- New `timeout` parameter for most functions and classes. This specifies the maximum amount of time to wait for a response from the server. ### Changed - The backend for MassIVE now uses the GNPS API to list files and projects, - only falling back to scraping the FTP server on failure. This should make + only falling back to scraping the FTP server on failure. This should make it much faster. Thanks @mwang87! - Files and projects are now returned in sorted order. ### Fixed -- Poor connections with PRIDE were leading to a number of occasional errors. - Multiple reconnect attempts are now tried for a wider variety of FTP +- Poor connections with PRIDE were leading to a number of occasional errors. + Multiple reconnect attempts are now tried for a wider variety of FTP operations. ## [1.1.1] - 2021-07-02 ### Fixed - Downloading files is now more robust. ppx will now retry FTP connections up to 10 times if the connection was dropped or refused. -- Partial downloads are now continued automatically by comparing the local +- Partial downloads are now continued automatically by comparing the local file size to the remote file size. ## [1.1.0] - 2021-05-18 @@ -75,26 +78,25 @@ instead. **Note that this may change the number, identity, and order of the file that were previously returned for PRIDE projects!** - Small documentation updates. - + ### Added -- Caching of the remote files and directories found for a project. If a +- Caching of the remote files and directories found for a project. If a project's `fetch` attribute is `False`, then we'll rely on this cached data, so long as it is available. Setting `fetch=True` will always refresh the data from the repository. -## [1.0.0] - 2021-05-14 -### Changed +## [1.0.0] - 2021-05-14 +### Changed - **We did a complete rework of the API!** This will break nearly all previous code using ppx, but greatly improves its versatility. See the [docs](https://ppx.readthedocs.io) for more details - Updated the build to align with [PEP517](https://www.python.org/dev/peps/pep-0517/) - + ### Added -- A command line interface for downloading files from PRIDE and MassIVE +- A command line interface for downloading files from PRIDE and MassIVE projects. - Additional unit tests. - A ppx logo - This changelog. - ppx is now available on bioconda! - diff --git a/ppx/__init__.py b/ppx/__init__.py index de4a7d0..dd2571f 100644 --- a/ppx/__init__.py +++ b/ppx/__init__.py @@ -1,4 +1,5 @@ """See the README for detailed documentation and examples.""" + try: from importlib.metadata import PackageNotFoundError, version diff --git a/ppx/config.py b/ppx/config.py index 87e5ac0..3a3be7c 100644 --- a/ppx/config.py +++ b/ppx/config.py @@ -1,4 +1,5 @@ """This module contains the configuration details for ppx""" + import logging import os from pathlib import Path @@ -43,7 +44,8 @@ def path(self, path): path = self._resolve_path(path) if not path.exists(): raise FileNotFoundError( - f"The specified directory or bucket ({path}) " "does not exist." + f"The specified directory or bucket ({path}) " + "does not exist." ) self._path = path diff --git a/ppx/factory.py b/ppx/factory.py index 6747ecb..ce00ca0 100644 --- a/ppx/factory.py +++ b/ppx/factory.py @@ -2,6 +2,7 @@ This is the foundation of the ppx package. """ + import logging import re from urllib.parse import urlparse @@ -78,11 +79,11 @@ def id(self): def find(self): """Find the dataset at the partner repository""" - kwargs = dict( - local=self._local, - fetch=self._fetch, - timeout=self._timeout, - ) + kwargs = { + "local": self._local, + "fetch": self._fetch, + "timeout": self._timeout, + } if self._repo == "PRIDE": return PrideProject(self._repo_id, **kwargs) @@ -164,7 +165,7 @@ def find_project(identifier, local=None, repo=None, fetch=False, timeout=10.0): repo = str(repo).lower() # User-specified: - kwargs = dict(local=local, fetch=fetch, timeout=timeout) + kwargs = {"local": local, "fetch": fetch, "timeout": timeout} if repo == "pride": return PrideProject(identifier, **kwargs) diff --git a/ppx/ftp.py b/ppx/ftp.py index 1ea74a4..2265171 100644 --- a/ppx/ftp.py +++ b/ppx/ftp.py @@ -1,4 +1,5 @@ """General utilities for working with the repository FTP sites.""" + import logging import re import socket diff --git a/ppx/massive.py b/ppx/massive.py index cec234d..bcc5576 100644 --- a/ppx/massive.py +++ b/ppx/massive.py @@ -1,4 +1,5 @@ """MassIVE datasets.""" + import logging import re import socket @@ -50,12 +51,12 @@ class MassiveProject(BaseProject): def __init__(self, msv_id, local=None, fetch=False, timeout=10.0): """Instantiate a MSVDataset object""" super().__init__(msv_id, local, fetch, timeout) - self._params = dict( - _stream="on", - _sort="filepath", - dataset__exact=self.id, - _size="max", - ) + self._params = { + "_stream": "on", + "_sort": "filepath", + "dataset__exact": self.id, + "_size": "max", + } def _validate_id(self, identifier): """Validate a MassIVE identifier. @@ -143,7 +144,9 @@ def remote_files(self, glob=None): if self.fetch or self._remote_files is None: try: info = self.file_info().splitlines()[1:] - self._remote_files = [r.split(",")[0].split("/", 1)[1] for r in info] + self._remote_files = [ + r.split(",")[0].split("/", 1)[1] for r in info + ] assert self._remote_files except ( TimeoutError, @@ -211,7 +214,7 @@ def list_projects(timeout=10.0): """ url = "https://gnps-datasetcache.ucsd.edu/datasette/database.csv" - params = dict(sql="select distinct dataset from filename", _size="max") + params = {"sql": "select distinct dataset from filename", "_size": "max"} try: res = requests.get(url, params, timeout=timeout).text.splitlines()[1:] res.sort() diff --git a/ppx/ppx.py b/ppx/ppx.py index 65fb1e4..902ad6a 100644 --- a/ppx/ppx.py +++ b/ppx/ppx.py @@ -1,4 +1,5 @@ """The command line entry point for ppx""" + import logging import sys from argparse import ArgumentParser @@ -11,9 +12,9 @@ def get_parser(): """Parse the command line arguments""" - desc = """Use this command line utility to download files from the PRIDE and MassIVE - proteomics repositories. The paths to the downloaded files are written to - stdout.""" + desc = """Use this command line utility to download files from the PRIDE + and MassIVE proteomics repositories. The paths to the downloaded files are + written to stdout.""" epilog = "More documentation and examples at: https://ppx.readthedocs.io" parser = ArgumentParser(description=desc, epilog=epilog) @@ -21,7 +22,10 @@ def get_parser(): parser.add_argument( "identifier", type=str, - help=("The ProteomeXchange, PRIDE, or MassIVE identifier for the " "project."), + help=( + "The ProteomeXchange, PRIDE, or MassIVE identifier for the " + "project." + ), ) parser.add_argument( @@ -79,7 +83,9 @@ def get_parser(): def main(): """Run ppx""" - logging.basicConfig(level=logging.INFO, format="[%(levelname)s]: %(message)s") + logging.basicConfig( + level=logging.INFO, format="[%(levelname)s]: %(message)s" + ) parser = get_parser() args = parser.parse_args() @@ -95,16 +101,21 @@ def main(): matches.update(pat_match) if not all(passed): - failed = " \n".join([f for f, p in zip(args.files, passed) if not p]) + failed = " \n".join( + [f for f, p in zip(args.files, passed) if not p] + ) raise FileNotFoundError( - "Unable to find one or more of the files or patterns:" f"\n {failed}" + "Unable to find one or more of the files or patterns:" + f"\n {failed}" ) else: matches = remote_files - LOGGER.info("Downloading %i files from %s...", len(matches), args.identifier) + LOGGER.info( + "Downloading %i files from %s...", len(matches), args.identifier + ) downloaded = proj.download(matches) for local_file in downloaded: diff --git a/ppx/pride.py b/ppx/pride.py index 9637fbd..5737ad2 100644 --- a/ppx/pride.py +++ b/ppx/pride.py @@ -1,4 +1,5 @@ """A class for PRIDE datasets""" + import json import re diff --git a/ppx/project.py b/ppx/project.py index 8711e39..b3e237b 100644 --- a/ppx/project.py +++ b/ppx/project.py @@ -1,4 +1,5 @@ """A base dataset class""" + from abc import ABC, abstractmethod from pathlib import Path @@ -239,7 +240,9 @@ def download(self, files, force_=False, silent=False): f"{', '.join(missing)}" ) - return self._parser.download(files, self.local, force_=force_, silent=silent) + return self._parser.download( + files, self.local, force_=force_, silent=silent + ) def cache(files, cache_file, fetch): diff --git a/setup.py b/setup.py index 10d9469..89817d6 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ """Setup ppx""" + import setuptools setuptools.setup() diff --git a/tests/conftest.py b/tests/conftest.py index d627a9e..93b9f1d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,6 +7,7 @@ - A mock FTP server response from PRIDE - A mock FTP server response from MassIVE """ + import ftplib import json import socket diff --git a/tests/system_tests/test_cli.py b/tests/system_tests/test_cli.py index e50d91e..2215f63 100644 --- a/tests/system_tests/test_cli.py +++ b/tests/system_tests/test_cli.py @@ -1,4 +1,5 @@ """Test the command line interface""" + import subprocess PXID = "PXD000001" diff --git a/tests/unit_tests/test_cloud.py b/tests/unit_tests/test_cloud.py index d9cf789..29eebe6 100644 --- a/tests/unit_tests/test_cloud.py +++ b/tests/unit_tests/test_cloud.py @@ -1,4 +1,5 @@ """Test using cloud locations""" + from cloudpathlib import CloudPath import ppx diff --git a/tests/unit_tests/test_config.py b/tests/unit_tests/test_config.py index 908309e..d0d530f 100644 --- a/tests/unit_tests/test_config.py +++ b/tests/unit_tests/test_config.py @@ -1,4 +1,5 @@ """Test the configuration""" + from pathlib import Path import pytest diff --git a/tests/unit_tests/test_download.py b/tests/unit_tests/test_download.py index 9d855d8..323d8ec 100644 --- a/tests/unit_tests/test_download.py +++ b/tests/unit_tests/test_download.py @@ -2,6 +2,7 @@ These tests are in a separate file because they all require internet access. """ + from ftplib import FTP, error_temp import pytest diff --git a/tests/unit_tests/test_find_project.py b/tests/unit_tests/test_find_project.py index eeabea3..4984eee 100644 --- a/tests/unit_tests/test_find_project.py +++ b/tests/unit_tests/test_find_project.py @@ -1,4 +1,5 @@ """Test finding projects""" + import pytest from requests.exceptions import ConnectTimeout, ReadTimeout diff --git a/tests/unit_tests/test_list_projects.py b/tests/unit_tests/test_list_projects.py index 85dc90c..0cddd61 100644 --- a/tests/unit_tests/test_list_projects.py +++ b/tests/unit_tests/test_list_projects.py @@ -1,4 +1,5 @@ """Test that the list_projects() functions work""" + import pytest import requests diff --git a/tests/unit_tests/test_massive.py b/tests/unit_tests/test_massive.py index df5b278..c23bf43 100644 --- a/tests/unit_tests/test_massive.py +++ b/tests/unit_tests/test_massive.py @@ -1,4 +1,5 @@ """Test MassIVE functionality w/o internet access""" + import shutil from pathlib import Path diff --git a/tests/unit_tests/test_pride.py b/tests/unit_tests/test_pride.py index 9ccc75d..df7e107 100644 --- a/tests/unit_tests/test_pride.py +++ b/tests/unit_tests/test_pride.py @@ -1,4 +1,5 @@ """Test PRIDE functionality w/o internet access""" + import json from pathlib import Path @@ -71,7 +72,9 @@ def test_metadata(mock_pride_project_response): assert meta == true_meta - title = "TMT spikes - Using R and Bioconductor for proteomics data analysis" + title = ( + "TMT spikes - Using R and Bioconductor for proteomics data analysis" + ) assert proj.title == title desc = ( diff --git a/tests/unit_tests/test_utils.py b/tests/unit_tests/test_utils.py index b700d3e..65f13ae 100644 --- a/tests/unit_tests/test_utils.py +++ b/tests/unit_tests/test_utils.py @@ -1,4 +1,5 @@ """Test the utility functions""" + import pytest import requests