def project_with_scm(tmp_path): project = FIXTURES / "projects/demo-using-scm" shutil.copytree(project, tmp_path / project.name) with utils.cd(tmp_path / project.name): subprocess.check_call(["git", "init"]) subprocess.check_call(["git", "add", "."]) subprocess.check_call(["git", "commit", "-m", "initial commit"]) subprocess.check_call( ["git", "tag", "-a", "0.1.0", "-m", "version 0.1.0"]) yield tmp_path / project.name
def test_auto_include_tests_for_sdist(): builder = Builder(FIXTURES / "projects/demo-package-with-tests") with utils.cd(builder.location): sdist_files = builder.find_files_to_add(True) wheel_files = builder.find_files_to_add(False) sdist_only_files = ("tests/__init__.py", "LICENSE", "pyproject.toml") include_files = ("my_package/__init__.py", ) for file in include_files: path = Path(file) assert path in sdist_files assert path in wheel_files for file in sdist_only_files: path = Path(file) assert path in sdist_files assert path not in wheel_files
def test_recursive_glob_patterns_in_includes(): builder = Builder(FIXTURES / "projects/demo-package-with-deep-path") with utils.cd(builder.location): sdist_files = builder.find_files_to_add(True) wheel_files = builder.find_files_to_add(False) data_files = ( "my_package/data/data_a.json", "my_package/data/data_inner/data_b.json", ) assert Path("my_package/__init__.py") in sdist_files assert Path("my_package/__init__.py") in wheel_files for file in data_files: path = Path(file) assert path in sdist_files assert path not in wheel_files
def build_fixture_project(project_name): project = FIXTURES / "projects" / project_name with utils.cd(project): yield project
def convert_package_paths(self) -> Dict[str, Union[List, Dict]]: """Return a {package_dir, packages, package_data, exclude_package_data} dict.""" packages = [] py_modules = [] package_data = {"": ["*"]} exclude_package_data = {} with cd(self.filepath.parent.as_posix()): src_dir = Path(self.package_dir or ".") if not self.includes: packages = list( find_packages_iter( self.package_dir or ".", exclude=["tests", "tests.*"], src=src_dir, )) if not packages: py_modules = [ path.name[:-3] for path in src_dir.glob("*.py") ] else: packages_set = set() includes = self.includes for include in includes[:]: if include.replace("\\", "/").endswith("/*"): include = include[:-2] if "*" not in include and os.path.isdir(include): dir_name = include.rstrip("/\\") temp = list( find_packages_iter(dir_name, src=self.package_dir or ".")) if os.path.isfile(os.path.join(dir_name, "__init__.py")): temp.insert(0, dir_name) packages_set.update(temp) includes.remove(include) packages[:] = list(packages_set) for include in includes: for path in glob.glob(include, recursive=True): if "/" not in path.lstrip("./") and path.endswith( ".py"): # Only include top level py modules py_modules.append(path.lstrip("./")[:-3]) if include.endswith(".py"): continue for package in packages: relpath = os.path.relpath(include, package) if not relpath.startswith(".."): package_data.setdefault(package, []).append(relpath) for exclude in self.excludes or []: for package in packages: relpath = os.path.relpath(exclude, package) if not relpath.startswith(".."): exclude_package_data.setdefault(package, []).append(relpath) if packages and py_modules: raise ProjectError( "Can't specify packages and py_modules at the same time.") return { "package_dir": { "": self.package_dir } if self.package_dir else {}, "packages": packages, "py_modules": py_modules, "package_data": package_data, "exclude_package_data": exclude_package_data, }
def build_fixture_project(project_name: str) -> Iterator[Path]: project = FIXTURES / "projects" / project_name with utils.cd(project): yield project