Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change to .fednignore
Browse files Browse the repository at this point in the history
Wrede committed Jan 29, 2025

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 0d19dff commit 3a7305d
Showing 11 changed files with 14 additions and 10 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 12 additions & 8 deletions fedn/cli/package_cmd.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import logging
import os
import tarfile
import click
import logging

from fedn.common.log_config import logger
import click

from fedn.cli.main import main
from fedn.cli.shared import CONTROLLER_DEFAULTS, get_response, print_response
from fedn.common.log_config import logger


def create_tar_with_ignore(path, name):
try:
ignore_patterns = []
ignore_file = os.path.join(path, ".ignore")
ignore_file = os.path.join(path, ".fednignore")
if os.path.exists(ignore_file):
# Read ignore patterns from .ignore file
with open(ignore_file, 'r') as f:
ignore_patterns = [line.strip() for line in f if line.strip() and not line.startswith('#')]
# Read ignore patterns from .fednignore file
with open(ignore_file, "r") as f:
ignore_patterns = [line.strip() for line in f if line.strip() and not line.startswith("#")]

def is_ignored(file_path):
for pattern in ignore_patterns:
@@ -29,7 +30,7 @@ def is_ignored(file_path):
for file in files:
file_path = os.path.join(root, file)
if not is_ignored(file_path):
logger.info(f"Adding file to tar archive: {file_path}")
logger.debug(f"Adding file to tar archive: {file_path}")
tar.add(file_path, arcname=os.path.relpath(file_path, path))
for dir in dirs:
dir_path = os.path.join(root, dir)
@@ -44,12 +45,14 @@ def is_ignored(file_path):
except Exception as e:
logger.error(f"An error occurred: {e}")


@main.group("package")
@click.pass_context
def package_cmd(ctx):
""":param ctx:"""
pass


@package_cmd.command("create")
@click.option("-p", "--path", required=True, help="Path to package directory containing fedn.yaml")
@click.option("-n", "--name", required=False, default="package.tgz", help="Name of package tarball")
@@ -75,6 +78,7 @@ def create_cmd(ctx, path, name):
logger.error(f"An error occurred: {e}")
exit(-1)


@click.option("-p", "--protocol", required=False, default=CONTROLLER_DEFAULTS["protocol"], help="Communication protocol of controller (api)")
@click.option("-H", "--host", required=False, default=CONTROLLER_DEFAULTS["host"], help="Hostname of controller (api)")
@click.option("-P", "--port", required=False, default=CONTROLLER_DEFAULTS["port"], help="Port of controller (api)")
4 changes: 2 additions & 2 deletions fedn/cli/tests/tests.py
Original file line number Diff line number Diff line change
@@ -306,7 +306,7 @@ class TestPackageCmd(unittest.TestCase):
def setUp(self):
self.runner = CliRunner()
self.test_dir = "test_dir"
self.ignore_file = os.path.join(self.test_dir, ".ignore")
self.ignore_file = os.path.join(self.test_dir, ".fednignore")
self.test_dir = os.path.abspath(self.test_dir)
os.makedirs(self.test_dir, exist_ok=True)

@@ -321,7 +321,7 @@ def setUp(self):
with open(os.path.join(self.test_dir, "ignore_folder", "file_in_folder.txt"), "w") as f:
f.write("This file should also be ignored.")

# Create .ignore file
# Create .fednignore file
with open(self.ignore_file, "w") as f:
f.write("ignore_me.txt\nignore_folder/")

0 comments on commit 3a7305d

Please sign in to comment.