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

Fix #261 - pkg_resources migration #262

Merged
merged 17 commits into from
Dec 4, 2024
Merged

Fix #261 - pkg_resources migration #262

merged 17 commits into from
Dec 4, 2024

Conversation

dnil
Copy link
Collaborator

@dnil dnil commented Nov 29, 2024

Description

Fixed

  • Refactored (mostly ChatGPT - thank you!) to use importlib
  • Refactored to use pathlib instead of os.path and path.py

I have aimed to have it safe for python >=3.9. As the PR is now, it might theoretically work back to 3.5/3.7 something, but also definitely with 3.13. More input on what we should support welcome. If we leave 3.7, we must update the Dockerfile as well, which currently runs an old 3.7 alpine. 🙄

How to prepare for test

  • Ssh to relevant server (depending on type of change)
  • Use stage: us
  • Paxa the environment: paxa
  • Install on stage (example for Hasta):
    bash /home/proj/production/servers/resources/hasta.scilifelab.se/update-tool-stage.sh -e S_[TOOL]-t [TOOL] -b [THIS-BRANCH-NAME] -a

How to test

  • Do ...

Expected test outcome

  • Check that ...
  • Take a screenshot and attach or copy/paste the output.

Review

  • Tests executed by
  • "Merge and deploy" approved by
    Thanks for filling in who performed the code review and the test!

This version is a

  • MAJOR - when you make incompatible API changes
  • MINOR - when you add functionality in a backwards compatible manner
  • PATCH - when you make backwards compatible bug fixes or documentation/instructions

Implementation Plan

  • Document in ...
  • Deploy this branch on ...
  • Inform to ...

@dnil dnil marked this pull request as ready for review December 4, 2024 12:32
@dnil
Copy link
Collaborator Author

dnil commented Dec 4, 2024

Ok, tests pass at least, so time for some feedback! 😁

@dnil dnil requested a review from northwestwitch December 4, 2024 12:33
@northwestwitch
Copy link
Member

If we leave 3.7, we must update the Dockerfile as well, which currently runs an old 3.7 alpine. 🙄

OMG!

@northwestwitch
Copy link
Member

northwestwitch commented Dec 4, 2024

I think that since we are touching the code we should aim to support python >=3.9 only. Doesn't have to be in this PR, but we should update python both in the Dockerfile and in the actions. Is it a lot of refactoring in the code that you are introducing in this PR when we update python?

@northwestwitch
Copy link
Member

We do have an image ready with python 3.11 and miniconda. I could work on one with python 3.12 and miniconda?

@dnil
Copy link
Collaborator Author

dnil commented Dec 4, 2024

Sounds great! I can switch to the 3.11+miniconda here directly. It would ofcourse be possible to build (or brew) outside of conda, but that would be a drop in replacement!

Copy link
Member

@northwestwitch northwestwitch left a comment

Choose a reason for hiding this comment

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

It looks good to me. Great refactoring! 💯

chanjo/__init__.py Show resolved Hide resolved
import pkg_resources
try:
from importlib.metadata import entry_points
except ImportError: # Backport support for importlib metadata on Python 3.7
Copy link
Member

Choose a reason for hiding this comment

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

Now I understand, it's for the Dockerfile!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't hurt much, other than perhaps that we install the compat libs without using them, so I guess we just keep it.

@@ -16,14 +19,20 @@

LOG = logging.getLogger(__name__)

COMMAND_GROUP_KEY = 'chanjo.subcommands.4'
Copy link
Member

Choose a reason for hiding this comment

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

What is this subcommands.4 group? I'm not familiar with this syntax

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As far as I understood it's just a label (

'chanjo.subcommands.4': [
). I just kept it.

chanjo/cli/init.py Show resolved Hide resolved
chanjo/init/demo.py Show resolved Hide resolved
chanjo/init/demo.py Show resolved Hide resolved
chanjo/testutils.py Outdated Show resolved Hide resolved
tests/conftest.py Show resolved Hide resolved
dnil and others added 3 commits December 4, 2024 14:31
Co-authored-by: Chiara Rasi <rasi.chiara@gmail.com>
@dnil
Copy link
Collaborator Author

dnil commented Dec 4, 2024

