average-australia-85137
07/21/2021, 4:04 PMGet
and then exiting)
@rule(level=LogLevel.DEBUG)
async def package_into_image(
field_set: DockerPackageFieldSet,
union_membership: UnionMembership,
) -> BuiltPackage:
target_name = field_set.address.target_name
transitive_targets = await Get(
TransitiveTargets, TransitiveTargetsRequest([field_set.address])
)
for t in transitive_targets.dependencies:
if type(t) is RelocatedFiles:
s = await Get(
SourceFiles,
SourceFilesRequest,
SourceFilesRequest(
sources_fields=[t.get(Sources)],
for_sources_types=[RelocatedFilesSources],
)
)
<http://logger.info|logger.info>('relocated files: %s', s.snapshot.files)
return BuiltPackage(
digest=s.snapshot.digest,
artifacts=([BuiltPackageArtifact(f, ()) for f in s.snapshot.files]),
)
has output:
[nate@ragin-cajun pants-docker]$ ./pants package test_docker:dockerized_flask_app
12:04:18.11 [INFO] relocated files: ()
fast-nail-55400
07/21/2021, 4:19 PMclass RelocateFilesViaCodegenRequest(GenerateSourcesRequest):
input = RelocatedFilesSources
output = FilesSources
@rule(desc="Relocating loose files for `relocated_files` targets", level=LogLevel.DEBUG)
async def relocate_files(request: RelocateFilesViaCodegenRequest) -> GeneratedSources:
fast-nail-55400
07/21/2021, 4:19 PMfast-nail-55400
07/21/2021, 4:19 PMenable_codegen=True
on your SourceFilesRequest
fast-nail-55400
07/21/2021, 4:21 PMfast-nail-55400
07/21/2021, 4:22 PMtype(t) is RelocatedFiles
, I believe the preferred solution is to check the target for specific fields. So `t.has_field(RelocatedFilesSources)`is probably preferred.fast-nail-55400
07/21/2021, 4:22 PMfor_sources_types=[RelocatedFilesSources],
average-australia-85137
07/21/2021, 4:26 PMenable_codegen=True
did not change the output (and the is
check is just there to illustrate what i'm trying to do, i'm not using it in my actual plugin)average-australia-85137
07/21/2021, 4:27 PMfiles(name="files",
sources=["static/style.css"])
relocated_files(name="relocated",
files_targets=[":files"],
src="static/",
dest="style/")
python_library(
name="test_docker",
dependencies=[":files",
":resources",
":relocated",]
)
# this doesn't matter I think none of this is being used before the function exits, we just look up the relocated files target and attempt to get the new sources
docker(
name="dockerized_flask_app",
image_setup_commands = ["apt-get update && apt-get upgrade --yes",
"apt-get -y install gcc libpq-dev"],
base_image="python:3.8.8-slim-buster",
tags=["version1", "version2"],
#command=["/.virtual_env/bin/python", "-m", "gunicorn", "<http://test_docker.app:app|test_docker.app:app>"],
command=["/.virtual_env/bin/gunicorn", "--bind=127.0.0.1:8000", "<http://test_docker.app:app|test_docker.app:app>"],
workdir="root",
dependencies=["test_docker", "//:gunicorn", "//:gevent",],
)
average-australia-85137
07/21/2021, 4:29 PMs = await Get(
SourceFiles,
SourceFilesRequest,
SourceFilesRequest(
sources_fields=[t.get(Sources)],
for_sources_types=[RelocatedFilesSources],
enable_codegen=True
)
)
I still get
[nate@ragin-cajun pants-docker]$ ./pants package test_docker:dockerized_flask_app
12:28:12.95 [INFO] Initializing scheduler...
12:28:13.11 [INFO] Scheduler initialized.
12:28:13.99 [INFO] relocated files: ()
fast-nail-55400
07/21/2021, 4:31 PMfor_sources_types=[FilesSources]
fast-nail-55400
07/21/2021, 4:31 PMRelocatedFilesSources
-> FilesSources
fast-nail-55400
07/21/2021, 4:32 PMHydrateSourcesRequest
state:
“”"Convert raw sources globs into an instance of HydratedSources.
If you only want to handle certain Sources fields, such as only PythonSources, set
. Any invalid sources will return afor_sources_types
instance with anHydratedSources
empty snapshot and.sources_type = None
Ifis set toenable_codegen
, any codegen sources will try to be converted to oneTrue
of the.for_sources_types
fast-nail-55400
07/21/2021, 4:33 PMaverage-australia-85137
07/21/2021, 4:33 PMfast-nail-55400
07/21/2021, 4:34 PMaverage-australia-85137
07/21/2021, 4:34 PMwitty-crayon-22786
07/21/2021, 4:44 PMaverage-australia-85137
07/21/2021, 4:57 PMcurved-television-6568
07/21/2021, 6:12 PM