Skip to content

Commit

Permalink
Merge pull request #2 from awslabs/feature/move-templates
Browse files Browse the repository at this point in the history
Exclude __pycache__ when using init
  • Loading branch information
dacort authored Mar 14, 2023
2 parents a7d4e9f + c212948 commit 7c2f20c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python = "^3.9"
click = "^7.1.2"
boto3 = "^1.26.6"
pytest-cov = "^4.0.0"
pyyaml = "^6.0"

[tool.poetry.group.dev.dependencies]
pytest = "7.2.2"
Expand Down
14 changes: 4 additions & 10 deletions src/emr_cli/packaging/python_project.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
import shutil
import subprocess
import sys
from pathlib import Path
from shutil import copy

import boto3

from emr_cli.deployments.emr_serverless import DeploymentPackage
from emr_cli.utils import console_log, parse_bucket_uri
from emr_cli.utils import console_log, copy_template, parse_bucket_uri


class PythonProject(DeploymentPackage):
Expand All @@ -19,7 +19,7 @@ def initialize(self, target_dir: str = os.getcwd()):
- Creates a Dockerfile
"""
console_log(f"Initializing project in {target_dir}")
self._copy_template(target_dir)
copy_template("pyspark", target_dir)
console_log("Project initialized.")

def copy_single_file(self, relative_file_path: str, target_dir: str = os.getcwd()):
Expand All @@ -30,13 +30,7 @@ def copy_single_file(self, relative_file_path: str, target_dir: str = os.getcwd(
Path(__file__).parent.parent / "templates" / "pyspark" / relative_file_path
)
target_path = Path(target_dir)
shutil.copy(template_path, target_path)

def _copy_template(self, target_dir: str):
source = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "templates", "pyspark")
)
shutil.copytree(source, target_dir, dirs_exist_ok=True)
copy(template_path, target_path)

def build(self):
"""
Expand Down
12 changes: 8 additions & 4 deletions src/emr_cli/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
from pathlib import Path
from shutil import copytree, ignore_patterns
from typing import List
from urllib.parse import urlparse

Expand Down Expand Up @@ -31,7 +32,10 @@ def mkdir(path: str):


def copy_template(source: str, target_dir: str):
source = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "templates", source)
"""
Copies the entire `source` directory to `target_dir`.
"""
source = os.path.abspath(Path(__file__).parent.parent / "templates" / source)
copytree(
source, target_dir, dirs_exist_ok=True, ignore=ignore_patterns("__pycache__")
)
shutil.copytree(source, target_dir, dirs_exist_ok=True)
21 changes: 21 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from emr_cli.packaging.python_poetry_project import PythonPoetryProject
from emr_cli.packaging.python_project import PythonProject


class TestInit:
def test_default_init(self, tmp_path):
p = PythonProject()

p.initialize(tmp_path)
assert (tmp_path / "pyproject.toml").exists()
assert (tmp_path / "entrypoint.py").exists()
assert (tmp_path / "jobs" / "extreme_weather.py").exists()
assert not (tmp_path / "README.md").exists()

def test_poetry_init(self, tmp_path):
p = PythonPoetryProject()

p.initialize(tmp_path)
assert (tmp_path / "entrypoint.py").exists()
assert (tmp_path / "pyproject.toml").exists()
assert (tmp_path / "README.md").exists()

0 comments on commit 7c2f20c

Please sign in to comment.