Deployed to stage:

[daniel.nilsson@hasta:~] [S_chanjo] $ bash /home/proj/production/servers/resources/hasta.scilifelab.se/update-tool-stage.sh -e S_chanjo -t chanjo -b migrate_pkg_resources
Collecting git+https://github.com/Clinical-Genomics/chanjo@migrate_pkg_resources
  Cloning https://github.com/Clinical-Genomics/chanjo (to revision migrate_pkg_resources) to ./tmp/pip-req-build-6e0m3uwv
  Running command git clone -q https://github.com/Clinical-Genomics/chanjo /home/daniel.nilsson/tmp/pip-req-build-6e0m3uwv
  Running command git checkout -b migrate_pkg_resources --track origin/migrate_pkg_resources
  Switched to a new branch 'migrate_pkg_resources'
  Branch migrate_pkg_resources set up to track remote branch migrate_pkg_resources from origin.
  Resolved https://github.com/Clinical-Genomics/chanjo to commit 9f5b2da3772e3a7d32d9a6da159330d6c9fe5f92
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: chanjo
  Building wheel for chanjo (setup.py) ... done
  Created wheel for chanjo: filename=chanjo-4.7.1-py2.py3-none-any.whl size=45449 sha256=a6b202c5d89b35a1707c587ebec111db110acb408248b2d1a311fcf72bff89d7
  Stored in directory: /home/daniel.nilsson/tmp/pip-ephem-wheel-cache-v2582w4z/wheels/78/c4/b6/8b300039f6ac80d9363e289a87c79746b679491f9c46c8fa17
Successfully built chanjo
Installing collected packages: chanjo
  Attempting uninstall: chanjo
    Found existing installation: chanjo 4.7.1
    Uninstalling chanjo-4.7.1:
      Successfully uninstalled chanjo-4.7.1
Successfully installed chanjo-4.7.1
Collecting git+https://github.com/Clinical-Genomics/chanjo@migrate_pkg_resources
  Cloning https://github.com/Clinical-Genomics/chanjo (to revision migrate_pkg_resources) to ./tmp/pip-req-build-zbx6pqy8
  Running command git clone -q https://github.com/Clinical-Genomics/chanjo /home/daniel.nilsson/tmp/pip-req-build-zbx6pqy8
  Running command git checkout -b migrate_pkg_resources --track origin/migrate_pkg_resources
  Switched to a new branch 'migrate_pkg_resources'
  Branch migrate_pkg_resources set up to track remote branch migrate_pkg_resources from origin.
  Resolved https://github.com/Clinical-Genomics/chanjo to commit 9f5b2da3772e3a7d32d9a6da159330d6c9fe5f92
  Preparing metadata (setup.py) ... done
Requirement already satisfied: coloredlogs in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from chanjo==4.7.1) (15.0.1)
Requirement already satisfied: click in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from chanjo==4.7.1) (8.1.7)
Requirement already satisfied: cryptography in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from chanjo==4.7.1) (42.0.8)
Requirement already satisfied: toolz in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from chanjo==4.7.1) (0.12.1)
Requirement already satisfied: pyyaml in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from chanjo==4.7.1) (6.0.1)
Requirement already satisfied: importlib_metadata in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from chanjo==4.7.1) (7.1.0)
Requirement already satisfied: importlib_resources in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from chanjo==4.7.1) (6.4.5)
Requirement already satisfied: pymysql in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from chanjo==4.7.1) (1.1.1)
Requirement already satisfied: sqlalchemy>=2.0 in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from chanjo==4.7.1) (2.0.30)
Requirement already satisfied: sqlservice>=3.0 in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from chanjo==4.7.1) (3.0.0)
Requirement already satisfied: typing-extensions>=4.6.0 in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from sqlalchemy>=2.0->chanjo==4.7.1) (4.11.0)
Requirement already satisfied: greenlet!=0.4.17 in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from sqlalchemy>=2.0->chanjo==4.7.1) (3.0.3)
Requirement already satisfied: humanfriendly>=9.1 in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from coloredlogs->chanjo==4.7.1) (10.0)
Requirement already satisfied: cffi>=1.12 in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from cryptography->chanjo==4.7.1) (1.16.0)
Requirement already satisfied: zipp>=0.5 in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from importlib_metadata->chanjo==4.7.1) (3.18.2)
Requirement already satisfied: pycparser in /home/proj/stage/bin/miniconda3/envs/S_chanjo/lib/python3.11/site-packages (from cffi>=1.12->cryptography->chanjo==4.7.1) (2.22)
fatal: Not a git repository (or any parent up to mount point /home)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
repository is clean
Logging deploy ...
Getting deployer... done.
Getting last commit message and SHA... done.
Getting version of deploy scripts... /home/daniel.nilsson
done.
Log deploy... done.
chanjo, version 4.7.1

