Skip to content

Commit

Permalink
Correct source file paths for projects with src/ layout and those usi…
Browse files Browse the repository at this point in the history
…ng namespace packages,
  • Loading branch information
domdfcoding committed Nov 5, 2020
1 parent dcef350 commit ba0de49
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
31 changes: 20 additions & 11 deletions repo_helper/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,26 @@ def copy_source(self) -> None:
Copy source files into the build directory.
"""

pkgdir = self.repo_dir / self.import_name

for py_pattern in {"**/*.py", "**/*.pyi", "**/*.pyx", "**/py.typed"}:
for py_file in pkgdir.rglob(py_pattern):
if "__pycache__" in py_file.parts:
continue

target = self.build_dir / py_file.relative_to(self.repo_dir)
target.parent.maybe_make(parents=True)
target.write_clean(py_file.read_text())
self.report_copied(py_file, target)
source_files = []

if self.config["py_modules"]:
source_files.extend(self.config["py_modules"])
else:
if self.config["stubs_package"]:
pkgdir = self.repo_dir / self.config["source_dir"] / f"{self.config['import_name'].replace('.', '/')}-stubs"
else:
pkgdir = self.repo_dir / self.config["source_dir"] / self.config["import_name"].replace(".", "/")

for py_pattern in {"**/*.py", "**/*.pyi", "**/*.pyx", "**/py.typed"}:
for py_file in pkgdir.rglob(py_pattern):
if "__pycache__" not in py_file.parts:
source_files.append(py_file)

for py_file in source_files:
target = self.build_dir / py_file.relative_to(self.repo_dir)
target.parent.maybe_make(parents=True)
target.write_clean(py_file.read_text())
self.report_copied(py_file, target)

def report_copied(self, source: pathlib.Path, target: pathlib.Path):
"""
Expand Down
8 changes: 4 additions & 4 deletions repo_helper/files/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# stdlib
import os.path
import pathlib
import posixpath
import re
from typing import Any, List

Expand Down Expand Up @@ -103,17 +104,16 @@ def get_source_files(self) -> List[str]:
source_files = []

if self._globals["py_modules"]:
source_files += self._globals["source_dir"]

for file in self._globals["py_modules"]:
source_files.append(f"{file}.py")
source_files.append(posixpath.join(self._globals["source_dir"], f"{file}.py"))

elif self._globals["stubs_package"]:
directory = f"{self._globals['source_dir']}{self._globals['import_name'].replace('.', '/')}-stubs"
directory = posixpath.join(self._globals["source_dir"], f"{self._globals['import_name'].replace('.', '/')}-stubs")
source_files.append(directory)

else:
directory = f"{self._globals['source_dir']}{self._globals['import_name'].replace('.', '/')}"
directory = posixpath.join(self._globals["source_dir"], self._globals["import_name"].replace(".", "/"))
source_files.append(directory)

if self._globals["enable_tests"]:
Expand Down

0 comments on commit ba0de49

Please sign in to comment.