ambitious-actor-36781
03/28/2022, 4:23 AMdeploy this to 'the cloud' using a binary blob
5. Run a subset of tests against this code in 'the cloud'
6. also have the ability to deploy this manually.
of cause, hope to leverage the whole Pants 'don't repeat work' feature to skip steps #1 to #4 if the code doesn't change.
I think I've got a grasp on doing the codegen.
But can't picture how to make the deploy the code as a dependency for tests work
And it's been nearly 6 months since I last used Pants.happy-kitchen-89482
03/28/2022, 5:46 AMhappy-kitchen-89482
03/28/2022, 5:46 AMhappy-kitchen-89482
03/28/2022, 5:47 AMhappy-kitchen-89482
03/28/2022, 5:47 AMambitious-actor-36781
03/28/2022, 6:26 AMambitious-actor-36781
03/28/2022, 6:32 AMresource.yaml file that has an ID for the file, and a pointer to the filename, and some other unique-stuff
3. Create a manifest.yaml file that references things inside multiple resource.yaml around the place (how this works I have no idea)
4. Use a provided 3rd party binary-blob that can be run on the command line to upload the code ./thing upload <http://path.to|path.to>.manifest.yaml
Then we want to test the stuff we uploaded using pytest and behaveambitious-actor-36781
03/28/2022, 6:35 AMresource.yaml on disk, modify it as necessary, and then spit out a new one.ambitious-actor-36781
03/28/2022, 7:03 AMGeneratedSourceRequest gives me a Snapshot(... files=(src/python/foo/resource.yaml)...)
just need to read that, and then dump that in a FileContents yeah?ambitious-actor-36781
03/28/2022, 7:28 AMambitious-actor-36781
03/28/2022, 7:38 AMimport yaml
from dataclasses import dataclass
from pants.engine.rules import collect_rules, rule, Get, MultiGet
from pants.engine.unions import UnionRule
from pants.engine.target import GenerateSourcesRequest, GeneratedSources
from pants.engine.fs import FileContent, Snapshot, Digest, DigestContents, CreateDigest
from pants.engine.environment import EnvironmentRequest, Environment
from .target_types import SmartId, SmartContractSrc, RTIMEResourceSrc
@dataclass(frozen=True)
class RTIMEConfigRequest:
pass
@dataclass(frozen=True)
class RTIMEConfig:
resource_prefix: str
class GenerateYamlFromResourceYamlRequest(GenerateSourcesRequest):
input = SmartSrc
output = RTIMEResourceSrc
@rule
async def get_tmv_resource_prefix(request: RTIMEConfigRequest) -> RTIMEConfig:
req = EnvironmentRequest(["RTIME_RESOURCE_PREFIX"])
env = await Get(Environment, EnvironmentRequest, req)
resource_prefix = env.get('RTIME_RESOURCE_PREFIX')
if not resource_prefix:
1/0
return RTIMEConfig(resource_prefix=resource_prefix)
@rule
async def generate_resource_yaml(request: GenerateYamlFromResourceYamlRequest) -> GeneratedSources:
rtime_config, digest_contents = await MultiGet(
Get(RTIMEConfig, RTIMEConfigRequest()),
Get(DigestContents, Digest, request.protocol_sources.digest),
)
src_file = digest_contents[0]
sc_id = request.protocol_target[SmartId]
resource = {
"type": "SMART__VERSION",
"id": f"{rtime_config.resource_prefix}{sc_id.value}",
"payload": src_file.content.decode('ascii')
}
content = FileContent(src_file.path, yaml.dump(resource, indent=2).encode())
digest = await Get(Digest, CreateDigest([content]))
snapshot = await Get(Snapshot, Digest, digest)
return GeneratedSources(snapshot)
def rules():
return [
*collect_rules(),
UnionRule(GenerateSourcesRequest, GenerateYamlFromResourceYamlRequest)
]ambitious-actor-36781
03/28/2022, 9:58 AMGet call in the codebase.ambitious-actor-36781
03/28/2022, 9:59 AMhappy-kitchen-89482
03/28/2022, 4:04 PMhappy-kitchen-89482
03/28/2022, 7:05 PMGet call, and what would have helped find it more easily? We'd like to improve the docs for all this.ambitious-actor-36781
03/28/2022, 11:33 PMDigestContents would give me the file contents. Then working out that request had a Digest tucked away in it to get what I wanted.
Or EnvironmentRequest to get a subset of the environment. Which I only knew about from my previous forays into plugin development.
If it were me, I'd probably consider making custom documentation browser where you can browse the available request/response dataclasses for rules and read what they do (e.g. Environment) and have it output a list of valid uses. e.g. you can get one with an EnvironmentRequest or CompleteEnvironmentRequest and it's used as an argument to a Processhundreds-father-404
03/28/2022, 11:34 PM./pants help DigestContents for example - will show you all the rules that return it etcambitious-actor-36781
03/28/2022, 11:36 PMambitious-actor-36781
03/28/2022, 11:39 PMtest targets that have a dependency on my publish targets do the deploy of the deployable before running the test. Because that seems alien to me.ambitious-actor-36781
03/28/2022, 11:40 PM