Testing a case:

[daniel.nilsson@hasta:~] [S_base] $ cg upload coverage magicaldog
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
Called undefined __pydantic_serializer__ on HousekeeperAPI, please wrap
Called undefined __dataclass_fields__ on HousekeeperAPI, please wrap
----------------- UPLOAD -----------------
----------------- COVERAGE --------------------
Running command /home/proj/stage/bin/miniconda3/envs/S_chanjo/bin/chanjo --config /home/proj/stage/servers/config/hasta.scilifelab.se/chanjo-stage.yaml db samples -s ACC8033A7
Sample already loaded, deleting previous entry and re-uploading: ACC8033A7
Running command /home/proj/stage/bin/miniconda3/envs/S_chanjo/bin/chanjo --config /home/proj/stage/servers/config/hasta.scilifelab.se/chanjo-stage.yaml db remove ACC8033A7
Running command /home/proj/stage/bin/miniconda3/envs/S_chanjo/bin/chanjo --config /home/proj/stage/servers/config/hasta.scilifelab.se/chanjo-stage.yaml load --sample ACC8033A7 --name 21166-I-1A --group magicaldog --group-name 21166-trio --threshold 10 /home/proj/stage/housekeeper-bundles/magicaldog/2024-02-02/ACC8033A7_lanes_1234_sorted_md_coverage.bed
Running command /home/proj/stage/bin/miniconda3/envs/S_chanjo/bin/chanjo --config /home/proj/stage/servers/config/hasta.scilifelab.se/chanjo-stage.yaml db samples -s ACC13777A2
Sample already loaded, deleting previous entry and re-uploading: ACC13777A2
Running command /home/proj/stage/bin/miniconda3/envs/S_chanjo/bin/chanjo --config /home/proj/stage/servers/config/hasta.scilifelab.se/chanjo-stage.yaml db remove ACC13777A2
Running command /home/proj/stage/bin/miniconda3/envs/S_chanjo/bin/chanjo --config /home/proj/stage/servers/config/hasta.scilifelab.se/chanjo-stage.yaml load --sample ACC13777A2 --name 21166-II-1U --group magicaldog --group-name 21166-trio --threshold 10 /home/proj/stage/housekeeper-bundles/magicaldog/2024-02-02/ACC13777A2_lanes_12345678_sorted_md_coverage.bed
Running command /home/proj/stage/bin/miniconda3/envs/S_chanjo/bin/chanjo --config /home/proj/stage/servers/config/hasta.scilifelab.se/chanjo-stage.yaml db samples -s ACC13777A3
Sample already loaded, deleting previous entry and re-uploading: ACC13777A3
Running command /home/proj/stage/bin/miniconda3/envs/S_chanjo/bin/chanjo --config /home/proj/stage/servers/config/hasta.scilifelab.se/chanjo-stage.yaml db remove ACC13777A3
Running command /home/proj/stage/bin/miniconda3/envs/S_chanjo/bin/chanjo --config /home/proj/stage/servers/config/hasta.scilifelab.se/chanjo-stage.yaml load --sample ACC13777A3 --name 21166-II-2U --group magicaldog --group-name 21166-trio --threshold 10 /home/proj/stage/housekeeper-bundles/magicaldog/2024-02-02/ACC13777A3_lanes_12345678_sorted_md_coverage.bed

Screenshot 2024-12-04 at 17 10 58

@dnil dnil merged commit cb7e319 into main Dec 4, 2024
1 check passed
@dnil dnil deleted the migrate_pkg_resources branch December 4, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants