From 40cfd8da6f3021a4a714c885cf0a15034ea900ba Mon Sep 17 00:00:00 2001 From: Joachim Moeyens Date: Tue, 29 Oct 2024 14:18:09 -0700 Subject: [PATCH] Swap to pdm --- .github/workflows/conda-build-lint-test.yml | 16 ++- .github/workflows/conda-publish.yml | 33 ------ .github/workflows/docker-build-lint-test.yml | 19 ++-- .../pip-build-lint-test-coverage.yml | 30 +++--- .gitignore | 5 + .pre-commit-config.yaml | 31 ------ Dockerfile | 29 ++--- LICENSE.md | 2 +- MANIFEST.in | 2 +- additional_requirements.txt | 1 - pyproject.toml | 102 +++++++++++------- recipe/meta.yaml | 38 ------- requirements.txt | 10 -- setup.cfg | 7 -- {difi => src/difi}/__init__.py | 2 +- {difi => src/difi}/cifi.py | 0 {difi => src/difi}/difi.py | 6 +- {difi => src/difi}/experimental/miniDifi.py | 0 {difi => src/difi}/experimental/rundifi.py | 0 {difi => src/difi}/io.py | 0 {difi => src/difi}/metrics.py | 0 {difi => src/difi}/tests/__init__.py | 0 {difi => src/difi}/tests/conftest.py | 0 {difi => src/difi}/tests/linkagesByLine.txt | 0 {difi => src/difi}/tests/test_cifi.py | 0 .../difi}/tests/test_cifi_benchmarks.py | 0 {difi => src/difi}/tests/test_difi.py | 0 .../difi}/tests/test_difi_benchmarks.py | 0 {difi => src/difi}/tests/test_io.py | 0 {difi => src/difi}/tests/test_metrics.py | 0 .../difi}/tests/test_metrics_benchmarks.py | 0 .../difi}/tests/test_observations.csv | 0 {difi => src/difi}/tests/test_utils.py | 0 {difi => src/difi}/utils.py | 4 +- 34 files changed, 117 insertions(+), 220 deletions(-) delete mode 100644 .github/workflows/conda-publish.yml delete mode 100644 .pre-commit-config.yaml delete mode 100644 additional_requirements.txt delete mode 100644 recipe/meta.yaml delete mode 100644 requirements.txt delete mode 100644 setup.cfg rename {difi => src/difi}/__init__.py (79%) rename {difi => src/difi}/cifi.py (100%) rename {difi => src/difi}/difi.py (99%) rename {difi => src/difi}/experimental/miniDifi.py (100%) rename {difi => src/difi}/experimental/rundifi.py (100%) rename {difi => src/difi}/io.py (100%) rename {difi => src/difi}/metrics.py (100%) rename {difi => src/difi}/tests/__init__.py (100%) rename {difi => src/difi}/tests/conftest.py (100%) rename {difi => src/difi}/tests/linkagesByLine.txt (100%) rename {difi => src/difi}/tests/test_cifi.py (100%) rename {difi => src/difi}/tests/test_cifi_benchmarks.py (100%) rename {difi => src/difi}/tests/test_difi.py (100%) rename {difi => src/difi}/tests/test_difi_benchmarks.py (100%) rename {difi => src/difi}/tests/test_io.py (100%) rename {difi => src/difi}/tests/test_metrics.py (100%) rename {difi => src/difi}/tests/test_metrics_benchmarks.py (100%) rename {difi => src/difi}/tests/test_observations.csv (100%) rename {difi => src/difi}/tests/test_utils.py (100%) rename {difi => src/difi}/utils.py (99%) diff --git a/.github/workflows/conda-build-lint-test.yml b/.github/workflows/conda-build-lint-test.yml index ceea041..7807e06 100644 --- a/.github/workflows/conda-build-lint-test.yml +++ b/.github/workflows/conda-build-lint-test.yml @@ -1,4 +1,4 @@ -name: conda - Build, Lint, and Test +name: conda - Build Lint and Test on: push: @@ -12,27 +12,25 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ["3.10"] defaults: run: shell: bash -l {0} steps: - name: Checkout git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get git tags run: git fetch --prune --unshallow --tags - name: Set up miniconda - uses: conda-incubator/setup-miniconda@v2 + uses: conda-incubator/setup-miniconda@v3 with: activate-environment: "difi" auto-update-conda: true python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: conda install -c defaults -c conda-forge --file requirements.txt --yes - name: Build and install - run: pip install . --no-deps + run: pip install .[dev] - name: Lint - run: pre-commit run --all-files + run: pdm lint - name: Test - run: pytest . --cov + run: pdm test \ No newline at end of file diff --git a/.github/workflows/conda-publish.yml b/.github/workflows/conda-publish.yml deleted file mode 100644 index 34d1489..0000000 --- a/.github/workflows/conda-publish.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: conda - Publish - -on: - push: - tags: - - 'v*' - -jobs: - publish: - runs-on: ubuntu-latest - container: - image: continuumio/miniconda3 - - steps: - - uses: actions/checkout@v3 - - name: Install dependencies - run: | - conda install -y anaconda-client conda-build - conda install -y setuptools setuptools_scm - - name: Update recipe with version variable - run: | - VERSION=$(python -m setuptools_scm) - LINE_STR='{% set version = "'${VERSION}'" %}' - RECIPE_PATH='recipe/meta.yaml' - echo $LINE_STR | cat - $RECIPE_PATH > temp && mv temp $RECIPE_PATH - - - name: Build and publish - env: - CONDA_USERNAME: ${{ secrets.CONDA_USERNAME }} - CONDA_TOKEN: ${{ secrets.CONDA_TOKEN }} - run: | - conda config --set anaconda_upload yes - conda build . --token $CONDA_TOKEN --user $CONDA_USERNAME diff --git a/.github/workflows/docker-build-lint-test.yml b/.github/workflows/docker-build-lint-test.yml index fb86df4..cd61079 100644 --- a/.github/workflows/docker-build-lint-test.yml +++ b/.github/workflows/docker-build-lint-test.yml @@ -1,4 +1,4 @@ -name: docker - Build, Lint, and Test +name: docker - Build Lint and Test on: push: @@ -11,20 +11,17 @@ jobs: runs-on: ubuntu-latest env: IMAGE_TAG: ${{ github.sha }} - + steps: - name: Checkout git repo - uses: actions/checkout@v3 - - uses: jpribyl/action-docker-layer-caching@v0.1.0 - # Ignore the failure of a step and avoid terminating the job. - continue-on-error: true + uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 with: install: true - - name: Build and install - run: docker build --load -t precovery:$IMAGE_TAG . + - name: Build + run: docker build --load -t difi:$IMAGE_TAG . - name: Lint - run: docker run -i precovery:$IMAGE_TAG pre-commit run --all-files + run: docker run -i difi:$IMAGE_TAG pdm lint - name: Test - run: docker run -i precovery:$IMAGE_TAG pytest . --cov + run: docker run -i difi:$IMAGE_TAG pdm test \ No newline at end of file diff --git a/.github/workflows/pip-build-lint-test-coverage.yml b/.github/workflows/pip-build-lint-test-coverage.yml index ed5c584..6d625e8 100644 --- a/.github/workflows/pip-build-lint-test-coverage.yml +++ b/.github/workflows/pip-build-lint-test-coverage.yml @@ -1,4 +1,4 @@ -name: pip - Build, Lint, Test, and Coverage +name: pip - Build Lint Test and Coverage on: push: @@ -12,30 +12,32 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ["3.10"] defaults: run: shell: bash -l {0} steps: - name: Checkout git repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get git tags run: git fetch --prune --unshallow --tags - - name: Set up miniconda - uses: conda-incubator/setup-miniconda@v2 + - uses: actions/setup-python@v5 with: - activate-environment: "difi" - auto-update-conda: true python-version: ${{ matrix.python-version }} - - name: Build and install - run: pip install .[tests] + cache: 'pip' # caching pip dependencies + - name: Install Dependencies + run: | + pip install pip --upgrade + pip install ".[dev]" - name: Lint - run: pre-commit run --all-files - - name: Test - run: pytest . --cov --cov-report xml - - name: Coverage + run: pdm run lint + # - name: Type check + # run: pdm run typecheck + - name: Test with coverage + run: pdm run coverage + - name: Coverage Report uses: coverallsapp/github-action@v2.0.0 with: github-token: ${{ secrets.COVERALLS_TOKEN }} - path-to-lcov: coverage.xml + path-to-lcov: coverage.xml \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8f5ad7c..95be9c7 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,8 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +# pdm virtual environments +.pdm-python +pdm.lock +_version.py \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index ddbbad8..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,31 +0,0 @@ -# See https://pre-commit.com for more information -# See https://pre-commit.com/hooks.html for more hooks -default_language_version: - python: python3.10 -repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 - hooks: - - id: trailing-whitespace - args: [--markdown-linebreak-ext=md] - - id: end-of-file-fixer - - id: check-yaml - - id: check-added-large-files -- repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 - hooks: - - id: flake8 -- repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - additional_dependencies: - - toml -- repo: https://github.com/psf/black - rev: 22.10.0 - hooks: - - id: black -- repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.1.1 - hooks: - - id: mypy diff --git a/Dockerfile b/Dockerfile index 3f691ac..87a0f66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,16 @@ -FROM ubuntu:latest +FROM python:3.11 + +# Set shell to bash +SHELL ["/bin/bash", "-c"] +CMD ["/bin/bash"] # Update system dependencies RUN apt-get update \ - && apt-get upgrade -y - -# Install system dependencies -RUN apt-get install -y git python3 python3-pip python3-dev - -# Upgrade pip to the latest version and install pre-commit -RUN pip install --upgrade pip pre-commit - -# Install pre-commit hooks (before difi is installed to cache this step) -# Remove the .git directory after pre-commit is installed as difi's .git -# will be added to the container -RUN mkdir /code/ -COPY .pre-commit-config.yaml /code/ -WORKDIR /code/ -RUN git init . \ - && pre-commit install-hooks \ - && rm -rf .git + && apt-get upgrade -y \ + && apt-get install -y pip git # Install difi +RUN mkdir -p /code/ +WORKDIR /code/ ADD . /code/ -RUN pip install -e .[tests] +RUN pip install -e .[dev] diff --git a/LICENSE.md b/LICENSE.md index 3debbab..9ce2fa9 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2018-2023, Joachim Moeyens +Copyright (c) 2018-2024, Joachim Moeyens All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/MANIFEST.in b/MANIFEST.in index 934423d..f283969 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ -include difi/*.py +include src/*.py include *.md include *.toml exclude Dockerfile diff --git a/additional_requirements.txt b/additional_requirements.txt deleted file mode 100644 index 2f4f122..0000000 --- a/additional_requirements.txt +++ /dev/null @@ -1 +0,0 @@ -jupyter diff --git a/pyproject.toml b/pyproject.toml index e11fd39..73d2c07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,13 +1,6 @@ -[build-system] -requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"] -build-backend = "setuptools.build_meta" - -[tool.setuptools_scm] -write_to = "difi/version.py" -write_to_template = "__version__ = '{version}'" - [project] name = "difi" +dynamic = ["version"] authors = [ {name = "Joachim Moeyens", email = "moeyensj@uw.edu"}, ] @@ -17,62 +10,93 @@ maintainers = [ description = "Did I Find It?" readme = "README.md" license = {file = "LICENSE.md"} -keywords = [ - "astronomy", - "astrophysics", - "space", - "science", - "asteroids", - "comets", - "solar system" -] +requires-python = ">=3.10" classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering :: Astronomy", "Topic :: Scientific/Engineering :: Physics", ] -requires-python = ">=3.8" +keywords = [ + "astronomy", + "astrophysics", + "space", + "science", + "asteroids", + "comets", + "solar system" +] + dependencies = [ "numba", "numpy", "pandas", ] -dynamic = ["version"] -[project.urls] -homepage = "https://github.com/moeyensj/difi" -repository = "https://github.com/moeyensj/difi" +[build-system] +requires = ["pdm-backend"] +build-backend = "pdm.backend" +[tool.pdm.build] +includes = ["src/difi/"] -[project.optional-dependencies] -tests = [ - "pytest", - "pytest-cov", - "pytest-benchmark", - "pre-commit", -] +[tool.pdm.version] +source = "scm" +write_to = "src/difi/_version.py" +write_template = "__version__ = '{}'" -[tool.pytest.ini_options] -addopts = ["--benchmark-skip"] +[tool.pdm.scripts] +check = { composite = ["lint", "typecheck", "test"] } +format = { composite = ["black ./src/difi", "isort ./src/difi"] } +lint = { composite = [ + "ruff check ./src/difi", + "black --check ./src/difi", + "isort --check-only ./src/difi", +] } +fix = "ruff ./src/difi --fix" +typecheck = "mypy --strict ./src/difi" -[tool.setuptools] -include-package-data = true +test = "pytest --benchmark-disable {args}" +doctest = "pytest --doctest-plus --doctest-only" +benchmark = "pytest --benchmark-only" +coverage = "pytest --cov=difi --cov-report=xml" -[tool.setuptools.packages.find] -include = ['difi*'] +[project.urls] +"Documentation" = "https://github.com/moeyensj/difi#README.md" +"Issues" = "https://github.com/moeyensj/difi/issues" +"Source" = "https://github.com/moeyensj/difi" -[tool.setuptools.package-data] -difi = ["tests/*.txt"] +[project.optional-dependencies] +dev = [ + "black", + "ipython", + "isort", + "mypy", + "pdm", + "pytest-benchmark", + "pytest-cov", + "pytest-doctestplus", + "pytest-mock", + "pytest", + "ruff", +] [tool.black] line-length = 110 [tool.isort] profile = "black" + +[tool.ruff] +line-length = 110 +target-version = "py311" +lint.ignore = [] +exclude = ["build"] + +[tool.mypy] +ignore_missing_imports = true diff --git a/recipe/meta.yaml b/recipe/meta.yaml deleted file mode 100644 index a897ee4..0000000 --- a/recipe/meta.yaml +++ /dev/null @@ -1,38 +0,0 @@ - -package: - name: difi - version: "{{ version }}" - -source: - git_url: "https://github.com/moeyensj/difi.git" - git_tag: "v{{ version }}" - -requirements: - host: - - python >=3.8 - - pip - - setuptools >=45 - - wheel - - setuptools_scm >=6.0 - run: - - python >=3.8 - - numba - - numpy - - pandas - - pytest - - pytest-cov - - pytest-benchmark - - pre-commit - -build: - noarch: python - script: pip install . - -test: - imports: - - difi - -about: - home: https://github.com/moeyensj/difi - license: BSD-3 Clause - license_file: LICENSE.md diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index aedd44d..0000000 --- a/requirements.txt +++ /dev/null @@ -1,10 +0,0 @@ -numba -numpy -pandas -pytest -pytest-cov -pytest-benchmark -pre-commit -setuptools>=45 -wheel -setuptools_scm>=6.0 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index c7a675b..0000000 --- a/setup.cfg +++ /dev/null @@ -1,7 +0,0 @@ -[flake8] -max_line_length = 110 -ignore = - W503 - E203 -exclude = - build diff --git a/difi/__init__.py b/src/difi/__init__.py similarity index 79% rename from difi/__init__.py rename to src/difi/__init__.py index c36829f..ebd504f 100644 --- a/difi/__init__.py +++ b/src/difi/__init__.py @@ -1,7 +1,7 @@ # flake8: noqa: F401,F403 +from ._version import __version__ from .cifi import * from .difi import * from .io import * from .metrics import * from .utils import * -from .version import __version__ diff --git a/difi/cifi.py b/src/difi/cifi.py similarity index 100% rename from difi/cifi.py rename to src/difi/cifi.py diff --git a/difi/difi.py b/src/difi/difi.py similarity index 99% rename from difi/difi.py rename to src/difi/difi.py index 7bf9682..bee3681 100644 --- a/difi/difi.py +++ b/src/difi/difi.py @@ -244,9 +244,9 @@ def analyzeLinkages( all_objects["object_id"] = all_objects["object_id"].astype(str) num_obs_per_object = observations["object_id"].value_counts() - all_objects.loc[ - all_objects["object_id"].isin(num_obs_per_object.index.values), "num_obs" - ] = num_obs_per_object.values + all_objects.loc[all_objects["object_id"].isin(num_obs_per_object.index.values), "num_obs"] = ( + num_obs_per_object.values + ) all_objects.sort_values( by=["num_obs", "object_id"], ascending=[False, True], inplace=True, ignore_index=True diff --git a/difi/experimental/miniDifi.py b/src/difi/experimental/miniDifi.py similarity index 100% rename from difi/experimental/miniDifi.py rename to src/difi/experimental/miniDifi.py diff --git a/difi/experimental/rundifi.py b/src/difi/experimental/rundifi.py similarity index 100% rename from difi/experimental/rundifi.py rename to src/difi/experimental/rundifi.py diff --git a/difi/io.py b/src/difi/io.py similarity index 100% rename from difi/io.py rename to src/difi/io.py diff --git a/difi/metrics.py b/src/difi/metrics.py similarity index 100% rename from difi/metrics.py rename to src/difi/metrics.py diff --git a/difi/tests/__init__.py b/src/difi/tests/__init__.py similarity index 100% rename from difi/tests/__init__.py rename to src/difi/tests/__init__.py diff --git a/difi/tests/conftest.py b/src/difi/tests/conftest.py similarity index 100% rename from difi/tests/conftest.py rename to src/difi/tests/conftest.py diff --git a/difi/tests/linkagesByLine.txt b/src/difi/tests/linkagesByLine.txt similarity index 100% rename from difi/tests/linkagesByLine.txt rename to src/difi/tests/linkagesByLine.txt diff --git a/difi/tests/test_cifi.py b/src/difi/tests/test_cifi.py similarity index 100% rename from difi/tests/test_cifi.py rename to src/difi/tests/test_cifi.py diff --git a/difi/tests/test_cifi_benchmarks.py b/src/difi/tests/test_cifi_benchmarks.py similarity index 100% rename from difi/tests/test_cifi_benchmarks.py rename to src/difi/tests/test_cifi_benchmarks.py diff --git a/difi/tests/test_difi.py b/src/difi/tests/test_difi.py similarity index 100% rename from difi/tests/test_difi.py rename to src/difi/tests/test_difi.py diff --git a/difi/tests/test_difi_benchmarks.py b/src/difi/tests/test_difi_benchmarks.py similarity index 100% rename from difi/tests/test_difi_benchmarks.py rename to src/difi/tests/test_difi_benchmarks.py diff --git a/difi/tests/test_io.py b/src/difi/tests/test_io.py similarity index 100% rename from difi/tests/test_io.py rename to src/difi/tests/test_io.py diff --git a/difi/tests/test_metrics.py b/src/difi/tests/test_metrics.py similarity index 100% rename from difi/tests/test_metrics.py rename to src/difi/tests/test_metrics.py diff --git a/difi/tests/test_metrics_benchmarks.py b/src/difi/tests/test_metrics_benchmarks.py similarity index 100% rename from difi/tests/test_metrics_benchmarks.py rename to src/difi/tests/test_metrics_benchmarks.py diff --git a/difi/tests/test_observations.csv b/src/difi/tests/test_observations.csv similarity index 100% rename from difi/tests/test_observations.csv rename to src/difi/tests/test_observations.csv diff --git a/difi/tests/test_utils.py b/src/difi/tests/test_utils.py similarity index 100% rename from difi/tests/test_utils.py rename to src/difi/tests/test_utils.py diff --git a/difi/utils.py b/src/difi/utils.py similarity index 99% rename from difi/utils.py rename to src/difi/utils.py index dbdc078..53beebb 100644 --- a/difi/utils.py +++ b/src/difi/utils.py @@ -127,7 +127,7 @@ def _classHandler( object_ids_list = [dataframe["object_id"].unique()] unique_objects = [object_ids_list[0]] - elif type(classes) == str: + elif isinstance(classes, str): if classes not in dataframe.columns: err = "Could not find class column ({}) in observations." raise ValueError(err.format(classes)) @@ -140,7 +140,7 @@ def _classHandler( object_ids_list[0] = dataframe["object_id"].unique() - elif type(classes) == dict: + elif isinstance(classes, dict): for c, t in classes.items(): if len(np.unique(t)) != len(t): err = "Truths for class {} are not unique."