Skip to content

Commit

Permalink
Merge pull request #8 from NarrativeScience/QPT-29657-updates-for-new…
Browse files Browse the repository at this point in the history
…-deploy

QPT-29657-tweaking pypants for new py2sfn deploy
  • Loading branch information
ns-mkhalid authored May 12, 2020
2 parents d574a69 + ab1c34c commit 5182935
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/pypants/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""CLI for working with Python packages and BUILD files in a Pants monorepo"""

__version__ = "0.4.0"
__version__ = "0.5.0"
2 changes: 1 addition & 1 deletion src/pypants/build_targets/py2sfn_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def set_dependencies(self, targets: Dict[str, BuildTarget]) -> None:
"""
logger.debug(f"Gathering dependencies for {self.key}")
for task_package_path in Path(self.package_path).glob("tasks/*/src/*"):
for task_package_path in Path(self.build_dir).glob("tasks/*/src/*"):
package_name = task_package_path.name
if package_name in targets:
self.dependencies.add(targets[package_name])
Expand Down
19 changes: 13 additions & 6 deletions src/pypants/process_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from multiprocessing import Pool
import os
from pathlib import Path
from typing import Dict, List, Tuple
import re
from typing import Dict, List, Optional, Tuple

import networkx as nx

Expand Down Expand Up @@ -101,17 +102,23 @@ def _gather_dependencies(self) -> None:
for package_name in package_names:
target.add_dependency(self._targets, package_name)

def generate_build_files(self) -> None:
def generate_build_files(self, target_pattern: Optional[str] = None) -> None:
"""Generate BUILD files.
You must have already called :py:meth:`.register_packages`.
Args:
target_pattern: If provided, BUILD files are only generated for targets with
keys matching the pattern
"""
logger.info("Generating BUILD files")
trees_to_write = []
for target in self._targets.values():
tree = target.generate_build_file()
if tree is not None:
trees_to_write.append((tree, target.build_file))
for key, target in self._targets.items():
if not target_pattern or re.search(target_pattern, key):
tree = target.generate_build_file()
if tree is not None:
trees_to_write.append((tree, target.build_file))

# Create a pool of workers that will render, format, and write each AST module
# tree to disk.
Expand Down

0 comments on commit 5182935

Please sign in to comment.