![]() The file test1 is being copied to the launch directory of fw2 and renamed as hello. The files_in of fw2 contains fwtest1, which means that Is available in _files_out under the name fwtest1. In the above example, fw1 generates a file called test1, which That intersects with files_out of the parent, these files are automatically copied over and renamed, with gzip,īzip2 compression being handled transparently. Note that FireWorks will search within subpackages automatically, so you can just put a root package (but loading will be slightly slower).Ĭlass FibonacciAdderTask ( FiretaskBase ): _fw_name = "Fibonacci Adder Task" def run_task ( self, fw_spec ): smaller = fw_spec larger = fw_spec stop_point = fw_spec m_sum = smaller + larger if m_sum < stop_point : print ( f "The next Fibonacci number is. However, you need to modify the USER_PACKAGES variable of the FW config to include the package for where to find the Firetask, e.g. (or) put the Firetask wherever you’d like. (or) if you have access to the FireWorks source directory, put your Firetask definition anywhere in er_objects or it subdirectories - it will be automatically be found there. No further registration is needed if you use this option. Use the decorator to define your FW name (see the Appendix). ![]() There are a couple of options for registering your Firetask (you only need to do one of the below): Second, you must register your Firetask so that it can be found by the FireWorks software. If you are unfamiliar with this topic, some more details about this process can be found here, or try Googling “how does Python find modules?” You can see the locations where Python looks for code by typing import sys followed by print(sys.path). This step usually means either installing the code into your site-packages directory (where many Python tools install code) or modifying your PYTHONPATH environment variable to include the location of the Firetask. If Python cannot import your code (e.g., from the shell), neither can FireWorks. is within Python’s search path and that you can import your Firetask in a Python shell. When FireWorks bootstraps your Firetask from a database definition, it needs to know where to look for Firetasks.įirst, you need to make sure your Firetask is defined in a file location that can be found by Python, i.e. Remember you can access dict keys of “fw_spec” as well as dict keys of “self” Keep the run_task method header intact, but change the definition to your custom operation. In this case, it’s tarring and gzipping some files according to the parameters the dictionary of itself, and ignoring anything in the fw_spec. ![]() It has two sources of information: the keys in fw_spec and a dictionary of self (which includes parameters like base_name used to construct the object). The meat of the Firetask is the run_task(self, fw_spec) method.Because optional_params is also set in this example, the Firetask will perform an additional safety check: it will throw an error if the user attempts to initialize ArchiveTask with any keyword arguments other than those listed in either required_params or optional_params.Īdd your required and optional parameters as desired. Because base_name is in required_params, it must be specified by the user or the FireTask will throw an error. In the example above, an ArchiveTask could be instantiated using something like my_task = ArchiveTask(base_name="my_filename", format="bztar"). As a developer, you can choose whether to add these variables or not - if you do set them, they help with safety and also documentation, thus they are recommended. The required_params and optional_params relate to how the Firetask is constructed.See the Appendix section for working around this and an alternate formulations for identifying the Firetask.Ĭhange the ``fw_name`` value to a desired identifier for your Firetask, e.g. It must be a unique name that is always retained. The _fw_name is how this Firetask is identified.This abstract class does some work under the covers and also requires that you define a run_task(self, fw_spec) method. The class extends the FiretaskBase abstract class.In the first line, the name of the class ( ArchiveDirTask) can be anything - it does not affect the operation of the code if you follow the structure above.Ĭhange the class name to anything you desire.You can copy this code to a new place and make the following modifications in order to write your Firetask: ![]() """ _fw_name = 'ArchiveDirTask' required_params = optional_params = def run_task ( self, fw_spec ): shutil. Args: base_name (str): Name of the file to create. Class ArchiveDirTask ( FiretaskBase ): """ Wrapper around shutil.make_archive to make tar archives.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |