Skip to content

Commit

Permalink
Merge branch 'dev' into renovate/peter-evans-create-or-update-comment…
Browse files Browse the repository at this point in the history
…-4.x
  • Loading branch information
mirpedrol authored Jan 29, 2024
2 parents 8f0ecbd + b6eb508 commit 027c519
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 149 deletions.
1 change: 1 addition & 0 deletions .github/workflows/create-test-lint-wf-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
- TEMPLATE: "template_skip_nf_core_configs.yml"
runner: ubuntu-latest
profile: "docker"
fail-fast: false

steps:
- name: go to working directory
Expand Down
31 changes: 19 additions & 12 deletions .github/workflows/fix-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
types: [created]

jobs:
deploy:
fix-linting:
# Only run if comment is on a PR with the main repo, and if it contains the magic keywords
if: >
contains(github.event.comment.html_url, '/pull/') &&
Expand All @@ -13,7 +13,7 @@ jobs:
runs-on: self-hosted
steps:
# Use the @nf-core-bot token to check out so we can push later
- uses: actions/checkout@v4
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
token: ${{ secrets.nf_core_bot_auth_token }}

Expand All @@ -31,11 +31,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.nf_core_bot_auth_token }}

- name: Set up Python 3.11
uses: actions/setup-python@v5
# Install and run pre-commit
- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
with:
python-version: 3.11
cache: "pip"

- name: Install pre-commit
run: pip install pre-commit
Expand All @@ -47,15 +46,15 @@ jobs:

# indication that the linting has finished
- name: react if linting finished succesfully
if: ${{ steps.pre-commit.outcome }} == 'success'
if: steps.pre-commit.outcome == 'success'
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: green_check_mark
reactions: "+1"

- name: Commit & push changes
id: commit-and-push
if: ${{ steps.pre-commit.outcome }} == 'failure'
if: steps.pre-commit.outcome == 'failure'
run: |
git config user.email "core@nf-co.re"
git config user.name "nf-core-bot"
Expand All @@ -66,17 +65,25 @@ jobs:
git push
- name: react if linting errors were fixed
if: ${{ steps.commit-and-push.outcome }} == 'success'
id: react-if-fixed
if: steps.commit-and-push.outcome == 'success'
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: pencil2
reactions: hooray

- name: react if linting errors were not fixed
if: ${{ steps.commit-and-push.outcome }} == 'failure'
if: steps.commit-and-push.outcome == 'failure'
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: x
reactions: confused

- name: react if linting errors were not fixed
if: steps.commit-and-push.outcome == 'failure'
uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3
with:
issue-number: ${{ github.event.issue.number }}
body: |
@${{ github.actor }} I tried to fix the linting errors, but it didn't work. Please fix them manually.
See [CI log](https://github.com/nf-core/tools/actions/runs/${{ github.run_id }}) for more details.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
rev: v0.1.14
hooks:
- id: ruff # linter
args: [--fix, --exit-non-zero-on-fix] # sort imports and fix
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
- switch to new image syntax in readme ([#2645](https://github.com/nf-core/tools/pull/2645))
- Add conda channel order to nextflow.config ([#2094](https://github.com/nf-core/tools/pull/2094))
- Fix tyop in pipeline nextflow.config ([#2664](https://github.com/nf-core/tools/pull/2664))
- add function to check `-profile` is well formatted ([#2678](https://github.com/nf-core/tools/pull/2678))
- Remove `nfcore_external_java_deps.jar` from lib directory in pipeline template ([#2675](https://github.com/nf-core/tools/pull/2675))
- Add function to check `-profile` is well formatted ([#2678](https://github.com/nf-core/tools/pull/2678))
- Add new pipeline error message pointing to docs when 'requirement exceeds available memory' error message ([#2680](https://github.com/nf-core/tools/pull/2680))
- add 👀👍🏻🎉😕 reactions to fix-linting-bot action ([#2692](https://github.com/nf-core/tools/pull/2692))

### Download

Expand All @@ -19,6 +22,7 @@
- Fix linting of a pipeline with patched custom module ([#2669](https://github.com/nf-core/tools/pull/2669))
- linting a pipeline also lints the installed subworkflows ([#2677](https://github.com/nf-core/tools/pull/2677))
- environment.yml name must be lowercase ([#2676](https://github.com/nf-core/tools/pull/2676))
- lint `nextflow.config` default values match the ones specified in `nextflow_schema.json` ([#2684](https://github.com/nf-core/tools/pull/2684))

### Modules

Expand All @@ -39,7 +43,10 @@
- Update pre-commit hook astral-sh/ruff-pre-commit to v0.1.13 ([#2660](https://github.com/nf-core/tools/pull/2660))
- Add new subcommand: `nf-core logo-create` to output an nf-core logo for a pipeline (instead of going through the website) ([#2662](https://github.com/nf-core/tools/pull/2662))
- Update actions/cache action to v4 ([#2666](https://github.com/nf-core/tools/pull/2666))
- Handle api redirects from the old site ([#2672](https://github.com/nf-core/tools/pull/2672))
- Remove redundanct v in pipeline version for emails ([#2667](https://github.com/nf-core/tools/pull/2667))
- add function to check `-profile` is well formatted ([#2678](https://github.com/nf-core/tools/pull/2678))
- Update pre-commit hook astral-sh/ruff-pre-commit to v0.1.14 ([#2674](https://github.com/nf-core/tools/pull/2674))
- Update peter-evans/create-or-update-comment action to v4 ([#2683](https://github.com/nf-core/tools/pull/2683))

# [v2.11.1 - Magnesium Dragon Patch](https://github.com/nf-core/tools/releases/tag/2.11) - [2023-12-20]
Expand Down
26 changes: 22 additions & 4 deletions nf_core/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,12 @@ def fix_linting(self):
def make_pipeline_logo(self):
"""Fetch a logo for the new pipeline from the nf-core website"""
email_logo_path = Path(self.outdir) / "assets"
create_logo(text=self.template_params["short_name"], dir=email_logo_path, theme="light")
create_logo(text=self.template_params["short_name"], dir=email_logo_path, theme="light", force=self.force)
for theme in ["dark", "light"]:
readme_logo_path = Path(self.outdir) / "docs" / "images"
create_logo(text=self.template_params["short_name"], dir=readme_logo_path, width=600, theme=theme)
create_logo(
text=self.template_params["short_name"], dir=readme_logo_path, width=600, theme=theme, force=self.force
)

def git_init_pipeline(self):
"""Initialises the new pipeline as a Git repository and submits first commit.
Expand Down Expand Up @@ -537,8 +539,24 @@ def git_init_pipeline(self):
repo.index.commit(f"initial template build from nf-core/tools, version {nf_core.__version__}")
if default_branch:
repo.active_branch.rename(default_branch)
repo.git.branch("TEMPLATE")
repo.git.branch("dev")
try:
repo.git.branch("TEMPLATE")
repo.git.branch("dev")

except git.GitCommandError as e:
if "already exists" in e.stderr:
log.debug("Branches 'TEMPLATE' and 'dev' already exist")
if self.force:
log.debug("Force option set - deleting branches")
repo.git.branch("-D", "TEMPLATE")
repo.git.branch("-D", "dev")
repo.git.branch("TEMPLATE")
repo.git.branch("dev")
else:
log.error(
"Branches 'TEMPLATE' and 'dev' already exist. Use --force to overwrite existing branches."
)
sys.exit(1)
log.info(
"Done. Remember to add a remote and push to GitHub:\n"
f"[white on grey23] cd {self.outdir} \n"
Expand Down
78 changes: 45 additions & 33 deletions nf_core/create_logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PIL import Image, ImageDraw, ImageFont

import nf_core
from nf_core.utils import NFCORE_CACHE_DIR

log = logging.getLogger(__name__)

Expand All @@ -26,7 +27,6 @@ def create_logo(
if not dir.is_dir():
log.debug(f"Creating directory {dir}")
dir.mkdir(parents=True, exist_ok=True)

assets = Path(nf_core.__file__).parent / "assets/logo"

if format == "svg":
Expand All @@ -51,44 +51,56 @@ def create_logo(
else:
logo_filename = f"nf-core-{text}_logo_{theme}.png" if not filename else filename
logo_filename = f"{logo_filename}.png" if not logo_filename.lower().endswith(".png") else logo_filename
cache_name = f"nf-core-{text}_logo_{theme}_{width}.png"
logo_path = Path(dir, logo_filename)

# Check if we haven't already created this logo
if logo_path.is_file() and not force:
log.info(f"Logo already exists at: {logo_path}. Use `--force` to overwrite.")
return logo_path

log.debug(f"Creating logo for {text}")

# make sure the figure fits the text
font_path = assets / "MavenPro-Bold.ttf"
log.debug(f"Using font: {str(font_path)}")
font = ImageFont.truetype(str(font_path), 400)
text_length = font.getmask(text).getbbox()[2] # get the width of the text based on the font

max_width = max(
2300, text_length + len(text) * 20
) # need to add some more space to the text length to make sure it fits

template_fn = "nf-core-repo-logo-base-lightbg.png"
if theme == "dark":
template_fn = "nf-core-repo-logo-base-darkbg.png"

template_path = assets / template_fn
img = Image.open(str(template_path))
# get the height of the template image
height = img.size[1]

# Draw text
draw = ImageDraw.Draw(img)
color = theme == "dark" and (250, 250, 250) or (5, 5, 5)
draw.text((110, 465), text, color, font=font)

# Crop to max width
img = img.crop((0, 0, max_width, height))

# Resize
img = img.resize((width, int((width / max_width) * height)))
# cache file
cache_path = Path(NFCORE_CACHE_DIR, "logo", cache_name)
img = None
if cache_path.is_file():
log.debug(f"Logo already exists in cache at: {cache_path}. Reusing this file.")
img = Image.open(str(cache_path))
if not img:
log.debug(f"Creating logo for {text}")

# make sure the figure fits the text
font_path = assets / "MavenPro-Bold.ttf"
log.debug(f"Using font: {str(font_path)}")
font = ImageFont.truetype(str(font_path), 400)
text_length = font.getmask(text).getbbox()[2] # get the width of the text based on the font

max_width = max(
2300, text_length + len(text) * 20
) # need to add some more space to the text length to make sure it fits

template_fn = "nf-core-repo-logo-base-lightbg.png"
if theme == "dark":
template_fn = "nf-core-repo-logo-base-darkbg.png"

template_path = assets / template_fn
img = Image.open(str(template_path))
# get the height of the template image
height = img.size[1]

# Draw text
draw = ImageDraw.Draw(img)
color = theme == "dark" and (250, 250, 250) or (5, 5, 5)
draw.text((110, 465), text, color, font=font)

# Crop to max width
img = img.crop((0, 0, max_width, height))

# Resize
img = img.resize((width, int((width / max_width) * height)))

# Save to cache
Path(cache_path.parent).mkdir(parents=True, exist_ok=True)
log.debug(f"Saving logo to cache: {cache_path}")
img.save(cache_path, "PNG")
# Save
img.save(logo_path, "PNG")

Expand Down
4 changes: 3 additions & 1 deletion nf_core/lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ def run_linting(
if subworkflow_lint_obj is not None:
subworkflow_lint_obj.filter_tests_by_key(subworkflow_lint_tests)

# Set up files for modules linting test
# Set up files for component linting test
module_lint_obj.set_up_pipeline_files()
if subworkflow_lint_obj is not None:
subworkflow_lint_obj.set_up_pipeline_files()

# Run the pipeline linting tests
try:
Expand Down
Loading

0 comments on commit 027c519

Please sign in to comment.