diff --git a/.gitignore b/.gitignore index 52570f50e87a880e4bbd3f26d230e1e1495a9c92..2e5bd3eb574ca824219f73ed0db32216fdacb36a 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,38 @@ user_conf.json # pycache __pycache__ + +*~ +*.swp +*.pyc +*.so +bin +eggs +parts +.installed.cfg +.mr.developer.cfg +*.egg-info +develop-eggs +sphinx +doc/api +src +dist +.nfs* +.gdb_history +build +*.egg +opsnr.stt +.coverage +.DS_Store +html/ +record.txt +_ci/ +miniconda.sh +miniconda/ +miniconda.cached/ +conda/recipe_append.yaml +conda-bld/ + +# built JS files +beat/editor/js +prefix/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..97e7ba7b4136b7c30f3b1c7aae9faa52c03d5919 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,171 @@ +# This build file uses template features from YAML so it is generic enough for +# any Bob project. Don't modify it unless you know what you're doing. + +# Definition of global variables (all stages) +variables: + CONDA_ROOT: "${CI_PROJECT_DIR}/miniconda" + + +# Definition of our build pipeline order +stages: + - build + - browser-tests + - deploy + - pypi + + +# Build targets +.build_template: &build_job + stage: build + before_script: + - mkdir _ci + - curl --silent "https://gitlab.idiap.ch/bob/bob.admin/raw/master/gitlab/install.sh" > _ci/install.sh + - chmod 755 _ci/install.sh + - ./_ci/install.sh _ci master #installs ci support scripts + - ./_ci/before_build.sh + script: + - ./_ci/build.sh + after_script: + - ./_ci/after_build.sh + cache: &build_caches + paths: + - miniconda.sh + - ${CONDA_ROOT}/pkgs/*.tar.bz2 + - ${CONDA_ROOT}/pkgs/urls.txt + + +.build_linux_template: &linux_build_job + <<: *build_job + tags: + - docker + image: continuumio/conda-concourse-ci + artifacts: + expire_in: 1 week + paths: + - _ci/ + - ${CONDA_ROOT}/conda-bld/linux-64/*.tar.bz2 + cache: + <<: *build_caches + key: "linux-cache" + + +.build_macosx_template: &macosx_build_job + <<: *build_job + tags: + - macosx + artifacts: + expire_in: 1 week + paths: + - _ci/ + - ${CONDA_ROOT}/conda-bld/osx-64/*.tar.bz2 + cache: + <<: *build_caches + key: "macosx-cache" + + +build_linux_27: + <<: *linux_build_job + variables: + PYTHON_VERSION: "2.7" + + +build_linux_36: + <<: *linux_build_job + variables: + PYTHON_VERSION: "3.6" + BUILD_EGG: "true" + artifacts: + expire_in: 1 week + paths: + - _ci/ + - dist/*.zip + - sphinx + - ${CONDA_ROOT}/conda-bld/linux-64/*.tar.bz2 + + +build_macosx_27: + <<: *macosx_build_job + variables: + PYTHON_VERSION: "2.7" + + +build_macosx_36: + <<: *macosx_build_job + variables: + PYTHON_VERSION: "3.6" + + +# Docker host based testing (must be run inside dind or docker-enabled host) +.browser_test_linux_template: &linux_browser_test_job + stage: browser-tests + image: docker.idiap.ch/beat/beat.env.editor:0.0.1r5 + before_script: + # safe keep artifacts as before_build.sh will erase those... + - mv ${CONDA_ROOT}/conda-bld . + - ./_ci/install.sh _ci master #updates ci support scripts + - ./_ci/before_build.sh + - mv conda-bld ${CONDA_ROOT} + script: + - export BEAT_BROWSER_TESTS=true + - BOB_TEST_ONLY=true ./_ci/build.sh + after_script: + - ./_ci/after_build.sh + + +browser_linux_36: + <<: *linux_browser_test_job + variables: + PYTHON_VERSION: "3.6" + dependencies: + - build_linux_36 + tags: + - docker + + +# Deploy targets +.deploy_template: &deploy_job + stage: deploy + before_script: + - ./_ci/install.sh _ci master #updates ci support scripts + script: + - ./_ci/deploy.sh + dependencies: + - build_linux_27 + - build_linux_36 + - build_macosx_27 + - build_macosx_36 + tags: + - deployer + + +deploy_beta: + <<: *deploy_job + environment: beta + only: + - master + + +deploy_stable: + <<: *deploy_job + environment: stable + only: + - /^v\d+\.\d+\.\d+([abc]\d*)?$/ # PEP-440 compliant version (tags) + except: + - branches + + +pypi: + stage: pypi + environment: pypi + only: + - /^v\d+\.\d+\.\d+([abc]\d*)?$/ # PEP-440 compliant version (tags) + except: + - branches + before_script: + - ./_ci/install.sh _ci master #updates ci support scripts + script: + - ./_ci/pypi.sh + dependencies: + - build_linux_36 + tags: + - deployer diff --git a/.nvmrc b/.nvmrc deleted file mode 100644 index b009dfb9d9f98f39d71d2a4ecc3110332b969fd3..0000000000000000000000000000000000000000 --- a/.nvmrc +++ /dev/null @@ -1 +0,0 @@ -lts/* diff --git a/LICENSE.AGPL b/LICENSE.AGPL new file mode 100644 index 0000000000000000000000000000000000000000..dba13ed2ddf783ee8118c6a581dbf75305f816a3 --- /dev/null +++ b/LICENSE.AGPL @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +<http://www.gnu.org/licenses/>. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000000000000000000000000000000000000..51f23fd8249e4bcb3938e59fafb73bb999a13476 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include LICENSE.AGPL README.rst version.txt requirements.txt buildout.cfg +recursive-include doc conf.py *.rst *.png *.ico +recursive-include beat/editor/templates *.jinja2 +recursive-include beat/editor/js * diff --git a/README.rst b/README.rst new file mode 100644 index 0000000000000000000000000000000000000000..a0cced31bcedcd9e79c1175f1588532aad966181 --- /dev/null +++ b/README.rst @@ -0,0 +1,65 @@ +.. vim: set fileencoding=utf-8 : + +.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ .. +.. Contact: beat.support@idiap.ch .. +.. .. +.. This file is part of the beat.editor module of the BEAT platform. .. +.. .. +.. Commercial License Usage .. +.. Licensees holding valid commercial BEAT licenses may use this file in .. +.. accordance with the terms contained in a written agreement between you .. +.. and Idiap. For further information contact tto@idiap.ch .. +.. .. +.. Alternatively, this file may be used under the terms of the GNU Affero .. +.. Public License version 3 as published by the Free Software and appearing .. +.. in the file LICENSE.AGPL included in the packaging of this file. .. +.. The BEAT platform is distributed in the hope that it will be useful, but .. +.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY .. +.. or FITNESS FOR A PARTICULAR PURPOSE. .. +.. .. +.. You should have received a copy of the GNU Affero Public License along .. +.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. .. + +.. image:: https://img.shields.io/badge/docs-stable-yellow.svg + :target: https://www.idiap.ch/software/beat/docs/beat/beat.editor/stable/index.html +.. image:: https://img.shields.io/badge/docs-latest-orange.svg + :target: https://www.idiap.ch/software/beat/docs/beat/beat.editor/master/index.html +.. image:: https://gitlab.idiap.ch/beat/beat.editor/badges/master/build.svg + :target: https://gitlab.idiap.ch/beat/beat.editor/commits/master +.. image:: https://gitlab.idiap.ch/beat/beat.editor/badges/master/coverage.svg + :target: https://gitlab.idiap.ch/beat/beat.editor/commits/master +.. image:: https://img.shields.io/badge/gitlab-project-0000c0.svg + :target: https://gitlab.idiap.ch/beat/beat.editor +.. image:: https://img.shields.io/pypi/v/beat.editor.svg + :target: https://pypi.python.org/pypi/beat.editor + + +=============================== + Local editor for BEAT objects +=============================== + +This package part of BEAT_, an open-source evaluation platform for data science +algorithms and workflows. It contains the source code for a local editor for +BEAT objects. + + +Installation +------------ + +Complete BEAT's `installation`_ instructions. Then, to install this package, +run:: + + $ conda install beat.editor + + +Contact +------- + +For questions or reporting issues to this software package, contact our +development `mailing list`_. + + +.. Place your references here: +.. _beat: https://www.idiap.ch/software/beat +.. _installation: https://www.idiap.ch/software/beat/install +.. _mailing list: https://www.idiap.ch/software/beat/discuss diff --git a/beat/__init__.py b/beat/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..71f2674e21adb38c7967af653043b066d09ce056 --- /dev/null +++ b/beat/__init__.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : + +############################################################################### +# # +# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ # +# Contact: beat.support@idiap.ch # +# # +# This file is part of the beat.editor module of the BEAT platform. # +# # +# Commercial License Usage # +# Licensees holding valid commercial BEAT licenses may use this file in # +# accordance with the terms contained in a written agreement between you # +# and Idiap. For further information contact tto@idiap.ch # +# # +# Alternatively, this file may be used under the terms of the GNU Affero # +# Public License version 3 as published by the Free Software and appearing # +# in the file LICENSE.AGPL included in the packaging of this file. # +# The BEAT platform is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # +# or FITNESS FOR A PARTICULAR PURPOSE. # +# # +# You should have received a copy of the GNU Affero Public License along # +# with the BEAT platform. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + +# see https://docs.python.org/3/library/pkgutil.html +from pkgutil import extend_path +__path__ = extend_path(__path__, __name__) diff --git a/src/components/plotter/PlotterEditor.spec.jsx b/beat/editor/__init__.py similarity index 100% rename from src/components/plotter/PlotterEditor.spec.jsx rename to beat/editor/__init__.py diff --git a/beat/editor/resources.py b/beat/editor/resources.py new file mode 100644 index 0000000000000000000000000000000000000000..ae5def8af805f24d74de2f034601231b8a8b7286 --- /dev/null +++ b/beat/editor/resources.py @@ -0,0 +1,346 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +############################################################################### +# # +# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ # +# Contact: beat.support@idiap.ch # +# # +# This file is part of the beat.editor module of the BEAT platform. # +# # +# Commercial License Usage # +# Licensees holding valid commercial BEAT licenses may use this file in # +# accordance with the terms contained in a written agreement between you # +# and Idiap. For further information contact tto@idiap.ch # +# # +# Alternatively, this file may be used under the terms of the GNU Affero # +# Public License version 3 as published by the Free Software and appearing # +# in the file LICENSE.AGPL included in the packaging of this file. # +# The BEAT platform is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # +# or FITNESS FOR A PARTICULAR PURPOSE. # +# # +# You should have received a copy of the GNU Affero Public License along # +# with the BEAT platform. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + + +'''Server resources (API endpoints)''' + + +import os +import glob +import shutil +import subprocess + +import simplejson + +from flask import request +from flask_restful import Resource + +import logging +logger = logging.getLogger(__name__) + +from . import utils + +from beat.core.dock import Host +from beat.core.environments import enumerate_packages + + +class Layout(Resource): + """Exposes toolchain layout functionality""" + + def __init__(self, config): + self.config = config + + def post(self): + data = request.get_json() + if data != None and 'toolchain' in data: + from beat.core.toolchain import Toolchain + obj = Toolchain(self.config.path, data['toolchain']) + diagram = obj.dot_diagram(is_layout=True) + diagram.format = 'json' + return diagram.pipe().decode() + + else: + raise RuntimeError('Invalid post content for tc layout!') + + +class Environments(Resource): + """Exposes local environment info""" + + def get(self): + """Uses beat.core to get the local environment (docker) information + and returns a list of environments""" + host = Host() + envs = host.processing_environments + for env in envs.keys(): + envs[env]['queues'] = {} + try: + envs[env]['packages'] = enumerate_packages(host, env) + except: + envs[env]['packages'] = [] + return envs + + +class Templates(Resource): + """Endpoint for generating template files""" + def __init__(self, config): + self.config = config + + def post(self): + data = request.get_json() + entity = data.pop('entity') + name = data.pop('name') + utils.generate_python_template(entity, name, self.config, **data) + + +def path_to_dict(path): + """Generates a dict of the given file/folder in the BEAT prefix""" + + d = dict(name=os.path.basename(path)) + if os.path.isdir(path): + d['type'] = "directory" + d['children'] = [path_to_dict(os.path.join(path, x)) + for x in os.listdir(path)] + elif os.path.isfile(path): + d['type'] = "file" + fname, fext = os.path.splitext(path) + if fext == '.json': + with open(path, 'rt') as f: + d['json'] = simplejson.loads(f.read()) + return d + + +VALID_ENTITIES = [ + 'dataformats', + 'databases', + 'libraries', + 'algorithms', + 'toolchains', + 'experiments', + 'plotters', + 'plotterparameters', +] +"""List of valid BEAT object entitities""" + + +def assert_valid_entity(v): + """Asserts the passed value corresponds to a valid BEAT entity""" + + assert v in VALID_ENTITIES, '%s is not a valid BEAT entity ' \ + '(valid values are %s)' % (v, ', '.join(VALID_ENTITIES)) + + +def generate_file_tree(entity, config): + """Generates a file tree (of dicts) given a specific BEAT entity""" + + assert_valid_entity(entity) + resource_path = os.path.join(config.path, entity) + if not os.path.isdir(resource_path): + raise IOError('Invalid resource path %s' % resource_path) + + return path_to_dict(resource_path) + + +def generate_json_entity(fto, parent_names): + """Generates info for a file in the BEAT path""" + if fto['type'] != 'file': + raise Exception('bad file tree obj') + + fname, fext = os.path.splitext(fto['name']) + + name_str = '' + for name in parent_names: + name_str += name + '/' + + name_str += fname + + return { + 'name': name_str, + 'contents': fto['json'] + } + + +def generate_entity_tree(entity, config): + """Generates the entire tree for an entity type from the prefix""" + + file_tree = generate_file_tree(entity, config) + entity_tree = {} + user_and_name = [ + 'dataformats', + 'libraries', + 'algorithms', + 'toolchains', + 'plotters', + 'plotterparameters', + ] + + if entity in user_and_name: + for user in file_tree['children']: + entity_tree[user['name']] = {} + for obj in user['children']: + entity_tree[user['name']][obj['name']] = list() + for f in obj['children']: + fname, fext = os.path.splitext(f['name']) + if fext != '.json': + continue + parent_names = [user['name'], obj['name']] + json_obj = generate_json_entity(f, parent_names) + entity_tree[user['name']][obj['name']].append(json_obj) + + elif entity == 'databases': + for obj in file_tree['children']: + entity_tree[obj['name']] = list() + for f in obj['children']: + fname, fext = os.path.splitext(f['name']) + if fext != '.json': + continue + parent_names = [obj['name']] + json_obj = generate_json_entity(f, parent_names) + entity_tree[obj['name']].append(json_obj) + + elif entity == 'experiments': + for user in file_tree['children']: + uname = user['name'] + entity_tree[uname] = {} + for tc_user in user['children']: + tcuname = tc_user['name'] + entity_tree[uname][tcuname] = {} + for tc_name in tc_user['children']: + tcname = tc_name['name'] + entity_tree[uname][tcuname][tcname] = {} + for tc_version in tc_name['children']: + tcv = tc_version['name'] + entity_tree[uname][tcuname][tcname][tcv] = list() + for exp_name in tc_version['children']: + fname, fext = os.path.splitext(exp_name['name']) + if fext != '.json': + continue + parent_names = [uname, tcuname, tcname, tcv] + json_obj = generate_json_entity( + exp_name, parent_names) + entity_tree[uname][tcuname][tcname][tcv].append( + json_obj) + + return entity_tree + + +def write_json(config, entity, obj, mode, copy_obj_name=''): + """Writes JSON from a webapp request to the prefix using the specified + mode""" + + assert_valid_entity(entity) + resource_path = os.path.join(config.path, entity) + name = obj['name'] + name_segs = name.split('/') + contents = obj['contents'] + stringified = simplejson.dumps(contents, indent=4, sort_keys=True) + + folder_path = os.path.join(resource_path, '/'.join(name_segs[:-1])) + file_subpath = os.path.join(resource_path, name) + file_path = file_subpath + '.json' + + if mode == 'update': + os.makedirs(folder_path, exist_ok=True) + with open(file_path, 'w') as f: + f.write(stringified) + + elif mode == 'create': + if not os.path.isfile(file_path): + os.makedirs(folder_path, exist_ok=True) + if copy_obj_name != '': + copy_obj_path = os.path.join(resource_path, copy_obj_name) + if os.path.isfile(copy_obj_path + '.json'): + files_to_copy = glob.glob('%s.*' % copy_obj_path) + copy_locations = ['%s%s' % (file_subpath, os.path.splitext(f)[1]) for f in files_to_copy] + for i in range(0, len(files_to_copy)): + if files_to_copy[i].endswith('.json'): continue + shutil.copy(files_to_copy[i], copy_locations[i]) + with open(file_path, 'w') as f: + f.write(stringified) + + elif mode == 'delete': + if os.path.isfile(file_path): + files_to_delete = glob.glob('%s.*' % file_subpath) + for f in files_to_delete: + os.remove(f) + # taken from https://stackoverflow.com/a/23488980 + + def remove_empty_dirs(path): + """Remove empty directories recursively""" + + for root, dirnames, filenames in os.walk(path, topdown=False): + for dirname in dirnames: + remove_empty_dirs( + os.path.realpath( + os.path.join(root, dirname) + ) + ) + if not os.listdir(path): os.rmdir(path) + + remove_empty_dirs(folder_path) + + else: + raise ValueError('Invalid write-mode `%s\'' % mode) + + +def gen_endpoint(entity): + """Generates an endpoint for the given BEAT entity + + Exposes actions to perform on the prefix + + """ + + class Endpoint(Resource): + """A class representing the template for an endpoint for a BEAT entity""" + + def __init__(self, config): + self.config = config + + def refresh(self): + """Regenerates the entity tree""" + try: + return generate_entity_tree(entity, self.config) + except IOError: + return [] + + def get(self): + """Returns the entity tree""" + return self.refresh() + + def post(self): + """Creates a new object""" + obj_list = request.get_json() + if not isinstance(obj_list, list): + obj_list = [obj_list] + for o in obj_list: + # two fields: + # - "obj" field (the object to create) + # - "copyObjName" field (the object that was copied, blank if + # not copied) + obj = o['obj'] + copy_obj_name = o['copiedObjName'] + write_json(self.config, entity, obj, 'create', copy_obj_name) + return self.refresh() + + def put(self): + """Updates an already-existing object""" + obj_list = request.get_json() + if not isinstance(obj_list, list): + obj_list = [obj_list] + for obj in obj_list: + write_json(self.config, entity, obj, 'update') + return self.refresh() + + def delete(self): + """Deletes an object""" + obj = request.get_json() + write_json(self.config, entity, obj, 'delete') + return self.refresh() + + Endpoint.__name__ = entity + + return Endpoint diff --git a/src/components/plotterparameter/PlotterParameterEditor.spec.jsx b/beat/editor/scripts/__init__.py similarity index 100% rename from src/components/plotterparameter/PlotterParameterEditor.spec.jsx rename to beat/editor/scripts/__init__.py diff --git a/beat/editor/scripts/server.py b/beat/editor/scripts/server.py new file mode 100644 index 0000000000000000000000000000000000000000..afed2895787609a50714103ad28cf570cf60a0d9 --- /dev/null +++ b/beat/editor/scripts/server.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +############################################################################### +# # +# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ # +# Contact: beat.support@idiap.ch # +# # +# This file is part of the beat.editor module of the BEAT platform. # +# # +# Commercial License Usage # +# Licensees holding valid commercial BEAT licenses may use this file in # +# accordance with the terms contained in a written agreement between you # +# and Idiap. For further information contact tto@idiap.ch # +# # +# Alternatively, this file may be used under the terms of the GNU Affero # +# Public License version 3 as published by the Free Software and appearing # +# in the file LICENSE.AGPL included in the packaging of this file. # +# The BEAT platform is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # +# or FITNESS FOR A PARTICULAR PURPOSE. # +# # +# You should have received a copy of the GNU Affero Public License along # +# with the BEAT platform. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + + +"""Starts the BEAT editor + +Usage: %(prog)s [-v...] [--debug] [--prefix=<path>] [--cache=<path>] [--dev] + %(prog)s --help + %(prog)s --version + + +Options: + + -h, --help Shows this help message and exits + -V, --version Prints the version and exits + -v, --verbose Increases the output verbosity level. Using "-vv" + allows the program to output informational messages as + it goes along. + -d, --debug Use the debug version of the javascript source to + launch the editor + --dev Use the development version, which doesn't open a new + web browser tab. + -p, --prefix=<path> Overrides the prefix of your local data. If not set use + the value from your RC file + [default: %(prefix)s] + -c, --cache=<path> Overrides the cache prefix. If not set, use the value + from your RC file, otherwise defaults to + `<prefix>/%(cache)s' + + +Examples: + + Start the editor: + + $ %(prog)s -vv + + Start the editor in development mode: + + $ %(prog)s -vv --debug + +""" + + +import os +import sys +import docopt + +from beat.cmdline.config import Configuration + + +def main(user_input=None): + + if user_input is not None: + argv = user_input + else: + argv = sys.argv[1:] + + import pkg_resources + + completions = dict( + prog=os.path.basename(sys.argv[0]), + version=pkg_resources.require('beat.editor')[0].version + ) + + from beat.cmdline.config import Configuration + completions.update(Configuration({}).as_dict()) + + args = docopt.docopt( + __doc__ % completions, + argv=argv, + version=completions['version'], + ) + + from ..utils import setup_logger + logger = setup_logger('beat.editor', args['--verbose']) + + # Check that we are in a BEAT working folder + config = Configuration(args) + logger.info('BEAT prefix set to `%s\'', config.path) + logger.info('BEAT cache set to `%s\'', config.cache) + + from flask import Flask, request, redirect, url_for + from flask_restful import Api + from flask_cors import CORS + from ..resources import Layout, Templates, Environments + from ..resources import VALID_ENTITIES, gen_endpoint + + static_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../js') + app = Flask(__name__, static_folder=static_folder, static_url_path='') + api = Api(app) + CORS(app) + + @app.route('/') + def home(): + return redirect(url_for('static', filename='index.html')) + + api.add_resource(Layout, '/layout', resource_class_kwargs={'config': config}) + api.add_resource(Templates, '/templates', resource_class_kwargs={'config': config}) + api.add_resource(Environments, '/environments') + for entity in VALID_ENTITIES: + api.add_resource(gen_endpoint(entity), '/' + entity, + resource_class_kwargs={'config': config}) + + + # open the browser tab right before starting the server + # the latency of opening the tab will keep us from getting 404s + if not args['--dev']: + import webbrowser + webbrowser.open('http://localhost:5000/') + + app.run(debug=args['--debug']) diff --git a/templates/algorithm.jinja2 b/beat/editor/templates/algorithm.jinja2 similarity index 100% rename from templates/algorithm.jinja2 rename to beat/editor/templates/algorithm.jinja2 diff --git a/templates/database.jinja2 b/beat/editor/templates/database.jinja2 similarity index 100% rename from templates/database.jinja2 rename to beat/editor/templates/database.jinja2 diff --git a/templates/library.jinja2 b/beat/editor/templates/library.jinja2 similarity index 100% rename from templates/library.jinja2 rename to beat/editor/templates/library.jinja2 diff --git a/beat/editor/utils.py b/beat/editor/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..84fedf4ddda50d5778f6c292f5767bac7365d046 --- /dev/null +++ b/beat/editor/utils.py @@ -0,0 +1,176 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +############################################################################### +# # +# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ # +# Contact: beat.support@idiap.ch # +# # +# This file is part of the beat.editor module of the BEAT platform. # +# # +# Commercial License Usage # +# Licensees holding valid commercial BEAT licenses may use this file in # +# accordance with the terms contained in a written agreement between you # +# and Idiap. For further information contact tto@idiap.ch # +# # +# Alternatively, this file may be used under the terms of the GNU Affero # +# Public License version 3 as published by the Free Software and appearing # +# in the file LICENSE.AGPL included in the packaging of this file. # +# The BEAT platform is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # +# or FITNESS FOR A PARTICULAR PURPOSE. # +# # +# You should have received a copy of the GNU Affero Public License along # +# with the BEAT platform. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + + +import os +import sys + +import jinja2 + +import logging +logger = logging.getLogger(__name__) + + +ENV = jinja2.Environment(loader=jinja2.PackageLoader(__name__, 'templates')) +"""Jinja2 environment for loading our templates""" + + +def generate_database(views=None): + """Generates a valid BEAT database from our stored template + + + Parameters: + + views (:py:class:`list`, Optional): A list of strings that represents the + views for the database + + + Returns: + + str: The rendered template as a string + + """ + + views = views or ['View'] + template = ENV.get_template('database.jinja2') + return template.render(views=views) + + +def generate_library(uses=None): + """Generates a valid BEAT library from our stored template + + + Parameters: + + uses (:py:class:`dict`, Optional): A dict of other libraries that the + library uses. Keys are the value to reference the library, values are + the library being referenced. + + + Returns: + + str: The rendered template as a string + + """ + + uses = uses or {} + template = ENV.get_template('library.jinja2') + return template.render(uses=uses) + + +def generate_algorithm(has_parameters=False, uses=None): + """Generates a valid BEAT algorithm from our stored template + + + Parameters: + + has_parameters (:py:class:`bool`, Optional): Whether the algorithm has + parameters or not (default: False) + + uses (:py:class:`dict`, Optional): A dict of libraries that the algorithm + uses. Keys are the value to reference the library, values are the + library being referenced. + + + Returns: + + str: The rendered template as a string + + """ + + uses = uses or {} + template = ENV.get_template('algorithm.jinja2') + return template.render(uses=uses, has_parameters=has_parameters) + + +TEMPLATE_FUNCTION = dict( + databases=generate_database, + libraries=generate_library, + algorithms=generate_algorithm, +) +"""Functions for template instantiation within beat.editor""" + + +def generate_python_template(entity, name, config, **kwargs): + """Generates a template for a BEAT entity with the given named arguments + + + Parameters: + + entity (str): A valid BEAT entity (valid values are + """ + + s = TEMPLATE_FUNCTION[entity](**kwargs) + + resource_path = os.path.join(config.path, entity) + file_path = os.path.join(resource_path, name) + '.py' + with open(file_path, 'w') as f: f.write(s) + + return s + + +def setup_logger(name, verbosity): + '''Sets up the logging of a script + + + Parameters: + + name (str): The name of the logger to setup + + verbosity (int): The verbosity level to operate with. A value of ``0`` + (zero) means only errors, ``1``, errors and warnings; ``2``, errors, + warnings and informational messages and, finally, ``3``, all types of + messages including debugging ones. + + ''' + + logger = logging.getLogger(name) + formatter = logging.Formatter("%(name)s@%(asctime)s -- %(levelname)s: " \ + "%(message)s") + + _warn_err = logging.StreamHandler(sys.stderr) + _warn_err.setFormatter(formatter) + _warn_err.setLevel(logging.WARNING) + + class _InfoFilter: + def filter(self, record): return record.levelno <= logging.INFO + + _debug_info = logging.StreamHandler(sys.stdout) + _debug_info.setFormatter(formatter) + _debug_info.setLevel(logging.DEBUG) + _debug_info.addFilter(_InfoFilter()) + + logger.addHandler(_debug_info) + logger.addHandler(_warn_err) + + + logger.setLevel(logging.ERROR) + if verbosity == 1: logger.setLevel(logging.WARNING) + elif verbosity == 2: logger.setLevel(logging.INFO) + elif verbosity >= 3: logger.setLevel(logging.DEBUG) + + return logger diff --git a/buildout.cfg b/buildout.cfg new file mode 100644 index 0000000000000000000000000000000000000000..5dd40ea146ed3b7ada5b0cbf63e5a9fcaa0462e1 --- /dev/null +++ b/buildout.cfg @@ -0,0 +1,8 @@ +[buildout] +parts = scripts +eggs = beat.editor +develop = . +newest = false + +[scripts] +recipe = bob.buildout:scripts diff --git a/.babelrc b/conda/js/.babelrc similarity index 100% rename from .babelrc rename to conda/js/.babelrc diff --git a/.eslintrc.js b/conda/js/.eslintrc.js similarity index 100% rename from .eslintrc.js rename to conda/js/.eslintrc.js diff --git a/.flowconfig b/conda/js/.flowconfig similarity index 100% rename from .flowconfig rename to conda/js/.flowconfig diff --git a/.postcssrc b/conda/js/.postcssrc similarity index 100% rename from .postcssrc rename to conda/js/.postcssrc diff --git a/.stylelintrc b/conda/js/.stylelintrc similarity index 100% rename from .stylelintrc rename to conda/js/.stylelintrc diff --git a/.tern-project b/conda/js/.tern-project similarity index 100% rename from .tern-project rename to conda/js/.tern-project diff --git a/index.html b/conda/js/index.html similarity index 100% rename from index.html rename to conda/js/index.html diff --git a/karma.conf.js b/conda/js/karma.conf.js similarity index 94% rename from karma.conf.js rename to conda/js/karma.conf.js index 034e2c436947ef4575a9153317d23f2d38d25da8..98c6bd36dac6c191beddc069b093e8bf78aeeb01 100644 --- a/karma.conf.js +++ b/conda/js/karma.conf.js @@ -8,7 +8,8 @@ delete webpackConfig.entry; module.exports = function (config) { config.set({ browsers: [ - 'ChromeHeadless', + // TODO: try to renable once chromium >55 comes out + //'ChromeHeadless', 'FirefoxHeadless', ], customLaunchers: { diff --git a/main.css b/conda/js/main.css similarity index 100% rename from main.css rename to conda/js/main.css diff --git a/main.jsx b/conda/js/main.jsx similarity index 100% rename from main.jsx rename to conda/js/main.jsx diff --git a/package-lock.json b/conda/js/package-lock.json similarity index 100% rename from package-lock.json rename to conda/js/package-lock.json diff --git a/package.json b/conda/js/package.json similarity index 98% rename from package.json rename to conda/js/package.json index d70c7cd29b2e0533a544c6c70591dd1d9c8df83f..db871a67febd881916da5e88bebd1bc22dabdafa 100644 --- a/package.json +++ b/conda/js/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "start": "cross-env NODE_ENV=debug webpack-dev-server --hot", - "prebuild": "rimraf dist", + "prebuild": "rimraf ../../beat/editor/js", "build": "cross-env NODE_ENV=production webpack", "test-start": "cross-env BABEL_ENV=test NODE_ENV=test karma start --no-single-run", "test": "cross-env BABEL_ENV=test NODE_ENV=test karma start", diff --git a/src/components/App.jsx b/conda/js/src/components/App.jsx similarity index 100% rename from src/components/App.jsx rename to conda/js/src/components/App.jsx diff --git a/src/components/CacheInput.jsx b/conda/js/src/components/CacheInput.jsx similarity index 64% rename from src/components/CacheInput.jsx rename to conda/js/src/components/CacheInput.jsx index f14cbd1a80864a4434a34d6d69ac6ff017867e32..a0f216a78109fa977550d0487bb37fa5a7f2572d 100644 --- a/src/components/CacheInput.jsx +++ b/conda/js/src/components/CacheInput.jsx @@ -12,22 +12,36 @@ import { import { rxField } from '@helpers/beat'; type Props = { + // consumer-supplied func for validating input + // if the func finds the input isnt valid, it should return a react.node of text for the error message validateFunc?: (string) => (true | React.Node), + // if the current input in the CacheInput instance is valid, this func will be called with that value onChange: (any) => any, + // the current value for this cacheinput value: string, + // for edge cases children?: React.Node, + // many fields in the beat editor are restricted to a certain "slugified" format + // if this cacheinput needs that, use this flag fieldTest?: boolean, - // delay in ms, defaults to 500 + // update delay in ms, defaults to 500 + // basically just simple throttling to keep from overwhelming complex updates in the parent delay?: number, }; type State = { + // the current string in the CacheInput input field, + // which may or may not be valid cache: string, + // whether the cache is valid valid: boolean, + // a text-like react node that represents an error message invalidityText?: React.Node, + // the delay to use (default 500) msDelay: number, }; +// test for the "fieldTest" flag, with a nice error message const fieldTestResults = (input: string): true | React.Node => { return (rxField.test(input) || <span> @@ -36,6 +50,8 @@ const fieldTestResults = (input: string): true | React.Node => { ); }; +// top-level validity func with some edgecase checking +// validateFunc arg lets you also check using a user-defined validate func const isValid = (input: string, currVal: string, validateFunc: (string) => true | React.Node, fieldTest: boolean): true | React.Node => { if(input === currVal) return true; @@ -51,6 +67,8 @@ const isValid = (input: string, currVal: string, validateFunc: (string) => true return funcRes; }; +// Provides a bootstrap-styled wrapper around <input /> that caches the raw user input until a valid input is provided. +// Also throttles the onChange event to prevent many parent state updates in a short time class CacheInput extends React.Component<Props, State>{ constructor(props: Props){ super(props); @@ -64,10 +82,12 @@ class CacheInput extends React.Component<Props, State>{ msDelay: this.props.delay !== undefined ? this.props.delay : 500, }; + // check validation as soon as it mounts componentDidMount () { this.updateValidity(this.state.cache); } + // if the parent's model changes, reset input componentWillReceiveProps (nextProps: any) { this.setState({ cache: (nextProps.value), @@ -75,6 +95,7 @@ class CacheInput extends React.Component<Props, State>{ this.clearTimer(); } + // gets the validity info of an input string given a curr val updateValidity = (input: string, currVal?: string = this.props.value) => { const func = this.props.validateFunc || (() => true); const validRes = isValid(input, currVal, func, this.props.fieldTest || false); @@ -86,6 +107,8 @@ class CacheInput extends React.Component<Props, State>{ return validRes === true; } + // the user can pass any props they want onto the inner <Input /> element + // some props shouldn't be passed though getInputProps = () => { const inputProps = { ...this.props }; delete inputProps['validateFunc']; @@ -95,12 +118,16 @@ class CacheInput extends React.Component<Props, State>{ return inputProps; } + // throttle timer ref onChangeTimer = null; + // clears the throttle timer clearTimer = () => { if(this.onChangeTimer) clearTimeout(this.onChangeTimer); } + // called whenever the user changes the raw input with the raw input event + // for perf reasons it really focuses on returning when possible change = (e: any) => { this.clearTimer(); const newInput = e.target.value; @@ -118,6 +145,9 @@ class CacheInput extends React.Component<Props, State>{ if(this.state.msDelay === 0){ this.props.onChange(e); } else { + // by default in react events have a "persist" method + // that lets you keep it around for a bit longer than normal + // in testing environments the event persists by default if(e.persist) e.persist(); this.onChangeTimer = setTimeout(() => { @@ -127,6 +157,7 @@ class CacheInput extends React.Component<Props, State>{ } } + // the Tooltips are annoying in test environments and need a react ref target = null render () { diff --git a/src/components/CacheInput.spec.jsx b/conda/js/src/components/CacheInput.spec.jsx similarity index 100% rename from src/components/CacheInput.spec.jsx rename to conda/js/src/components/CacheInput.spec.jsx diff --git a/src/components/DeleteInputBtn.jsx b/conda/js/src/components/DeleteInputBtn.jsx similarity index 79% rename from src/components/DeleteInputBtn.jsx rename to conda/js/src/components/DeleteInputBtn.jsx index e8cc0207d87379b6ad37fef82e63d6575e2c71b4..bec3cd7ece45c1e31808f2c3f4eb0854c3d1c67c 100644 --- a/src/components/DeleteInputBtn.jsx +++ b/conda/js/src/components/DeleteInputBtn.jsx @@ -9,6 +9,8 @@ type Props = { deleteFunc: (any) => any, } +// super simple wrapper for a button that attaches to an input +// styled like a Delete button const DeleteInputBtn = ({ deleteFunc }: Props) => ( <InputGroupAddon addonType='prepend'> <Button diff --git a/src/components/DeleteInputBtn.spec.jsx b/conda/js/src/components/DeleteInputBtn.spec.jsx similarity index 100% rename from src/components/DeleteInputBtn.spec.jsx rename to conda/js/src/components/DeleteInputBtn.spec.jsx diff --git a/src/components/EntityDetail.jsx b/conda/js/src/components/EntityDetail.jsx similarity index 85% rename from src/components/EntityDetail.jsx rename to conda/js/src/components/EntityDetail.jsx index d90a1ae52717a26626a92f53178c560a4b907d81..b94caf856c906ea18227384f4eb44950654104c4 100644 --- a/src/components/EntityDetail.jsx +++ b/conda/js/src/components/EntityDetail.jsx @@ -37,18 +37,28 @@ import PlotterEditorContainer from './plotter'; import PlotterparameterEditorContainer from './plotterparameter'; type Props = { + // the match object from react-router + // used to find which object to render match: any, + // the history object from react-router + // used to push new history to history: any, + // gets the object based on the current URL getEntityObject: () => BeatObject, + // updates the current object updateFunc: (BeatObject) => any, }; +// 3 tabs so far: editor, docs, raw json type Tab = '0' | '1' | '2'; type State = { + // which tab is active activeTab: Tab, }; +// wrapper for editors +// doesnt really do much now besides the raw json tab export class EntityDetail extends React.Component<Props, State> { constructor(props: Props){ super(props); @@ -72,6 +82,7 @@ export class EntityDetail extends React.Component<Props, State> { return ( <Container> <Row> + {/* title line (name & validation info) */} <Col> <h4 style={{'textAlign': 'center'}}> <span style={{'textTransform': 'capitalize'}}> @@ -114,6 +125,7 @@ export class EntityDetail extends React.Component<Props, State> { </NavItem> </Nav> <TabContent activeTab={this.state.activeTab} className='mt-2'> + {/* Uses the appropriate editor, could probably be done nicer */} <TabPane tabId='0'> { this.props.match.params.entity === 'algorithm' && @@ -191,9 +203,13 @@ export class EntityDetail extends React.Component<Props, State> { } const mapStateToProps = (state, ownProps) => { + // which beat entity is currently active: 'algorithm', 'plotter', 'database', etc. const entity = ownProps.match.params.entity; + // the name of the object ("atnt/1", "plot/isoroc/1", "user/tc/test/1/exp", etc.) const name = ownProps.match.params.name; const obj = { + // uses a selector based off the entity and finds the obj given the name + // if the obj doesnt exist (huge edge case) just return a default obj to not break everything getEntityObject: (): BeatObject => Selectors[`${ entity }Get`](state).find(o => o.name === name) || getDefaultEntityObject(), }; @@ -201,6 +217,7 @@ const mapStateToProps = (state, ownProps) => { }; const mapDispatchToProps = (dispatch, ownProps) => ({ + // replace the obj in the Redux store with the new object updateFunc: (obj) => { dispatch(Actions[`${ ownProps.match.params.entity }Update`](ownProps.match.params.name, obj)); ownProps.history.push(`/${ ownProps.match.params.entity }/${ obj.name }`); diff --git a/src/components/EntityHome.jsx b/conda/js/src/components/EntityHome.jsx similarity index 100% rename from src/components/EntityHome.jsx rename to conda/js/src/components/EntityHome.jsx diff --git a/src/components/EntityList.jsx b/conda/js/src/components/EntityList.jsx similarity index 100% rename from src/components/EntityList.jsx rename to conda/js/src/components/EntityList.jsx diff --git a/src/components/EntityTemplateGenerationButton.jsx b/conda/js/src/components/EntityTemplateGenerationButton.jsx similarity index 100% rename from src/components/EntityTemplateGenerationButton.jsx rename to conda/js/src/components/EntityTemplateGenerationButton.jsx diff --git a/src/components/HomeContent.jsx b/conda/js/src/components/HomeContent.jsx similarity index 100% rename from src/components/HomeContent.jsx rename to conda/js/src/components/HomeContent.jsx diff --git a/src/components/InfoTooltip.jsx b/conda/js/src/components/InfoTooltip.jsx similarity index 100% rename from src/components/InfoTooltip.jsx rename to conda/js/src/components/InfoTooltip.jsx diff --git a/src/components/MainContent.jsx b/conda/js/src/components/MainContent.jsx similarity index 100% rename from src/components/MainContent.jsx rename to conda/js/src/components/MainContent.jsx diff --git a/src/components/MainNav.jsx b/conda/js/src/components/MainNav.jsx similarity index 90% rename from src/components/MainNav.jsx rename to conda/js/src/components/MainNav.jsx index ac72d3f43dbe8116b6a1b4326ac99305112e999e..ad735983867317657e01a9422d640def2dc41329 100644 --- a/src/components/MainNav.jsx +++ b/conda/js/src/components/MainNav.jsx @@ -104,13 +104,18 @@ export class MainNav extends React.Component<Props, State> { } </Nav> <Nav className="ml-auto" navbar> - <NavItem className='mr-1'> - <Button outline onClick={this.toggle}>Settings</Button> - <Settings - isOpen={this.state.settingsOpen} - toggle={this.toggle} - /> - </NavItem> + { + // right now we have no settings so there's no need to offer the user this modal + /* + <NavItem className='mr-1'> + <Button outline onClick={this.toggle}>Settings</Button> + <Settings + isOpen={this.state.settingsOpen} + toggle={this.toggle} + /> + </NavItem> + */ + } <NavItem> <Button outline color={this.props.unsavedChanges ? 'primary' : 'secondary'} disabled={this.state.isSaving} diff --git a/src/components/NewEntityModal.jsx b/conda/js/src/components/NewEntityModal.jsx similarity index 100% rename from src/components/NewEntityModal.jsx rename to conda/js/src/components/NewEntityModal.jsx diff --git a/src/components/ParameterConsume.jsx b/conda/js/src/components/ParameterConsume.jsx similarity index 100% rename from src/components/ParameterConsume.jsx rename to conda/js/src/components/ParameterConsume.jsx diff --git a/src/components/ParameterCreate.jsx b/conda/js/src/components/ParameterCreate.jsx similarity index 100% rename from src/components/ParameterCreate.jsx rename to conda/js/src/components/ParameterCreate.jsx diff --git a/src/components/SearchBar.jsx b/conda/js/src/components/SearchBar.jsx similarity index 100% rename from src/components/SearchBar.jsx rename to conda/js/src/components/SearchBar.jsx diff --git a/src/components/Settings.jsx b/conda/js/src/components/Settings.jsx similarity index 100% rename from src/components/Settings.jsx rename to conda/js/src/components/Settings.jsx diff --git a/src/components/TypedField.jsx b/conda/js/src/components/TypedField.jsx similarity index 100% rename from src/components/TypedField.jsx rename to conda/js/src/components/TypedField.jsx diff --git a/src/components/ValidSchemaBadge.jsx b/conda/js/src/components/ValidSchemaBadge.jsx similarity index 100% rename from src/components/ValidSchemaBadge.jsx rename to conda/js/src/components/ValidSchemaBadge.jsx diff --git a/src/components/ValidSchemaBadge.spec.jsx b/conda/js/src/components/ValidSchemaBadge.spec.jsx similarity index 100% rename from src/components/ValidSchemaBadge.spec.jsx rename to conda/js/src/components/ValidSchemaBadge.spec.jsx diff --git a/src/components/algorithm/AlgorithmEditor.jsx b/conda/js/src/components/algorithm/AlgorithmEditor.jsx similarity index 88% rename from src/components/algorithm/AlgorithmEditor.jsx rename to conda/js/src/components/algorithm/AlgorithmEditor.jsx index f1aaa911f844fb20f6b4580c00ace4b255cac4c0..96e120bf4e871a54dca17029ba5ce7d867605559 100644 --- a/src/components/algorithm/AlgorithmEditor.jsx +++ b/conda/js/src/components/algorithm/AlgorithmEditor.jsx @@ -40,20 +40,29 @@ type Props = { }; type State = { + // which tab the user is viewing (endpoints, params, etc.) activeTab: string, + // data that the user edits, needs use to click "save" to save changes cache: any, + // algorithm-specific validity checking (alerts for common errors & warnings) validity: AlgorithmValidatorObject, + // parameters can restrict their values to individual choices + // this string represents a choice that is being edited choiceCache: string, }; +// represents an input or output value +// inputs/outputs are just an object with a "type" field type IOEntry = {| type: string, |}; +// represents a collection of inputs/outputs type IOObject = { [string]: IOEntry, }; +// represents a group/endpoint, optionally with outputs type Group = { name: string, inputs: IOObject, @@ -73,6 +82,7 @@ export class AlgorithmEditor extends React.Component<Props, State> { choiceCache: '', } + // if the data changes behind the scenes, update the editor with these changes componentWillReceiveProps (nextProps: Props) { this.setState({ cache: getValidObj(nextProps.data), @@ -80,12 +90,16 @@ export class AlgorithmEditor extends React.Component<Props, State> { }); } + // get the result types (analyzer result types are restricted to a subset of all available types) getResultDfs = (): string[] => ANALYZER_RESULT_TYPES.concat(this.props.dataformats.filter(d => d.name.startsWith('plot')).map(d => d.name)) + // returns a validity object based on the given algorithm cache and list of all algorithms getValidity = (cache: BeatObject = this.state.cache, algs: BeatObject[] = this.props.algorithms): AlgorithmValidatorObject => { return algorithmValidator(cache, algs.filter(o => o !== this.props.data)); } + // much like getValidity but just returns a bool + // doesnt worry about warnings, just errors isValid = (cache: BeatObject): boolean => { const isValid = Object.entries(this.getValidity(cache)) .filter(([name, bool]) => name !== (this.isAnalyzer() ? 'endpoint0OutputExists' : 'result0Exists')) @@ -95,10 +109,15 @@ export class AlgorithmEditor extends React.Component<Props, State> { return isValid; } + // change the tab tabTo = (tab: string) => { if(this.state.activeTab !== tab) this.setState({ activeTab: tab }); } + // is the algorithm an analyzer? + // theres no flag set, so instead check for the existence of a 'splittable' field which only normal algorithms have isAnalyzer = (): boolean => { return !Object.keys(this.state.cache.contents).includes('splittable'); } + // helper to change a value in the "contents" subobject of an algorithm + // (this is where the vast majority of change happens) changeContentsVal = (field: string, val: any) => { const newCache = { ...this.state.cache, @@ -113,6 +132,7 @@ export class AlgorithmEditor extends React.Component<Props, State> { }); } + // updates an old group object to a new group object updateGroup = (oldGroup: Group, newGroup: Group) => { const gIdx = this.state.cache.contents.groups.findIndex(g => JSON.stringify(g) === JSON.stringify(oldGroup)); const newGroups = jsonClone(this.state.cache.contents.groups); @@ -134,12 +154,14 @@ export class AlgorithmEditor extends React.Component<Props, State> { this.changeContentsVal('parameters', params); } + // updates a result given the result name and the value obj updateResult = (name: string, res: any) => { const rs = this.state.cache.contents.results; rs[name] = res; this.changeContentsVal('results', rs); } + // toggles the algorithm to an analyzer algorithm changeToAnalyzer = () => { const contents = jsonClone(this.state.cache.contents); contents.groups = contents.groups.map(g => { @@ -159,6 +181,7 @@ export class AlgorithmEditor extends React.Component<Props, State> { }); } + // toggles the algorithm to a normal algorithm changeToNormal = () => { const contents = jsonClone(this.state.cache.contents); delete contents.results; @@ -176,6 +199,8 @@ export class AlgorithmEditor extends React.Component<Props, State> { }); } + // generates a func from a given group & type that takes an input/output name + // and deletes it from the group deleteIO = (group: Group, type: 'inputs' | 'outputs') => (name: string) => { if(!group[type]) return; @@ -183,10 +208,14 @@ export class AlgorithmEditor extends React.Component<Props, State> { this.updateGroup(group, { ...group }); } + // rendergs the endpoints tab renderEndpoints = () => ( <TabPane tabId='0'> { + // loop through all groups in the alg this.state.cache.contents.groups.map((group: Group, i, groups: Group[]) => { + // func to update an input/output + // lets you change the name and/or the type const ioUpdate = (subObj: 'inputs' | 'outputs') => (oldName: string, newName: string, newObj: IOEntry) => { const changedObj = changeObjFieldName(group[subObj], oldName, newName); changedObj[newName] = newObj; @@ -325,8 +354,9 @@ export class AlgorithmEditor extends React.Component<Props, State> { <Button outline block id='newGroupBtn' onClick={(e) => { + const newGroupName = generateNewKey('group', this.state.cache.contents.groups.map(g => g.name)); const newGroup = { - name: `group ${ this.state.cache.contents.groups.length }`, + name: newGroupName, inputs: {}, }; if(!this.isAnalyzer() && this.state.cache.contents.groups.length === 0) @@ -343,10 +373,12 @@ export class AlgorithmEditor extends React.Component<Props, State> { </TabPane> ); + // renders the parameters tab renderParameters = () => { return ( <TabPane tabId='1'> { + // loop through all the parameters (Object.entries(this.state.cache.contents.parameters): [string, any][]).map(([name, param], i, params) => ( <Row key={i} className='mb-2'> <Col sm='12'> @@ -382,11 +414,13 @@ export class AlgorithmEditor extends React.Component<Props, State> { ); } + // renders the libraries tab renderLibraries = () => ( <TabPane tabId='2'> <Row> <Col sm='12'> { + // loop through all the used libs (Object.entries(this.state.cache.contents.uses): [string, any][]) .map(([name, lib], i, lEntries) => ( <TypedField @@ -396,6 +430,7 @@ export class AlgorithmEditor extends React.Component<Props, State> { types={this.props.libraries.map(l => l.name)} existingFields={lEntries.map(([n, v]) => n)} nameUpdateFunc={str => { + // update the alias this.changeContentsVal('uses', changeObjFieldName( this.state.cache.contents.uses, @@ -405,6 +440,7 @@ export class AlgorithmEditor extends React.Component<Props, State> { ); }} typeUpdateFunc={str => { + // update the chosen library for the alias const libs = { ...this.state.cache.contents.uses, [name]: str @@ -438,9 +474,11 @@ export class AlgorithmEditor extends React.Component<Props, State> { </TabPane> ); + // renders the results tab (only if the alg is an analyzer) renderResults = () => ( <TabPane tabId='3'> { + // loop through results (Object.entries(this.state.cache.contents.results): [string, any][]) .map(([name, result], i, rEntries) => ( <TypedField @@ -475,6 +513,7 @@ export class AlgorithmEditor extends React.Component<Props, State> { }} > <Col> + {/* display by default checkbox */} <Label check> <Input type='checkbox' @@ -518,6 +557,7 @@ export class AlgorithmEditor extends React.Component<Props, State> { render = () => ( <div> + {/* header content (save button & template gen button) */} <div className='d-flex'> <Button className='mx-auto' @@ -532,6 +572,7 @@ export class AlgorithmEditor extends React.Component<Props, State> { entity={'algorithm'} /> </div> + {/* simple universal stuff - description, what type of alg, if its splittable */} <Form> <FormGroup tag='fieldset'> <FormGroup> @@ -580,6 +621,7 @@ export class AlgorithmEditor extends React.Component<Props, State> { </FormGroup> } </FormGroup> + {/* most errors/warnings from the current AlgorithmValidator object are displayed here */} { (!this.isAnalyzer() || this.getValidity().result0Exists) || <Alert color='danger'> @@ -605,6 +647,7 @@ export class AlgorithmEditor extends React.Component<Props, State> { You need at least 1 input in the first endpoint group. </Alert> } + {/* all the tabs: endpoints, params, libs, results */} <Nav tabs className='mt-3 mb-3'> <NavItem> <NavLink diff --git a/src/components/algorithm/AlgorithmEditor.spec.jsx b/conda/js/src/components/algorithm/AlgorithmEditor.spec.jsx similarity index 100% rename from src/components/algorithm/AlgorithmEditor.spec.jsx rename to conda/js/src/components/algorithm/AlgorithmEditor.spec.jsx diff --git a/src/components/algorithm/index.js b/conda/js/src/components/algorithm/index.js similarity index 100% rename from src/components/algorithm/index.js rename to conda/js/src/components/algorithm/index.js diff --git a/src/components/database/DatabaseEditor.css b/conda/js/src/components/database/DatabaseEditor.css similarity index 100% rename from src/components/database/DatabaseEditor.css rename to conda/js/src/components/database/DatabaseEditor.css diff --git a/src/components/database/DatabaseEditor.jsx b/conda/js/src/components/database/DatabaseEditor.jsx similarity index 100% rename from src/components/database/DatabaseEditor.jsx rename to conda/js/src/components/database/DatabaseEditor.jsx diff --git a/src/components/database/DatabaseEditor.spec.jsx b/conda/js/src/components/database/DatabaseEditor.spec.jsx similarity index 100% rename from src/components/database/DatabaseEditor.spec.jsx rename to conda/js/src/components/database/DatabaseEditor.spec.jsx diff --git a/src/components/database/index.js b/conda/js/src/components/database/index.js similarity index 100% rename from src/components/database/index.js rename to conda/js/src/components/database/index.js diff --git a/src/components/dataformat/DataformatEditor.jsx b/conda/js/src/components/dataformat/DataformatEditor.jsx similarity index 100% rename from src/components/dataformat/DataformatEditor.jsx rename to conda/js/src/components/dataformat/DataformatEditor.jsx diff --git a/src/components/dataformat/DataformatEditor.spec.jsx b/conda/js/src/components/dataformat/DataformatEditor.spec.jsx similarity index 100% rename from src/components/dataformat/DataformatEditor.spec.jsx rename to conda/js/src/components/dataformat/DataformatEditor.spec.jsx diff --git a/src/components/dataformat/index.js b/conda/js/src/components/dataformat/index.js similarity index 100% rename from src/components/dataformat/index.js rename to conda/js/src/components/dataformat/index.js diff --git a/src/components/experiment/ExperimentEditor.css b/conda/js/src/components/experiment/ExperimentEditor.css similarity index 100% rename from src/components/experiment/ExperimentEditor.css rename to conda/js/src/components/experiment/ExperimentEditor.css diff --git a/src/components/experiment/ExperimentEditor.jsx b/conda/js/src/components/experiment/ExperimentEditor.jsx similarity index 98% rename from src/components/experiment/ExperimentEditor.jsx rename to conda/js/src/components/experiment/ExperimentEditor.jsx index b350106737b0b8c8cb60eae15eb9ea8dbf20ee71..51218f76341f68c48bef1e326bb1a8039cbb7663 100644 --- a/src/components/experiment/ExperimentEditor.jsx +++ b/conda/js/src/components/experiment/ExperimentEditor.jsx @@ -288,30 +288,32 @@ const EnvironmentConfig = ({ envInfo, queue, availableEnvs, updateEnvInfo, updat } </Input> </Col> - <Col> - <Label> - <InfoTooltip - id='queueTooltip' - info={`The "queue" refers to the job queue to put the experiment in once a user decides to run it. This setting currently is only used on the BEAT web platform, and has no effect if ran through beat.cmdline.`} - > - Queue - </InfoTooltip> - </Label> - <Input - type='select' - className='queue custom-select' - value={queue} - onChange={e => updateQueue(e.target.value)} - placeholder='Queue' - disabled={disabled} - > - { - (queues || []).map((queue, i) => - <option key={i} value={queue}>{ queue }</option> - ) - } - </Input> - </Col> + { Array.isArray(queues) && queues.length > 0 && + <Col> + <Label> + <InfoTooltip + id='queueTooltip' + info={`The "queue" refers to the job queue to put the experiment in once a user decides to run it. This setting currently is only used on the BEAT web platform, and has no effect if ran through beat.cmdline.`} + > + Queue + </InfoTooltip> + </Label> + <Input + type='select' + className='queue custom-select' + value={queue} + onChange={e => updateQueue(e.target.value)} + placeholder='Queue' + disabled={disabled} + > + { + (queues).map((queue, i) => + <option key={i} value={queue}>{ queue }</option> + ) + } + </Input> + </Col> + } </FormGroup> ); }; @@ -1101,7 +1103,8 @@ export class ExperimentEditor extends React.Component<Props, State> { ...this.state.cache.contents.globals.environment, name, version, - } + }, + queue: '', } })} updateQueue={queue => this.setContents({ diff --git a/src/components/experiment/ExperimentEditor.spec.jsx b/conda/js/src/components/experiment/ExperimentEditor.spec.jsx similarity index 100% rename from src/components/experiment/ExperimentEditor.spec.jsx rename to conda/js/src/components/experiment/ExperimentEditor.spec.jsx diff --git a/src/components/experiment/index.js b/conda/js/src/components/experiment/index.js similarity index 100% rename from src/components/experiment/index.js rename to conda/js/src/components/experiment/index.js diff --git a/src/components/library/LibraryEditor.jsx b/conda/js/src/components/library/LibraryEditor.jsx similarity index 100% rename from src/components/library/LibraryEditor.jsx rename to conda/js/src/components/library/LibraryEditor.jsx diff --git a/src/components/library/LibraryEditor.spec.jsx b/conda/js/src/components/library/LibraryEditor.spec.jsx similarity index 100% rename from src/components/library/LibraryEditor.spec.jsx rename to conda/js/src/components/library/LibraryEditor.spec.jsx diff --git a/src/components/library/index.js b/conda/js/src/components/library/index.js similarity index 100% rename from src/components/library/index.js rename to conda/js/src/components/library/index.js diff --git a/src/components/plotter/PlotterEditor.jsx b/conda/js/src/components/plotter/PlotterEditor.jsx similarity index 100% rename from src/components/plotter/PlotterEditor.jsx rename to conda/js/src/components/plotter/PlotterEditor.jsx diff --git a/conda/js/src/components/plotter/PlotterEditor.spec.jsx b/conda/js/src/components/plotter/PlotterEditor.spec.jsx new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/components/plotter/index.js b/conda/js/src/components/plotter/index.js similarity index 100% rename from src/components/plotter/index.js rename to conda/js/src/components/plotter/index.js diff --git a/src/components/plotterparameter/PlotterParameterEditor.jsx b/conda/js/src/components/plotterparameter/PlotterParameterEditor.jsx similarity index 100% rename from src/components/plotterparameter/PlotterParameterEditor.jsx rename to conda/js/src/components/plotterparameter/PlotterParameterEditor.jsx diff --git a/conda/js/src/components/plotterparameter/PlotterParameterEditor.spec.jsx b/conda/js/src/components/plotterparameter/PlotterParameterEditor.spec.jsx new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/components/plotterparameter/index.js b/conda/js/src/components/plotterparameter/index.js similarity index 100% rename from src/components/plotterparameter/index.js rename to conda/js/src/components/plotterparameter/index.js diff --git a/src/components/toolchain/GraphicalEditor.css b/conda/js/src/components/toolchain/GraphicalEditor.css similarity index 100% rename from src/components/toolchain/GraphicalEditor.css rename to conda/js/src/components/toolchain/GraphicalEditor.css diff --git a/src/components/toolchain/GraphicalEditor.jsx b/conda/js/src/components/toolchain/GraphicalEditor.jsx similarity index 100% rename from src/components/toolchain/GraphicalEditor.jsx rename to conda/js/src/components/toolchain/GraphicalEditor.jsx diff --git a/src/components/toolchain/GraphicalEditorHelpModal.jsx b/conda/js/src/components/toolchain/GraphicalEditorHelpModal.jsx similarity index 100% rename from src/components/toolchain/GraphicalEditorHelpModal.jsx rename to conda/js/src/components/toolchain/GraphicalEditorHelpModal.jsx diff --git a/src/components/toolchain/InsertObjectModal.jsx b/conda/js/src/components/toolchain/InsertObjectModal.jsx similarity index 100% rename from src/components/toolchain/InsertObjectModal.jsx rename to conda/js/src/components/toolchain/InsertObjectModal.jsx diff --git a/src/components/toolchain/RenameGroupModal.jsx b/conda/js/src/components/toolchain/RenameGroupModal.jsx similarity index 100% rename from src/components/toolchain/RenameGroupModal.jsx rename to conda/js/src/components/toolchain/RenameGroupModal.jsx diff --git a/src/components/toolchain/ToolchainBlock.jsx b/conda/js/src/components/toolchain/ToolchainBlock.jsx similarity index 100% rename from src/components/toolchain/ToolchainBlock.jsx rename to conda/js/src/components/toolchain/ToolchainBlock.jsx diff --git a/src/components/toolchain/ToolchainConnection.jsx b/conda/js/src/components/toolchain/ToolchainConnection.jsx similarity index 100% rename from src/components/toolchain/ToolchainConnection.jsx rename to conda/js/src/components/toolchain/ToolchainConnection.jsx diff --git a/src/components/toolchain/ToolchainConnection.spec.jsx b/conda/js/src/components/toolchain/ToolchainConnection.spec.jsx similarity index 100% rename from src/components/toolchain/ToolchainConnection.spec.jsx rename to conda/js/src/components/toolchain/ToolchainConnection.spec.jsx diff --git a/src/components/toolchain/ToolchainEditor.css b/conda/js/src/components/toolchain/ToolchainEditor.css similarity index 100% rename from src/components/toolchain/ToolchainEditor.css rename to conda/js/src/components/toolchain/ToolchainEditor.css diff --git a/src/components/toolchain/ToolchainEditor.jsx b/conda/js/src/components/toolchain/ToolchainEditor.jsx similarity index 100% rename from src/components/toolchain/ToolchainEditor.jsx rename to conda/js/src/components/toolchain/ToolchainEditor.jsx diff --git a/src/components/toolchain/ToolchainEditor.spec.jsx b/conda/js/src/components/toolchain/ToolchainEditor.spec.jsx similarity index 100% rename from src/components/toolchain/ToolchainEditor.spec.jsx rename to conda/js/src/components/toolchain/ToolchainEditor.spec.jsx diff --git a/src/components/toolchain/ToolchainModal.jsx b/conda/js/src/components/toolchain/ToolchainModal.jsx similarity index 100% rename from src/components/toolchain/ToolchainModal.jsx rename to conda/js/src/components/toolchain/ToolchainModal.jsx diff --git a/src/components/toolchain/index.js b/conda/js/src/components/toolchain/index.js similarity index 100% rename from src/components/toolchain/index.js rename to conda/js/src/components/toolchain/index.js diff --git a/src/components/toolchain/types.js b/conda/js/src/components/toolchain/types.js similarity index 100% rename from src/components/toolchain/types.js rename to conda/js/src/components/toolchain/types.js diff --git a/src/helpers/api.js b/conda/js/src/helpers/api.js similarity index 100% rename from src/helpers/api.js rename to conda/js/src/helpers/api.js diff --git a/src/helpers/beat.js b/conda/js/src/helpers/beat.js similarity index 100% rename from src/helpers/beat.js rename to conda/js/src/helpers/beat.js diff --git a/src/helpers/index.js b/conda/js/src/helpers/index.js similarity index 100% rename from src/helpers/index.js rename to conda/js/src/helpers/index.js diff --git a/src/helpers/schema/algorithm.json b/conda/js/src/helpers/schema/algorithm.json similarity index 100% rename from src/helpers/schema/algorithm.json rename to conda/js/src/helpers/schema/algorithm.json diff --git a/src/helpers/schema/common.json b/conda/js/src/helpers/schema/common.json similarity index 100% rename from src/helpers/schema/common.json rename to conda/js/src/helpers/schema/common.json diff --git a/src/helpers/schema/database.json b/conda/js/src/helpers/schema/database.json similarity index 100% rename from src/helpers/schema/database.json rename to conda/js/src/helpers/schema/database.json diff --git a/src/helpers/schema/dataformat.json b/conda/js/src/helpers/schema/dataformat.json similarity index 100% rename from src/helpers/schema/dataformat.json rename to conda/js/src/helpers/schema/dataformat.json diff --git a/src/helpers/schema/execution.json b/conda/js/src/helpers/schema/execution.json similarity index 100% rename from src/helpers/schema/execution.json rename to conda/js/src/helpers/schema/execution.json diff --git a/src/helpers/schema/experiment.json b/conda/js/src/helpers/schema/experiment.json similarity index 100% rename from src/helpers/schema/experiment.json rename to conda/js/src/helpers/schema/experiment.json diff --git a/src/helpers/schema/index.js b/conda/js/src/helpers/schema/index.js similarity index 100% rename from src/helpers/schema/index.js rename to conda/js/src/helpers/schema/index.js diff --git a/src/helpers/schema/library.json b/conda/js/src/helpers/schema/library.json similarity index 100% rename from src/helpers/schema/library.json rename to conda/js/src/helpers/schema/library.json diff --git a/src/helpers/schema/plotter.json b/conda/js/src/helpers/schema/plotter.json similarity index 100% rename from src/helpers/schema/plotter.json rename to conda/js/src/helpers/schema/plotter.json diff --git a/src/helpers/schema/plotterparameter.json b/conda/js/src/helpers/schema/plotterparameter.json similarity index 100% rename from src/helpers/schema/plotterparameter.json rename to conda/js/src/helpers/schema/plotterparameter.json diff --git a/src/helpers/schema/toolchain.json b/conda/js/src/helpers/schema/toolchain.json similarity index 100% rename from src/helpers/schema/toolchain.json rename to conda/js/src/helpers/schema/toolchain.json diff --git a/src/helpers/search.worker.js b/conda/js/src/helpers/search.worker.js similarity index 100% rename from src/helpers/search.worker.js rename to conda/js/src/helpers/search.worker.js diff --git a/src/store/actionTypes.js b/conda/js/src/store/actionTypes.js similarity index 100% rename from src/store/actionTypes.js rename to conda/js/src/store/actionTypes.js diff --git a/src/store/actions.js b/conda/js/src/store/actions.js similarity index 96% rename from src/store/actions.js rename to conda/js/src/store/actions.js index fc0ffe741262c5132ea4cf9d4a579d81003bfd59..8d6b94d0a5fa144cbcca4d8ada2f081fa4b1b46c 100644 --- a/src/store/actions.js +++ b/conda/js/src/store/actions.js @@ -24,13 +24,11 @@ export type ActionThunkCreator = (any) => (dispatch: Dispatch<*>) => Promise<*>; export const fetchAllObjects: ActionThunkCreator = () => async (dispatch: Dispatch<*>) => { //console.log(`fetchAllObjects`); - const getFuncs = [...BEAT_ENTITIES, 'settings', 'environments'].map(e => genModuleApiFuncs(e).get); + const getFuncs = [...BEAT_ENTITIES].map(e => genModuleApiFuncs(e).get); const jsons = await Promise.all(getFuncs.map(async (get): Promise<*> => get())); - const arrs = jsons.map((j, i, js) => i >= js.length - 2 ? j : objToArr(j)); + const arrs = jsons.map((j, i, js) => objToArr(j)); - console.log(environmentsSave(arrs[9])); - dispatch(environmentsSave(arrs[9])); - dispatch(settingsSave(arrs[8])); + //dispatch(settingsSave(arrs[8])); dispatch(databaseSave(arrs[0])); dispatch(librarySave(arrs[1])); @@ -41,6 +39,10 @@ export const fetchAllObjects: ActionThunkCreator = () => async (dispatch: Dispat dispatch(plotterSave(arrs[6])); dispatch(plotterparameterSave(arrs[7])); dispatch(clearUnsaved()); + + const envGet = genModuleApiFuncs('environments').get; + const envJson = await envGet(); + dispatch(environmentsSave(envJson)); }; export const deleteObject = (entity: BeatEntity, obj: BeatObject): ActionThunkCreator => () => async (dispatch: Dispatch<*>) => { diff --git a/src/store/index.js b/conda/js/src/store/index.js similarity index 100% rename from src/store/index.js rename to conda/js/src/store/index.js diff --git a/src/store/reducers.js b/conda/js/src/store/reducers.js similarity index 99% rename from src/store/reducers.js rename to conda/js/src/store/reducers.js index 1ea97ca3b4900d9d4107a22ab7949854f8decc3f..a60ba5da808f1bdb62706b10eea555bf1ed7f77a 100644 --- a/src/store/reducers.js +++ b/conda/js/src/store/reducers.js @@ -96,9 +96,7 @@ const environments = (state: BeatEnvironment[] = [], action: Action) => { const {type, payload} = action; switch(type){ case 'SAVE_ENVIRONMENTS': - return [ - ...payload, - ]; + return payload; default: throw new Error(`Invalid actionType "${ type }"`); } diff --git a/src/store/selectors.js b/conda/js/src/store/selectors.js similarity index 100% rename from src/store/selectors.js rename to conda/js/src/store/selectors.js diff --git a/test/index.js b/conda/js/test/index.js similarity index 100% rename from test/index.js rename to conda/js/test/index.js diff --git a/test/test_algs.json b/conda/js/test/test_algs.json similarity index 100% rename from test/test_algs.json rename to conda/js/test/test_algs.json diff --git a/test/test_dbs.json b/conda/js/test/test_dbs.json similarity index 100% rename from test/test_dbs.json rename to conda/js/test/test_dbs.json diff --git a/test/test_dfs.json b/conda/js/test/test_dfs.json similarity index 100% rename from test/test_dfs.json rename to conda/js/test/test_dfs.json diff --git a/test/test_exps.json b/conda/js/test/test_exps.json similarity index 100% rename from test/test_exps.json rename to conda/js/test/test_exps.json diff --git a/test/test_libs.json b/conda/js/test/test_libs.json similarity index 100% rename from test/test_libs.json rename to conda/js/test/test_libs.json diff --git a/test/test_tcs.json b/conda/js/test/test_tcs.json similarity index 100% rename from test/test_tcs.json rename to conda/js/test/test_tcs.json diff --git a/webpack.config.js b/conda/js/webpack.config.js similarity index 98% rename from webpack.config.js rename to conda/js/webpack.config.js index 9dd4f3fcca2aa195d8aad33d20e433793fefd4c3..d7d26749660290a77dc91a531c992907dac2a524 100644 --- a/webpack.config.js +++ b/conda/js/webpack.config.js @@ -5,7 +5,7 @@ const VisualizerPlugin = require('webpack-visualizer-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const UglifyJsPlugin = require('uglifyjs-webpack-plugin') -const dist = resolve(__dirname, 'dist'); +const dist = resolve(__dirname, '../../beat/editor/js'); const isExternal = (module) => module.context && module.context.indexOf('node_modules') === -1; diff --git a/conda/meta.yaml b/conda/meta.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5819e08e44525065812569ae20f54426ac2ecf8e --- /dev/null +++ b/conda/meta.yaml @@ -0,0 +1,75 @@ +{% set name = 'beat.editor' %} +{% set project_dir = environ.get('RECIPE_DIR') + '/..' %} + +package: + name: {{ name }} + version: {{ environ.get('BOB_PACKAGE_VERSION', '0.0.1') }} + +build: + entry_points: + - beateditor = beat.editor.scripts.server:main + number: {{ environ.get('BOB_BUILD_NUMBER', 0) }} + run_exports: + - {{ pin_subpackage(name) }} + script: + - cd {{ project_dir }} + {% if environ.get('BUILD_EGG') %} + - python setup.py sdist --formats=zip + {% endif %} + - python setup.py install --single-version-externally-managed --record record.txt + - cd {{ environ.get('RECIPE_DIR') }}/js + - npm install + - npm run build + +requirements: + host: + - python {{ python }} + - setuptools {{ setuptools }} + - nodejs {{ nodejs }} + run: + - python + - setuptools + - simplejson + - jinja2 + - flask + - flask-cors + - flask-restful + - docopt + - beat.cmdline + +test: + files: + - js + + requires: + - bob-devel {{ bob_devel }}.* + - beat-devel {{ beat_devel }}.* + - bob.extension + - nose + - coverage + - sphinx + - sphinx_rtd_theme + - nodejs + + imports: + - {{ name }} + + commands: + - beateditor --help + - nosetests --with-coverage --cover-package={{ name }} -sv {{ name }} + - sphinx-build -aEW {{ project_dir }}/doc {{ project_dir }}/sphinx + - sphinx-build -aEb doctest {{ project_dir }}/doc sphinx + - conda inspect linkages -p $PREFIX {{ name }} # [not win] + - conda inspect objects -p $PREFIX {{ name }} # [osx] + {% if environ.get('BEAT_BROWSER_TESTS', False) %} + - cd {{ project_dir }}/conda/js + - npm install + - npm test + - cd - + {% endif %} + +about: + home: https://www.idiap.ch/software/beat/ + license: AGPLv3 + summary: Local editor for BEAT objects + license_family: AGPL diff --git a/DEV.md b/doc/DEV.md similarity index 100% rename from DEV.md rename to doc/DEV.md diff --git a/README.md b/doc/README.md similarity index 100% rename from README.md rename to doc/README.md diff --git a/doc/api.rst b/doc/api.rst new file mode 100644 index 0000000000000000000000000000000000000000..a50286509648a23ed5674b729f5fc9cef2046bad --- /dev/null +++ b/doc/api.rst @@ -0,0 +1,10 @@ + +===== + API +===== + +This section includes information for using the Python API of +``beat.editor``. + +.. automodule:: beat.editor + diff --git a/doc/conf.py b/doc/conf.py new file mode 100644 index 0000000000000000000000000000000000000000..b2edea372e39c0b386861ef5b5f143d18b21ea2f --- /dev/null +++ b/doc/conf.py @@ -0,0 +1,265 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : + +import os +import sys +import glob +import pkg_resources + + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +needs_sphinx = '1.3' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = [ + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.ifconfig', + 'sphinx.ext.autodoc', + 'sphinx.ext.autosummary', + 'sphinx.ext.doctest', + 'sphinx.ext.graphviz', + 'sphinx.ext.intersphinx', + 'sphinx.ext.napoleon', + 'sphinx.ext.viewcode', + 'sphinx.ext.mathjax', + #'matplotlib.sphinxext.plot_directive' + ] + +# Be picky about warnings +nitpicky = True + +# Ignores stuff we can't easily resolve on other project's sphinx manuals +nitpick_ignore = [] + +# Allows the user to override warnings from a separate file +if os.path.exists('nitpick-exceptions.txt'): + for line in open('nitpick-exceptions.txt'): + if line.strip() == "" or line.startswith("#"): + continue + dtype, target = line.split(None, 1) + target = target.strip() + try: # python 2.x + target = unicode(target) + except NameError: + pass + nitpick_ignore.append((dtype, target)) + +# Always includes todos +todo_include_todos = True + +# Generates auto-summary automatically +autosummary_generate = True + +# Create numbers on figures with captions +numfig = True + +# If we are on OSX, the 'dvipng' path maybe different +dvipng_osx = '/opt/local/libexec/texlive/binaries/dvipng' +if os.path.exists(dvipng_osx): pngmath_dvipng = dvipng_osx + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'beat.backend.python' +import time +copyright = u'%s, Idiap Research Institute' % time.strftime('%Y') + +# Grab the setup entry +distribution = pkg_resources.require(project)[0] + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = distribution.version +# The full version, including alpha/beta/rc tags. +release = distribution.version + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['links.rst'] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# Some variables which are useful for generated material +project_variable = project.replace('.', '_') +short_description = u'Biometrics Evaluation and Testing Platform (Python backend)' +owner = [u'Idiap Research Institute'] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +import sphinx_rtd_theme +html_theme = 'sphinx_rtd_theme' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] + +# The name for this set of Sphinx documents. If None, it defaults to +# "<project> v<release> documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = project_variable + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +html_logo = 'img/logo.png' + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +html_favicon = 'img/favicon.ico' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +#html_static_path = ['_static'] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a <link> tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = project_variable + u'_doc' + + +# -- Post configuration -------------------------------------------------------- + +# Included after all input documents +rst_epilog = """ +.. |project| replace:: BEAT +.. |version| replace:: %s +.. |current-year| date:: %%Y +""" % (version,) + +# Default processing flags for sphinx +autoclass_content = 'class' +autodoc_member_order = 'bysource' +autodoc_default_flags = [ + 'members', + 'undoc-members', + 'show-inheritance', + ] + +# For inter-documentation mapping: +from bob.extension.utils import link_documentation, load_requirements +sphinx_requirements = "extra-intersphinx.txt" +if os.path.exists(sphinx_requirements): + intersphinx_mapping = link_documentation( + additional_packages=['python','numpy'] + \ + load_requirements(sphinx_requirements) + ) +else: + intersphinx_mapping = link_documentation() + +# Adds simplejson, pyzmq links +intersphinx_mapping['http://simplejson.readthedocs.io/en/stable/'] = None +intersphinx_mapping['http://pyzmq.readthedocs.io/en/stable/'] = None + +# We want to remove all private (i.e. _. or __.__) members +# that are not in the list of accepted functions +accepted_private_functions = ['__array__'] + +def member_function_test(app, what, name, obj, skip, options): + # test if we have a private function + if len(name) > 1 and name[0] == '_': + # test if this private function should be allowed + if name not in accepted_private_functions: + # omit privat functions that are not in the list of accepted private functions + return skip + else: + # test if the method is documented + if not hasattr(obj, '__doc__') or not obj.__doc__: + return skip + return False + +def setup(app): + app.connect('autodoc-skip-member', member_function_test) diff --git a/doc/img/favicon.ico b/doc/img/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..acbc0d0056cc417e7e8b71c3aac7231df78e46b7 Binary files /dev/null and b/doc/img/favicon.ico differ diff --git a/doc/img/logo.png b/doc/img/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..180021b7d25cf7bee47a4c38039562462265c8ab Binary files /dev/null and b/doc/img/logo.png differ diff --git a/doc/index.rst b/doc/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..8688cbc83824b47c0303da89e80a35ec070bd672 --- /dev/null +++ b/doc/index.rst @@ -0,0 +1,43 @@ +.. vim: set fileencoding=utf-8 : + +.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ .. +.. Contact: beat.support@idiap.ch .. +.. .. +.. This file is part of the beat.editor module of the BEAT platform. .. +.. .. +.. Commercial License Usage .. +.. Licensees holding valid commercial BEAT licenses may use this file in .. +.. accordance with the terms contained in a written agreement between you .. +.. and Idiap. For further information contact tto@idiap.ch .. +.. .. +.. Alternatively, this file may be used under the terms of the GNU Affero .. +.. Public License version 3 as published by the Free Software and appearing .. +.. in the file LICENSE.AGPL included in the packaging of this file. .. +.. The BEAT platform is distributed in the hope that it will be useful, but .. +.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY .. +.. or FITNESS FOR A PARTICULAR PURPOSE. .. +.. .. +.. You should have received a copy of the GNU Affero Public License along .. +.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. .. + + +=============================== + Local editor for BEAT objects +=============================== + +.. todo:: + + Write user guide + + +.. toctree:: + + api + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/licenses.md b/doc/licenses.md similarity index 100% rename from licenses.md rename to doc/licenses.md diff --git a/doc/nitpick-exceptions.txt b/doc/nitpick-exceptions.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f250370611ddaaad6e3a98a76bea55d95193ebd --- /dev/null +++ b/doc/nitpick-exceptions.txt @@ -0,0 +1,10 @@ +# Not available in Python 2.7, but ok in Python 3.x +py:exc TypeError +py:exc RuntimeError +py:exc ValueError +py:exc KeyError +py:class tuple +py:class list + +# Issue on the simplejson documentation +py:class simplejson.encoder.JSONEncoder diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..7881ec20d3591f76b89e7fd88711169ac353f28a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +setuptools +simplejson +jinja2 +flask +flask-cors +flask-restful +docopt +beat.cmdline diff --git a/server.py b/server.py deleted file mode 100644 index e79cf9156b187e1ace0b8161e6fd8fcb1d9f7776..0000000000000000000000000000000000000000 --- a/server.py +++ /dev/null @@ -1,457 +0,0 @@ -""" -A simple Flask server providing an API for the local BEAT prefix and user configuration. -Dependencies: - simplejson - flask - flask_restful - flask_cors -""" -import os -import glob -from shutil import copy as copy_file -import subprocess -import json -from enum import Enum -import simplejson -from flask import Flask, request -from flask_restful import Resource, Api -from flask_cors import CORS -import templates - -app = Flask(__name__) -api = Api(app) -CORS(app) - -def get_user_conf(): - """Reads & returns the user configuration in a dict""" - user_conf = {} - if os.path.isfile('./user_conf.json'): - with open('./user_conf.json') as f: - try: - user_conf = json.load(f) - except json.JSONDecodeError: - print('user_conf.json is invalid!') - raise SystemExit - else: - with open('./user_conf.json', 'w') as f: - user_conf = { - 'prefix': '~' - } - json.dump(user_conf, f) - - - if 'prefix' not in user_conf: - raise Exception('Invalid user_conf: Needs "prefix" key!') - return user_conf - -def get_prefix(): - """Returns an absolute path to the user-defined BEAT prefix location""" - return os.path.expanduser(get_user_conf()['prefix']) - -def get_tc_layout(tc_name): - """Returns the JSON returned by Graphviz's dot "-Tjson0" output for the given toolchain""" - prefix = get_prefix() - beat_ex_loc = '%s/bin/beat' % prefix - tc_dot_loc = '%s/toolchains/%s.dot' % (prefix, tc_name) - if not os.path.isfile(beat_ex_loc): - raise Exception('BEAT executable not at %s' % beat_ex_loc) - beat_cmd = 'cd %s && ./bin/beat tc draw %s' % (prefix, tc_name) - output = subprocess.call(beat_cmd, shell=True) - if not os.path.isfile(tc_dot_loc): - print('Running command "%s" got:' % beat_cmd) - print(output) - raise Exception('"%s" graphviz dot file not found at "%s"' % (tc_name, tc_dot_loc)) - - s = subprocess.check_output('dot %s -Tjson0' % tc_dot_loc, shell=True, encoding='utf-8') - - return s - -def get_environment_info(): - json = simplejson.loads(''' - [ - { - "name": "Scientific Python 2.7", - "packages": { - "alabaster": "0.7.6", - "babel": "1.3" - }, - "queues": { - "Default": { - "memory_limit": 5983, - "nb_slots": 2, - "max_slots_per_user": 2, - "nb_cores_per_slot": 1, - "time_limit": 360 - } - }, - "accessibility": "public", - "languages": [ - "python" - ], - "version": "0.0.4", - "short_description": "Scientific Python 2.7" - }, - { - "name": "Scientific Python 2.7", - "packages": { - "alabaster": "0.7.10", - "Babel": "2.4.0" - }, - "queues": { - "Default": { - "memory_limit": 5983, - "nb_slots": 2, - "max_slots_per_user": 2, - "nb_cores_per_slot": 1, - "time_limit": 360 - } - }, - "accessibility": "public", - "languages": [ - "python" - ], - "version": "1.0.0", - "short_description": "Scientific Python 2.7" - } - ] - ''') - - return json - - -class BeatEntity(Enum): - """List of BEAT entities to serve to the webapp""" - DATAFORMAT = 'dataformats' - DATABASE = 'databases' - LIBRARY = 'libraries' - ALGORITHM = 'algorithms' - TOOLCHAIN = 'toolchains' - EXPERIMENT = 'experiments' - PLOTTER = 'plotters' - PLOTTERPARAMETER = 'plotterparameters' - - -def read_json(path): - """Reads a JSON file and returns the parse JSON obj""" - with open(path, 'r') as f: - data = json.load(f) - return data - - -def path_to_dict(path): - """Generates a dict of the given file/folder in the BEAT prefix""" - d = { - 'name': os.path.basename(path) - } - if os.path.isdir(path): - d['type'] = "directory" - d['children'] = [path_to_dict(os.path.join(path, x)) - for x in os.listdir(path)] - elif os.path.isfile(path): - d['type'] = "file" - fname, fext = os.path.splitext(path) - if fext == '.json': - d['json'] = read_json(path) - return d - - -def generate_file_tree(be): - """Generates a file tree (of dicts) given a specific BEAT entity""" - resource_path = os.path.join(get_prefix(), be.value) - if not os.path.isdir(resource_path): - raise NotADirectoryError('Invalid resource path %s' % resource_path) - - #print('generating entity tree for path %s' % resource_path) - return path_to_dict(resource_path) - - -def generate_json_entity(fto, parent_names): - """Generates info for a file in the BEAT path""" - if fto['type'] != 'file': - raise Exception('bad file tree obj') - - fname, fext = os.path.splitext(fto['name']) - - name_str = '' - for name in parent_names: - name_str += name + '/' - - name_str += fname - - return { - 'name': name_str, - 'contents': fto['json'] - } - - -def generate_entity_tree(be): - """Generates the entire tree for an entity type from the prefix""" - file_tree = generate_file_tree(be) - entity_tree = {} - user_and_name = [ - BeatEntity.DATAFORMAT, - BeatEntity.LIBRARY, - BeatEntity.ALGORITHM, - BeatEntity.TOOLCHAIN, - BeatEntity.PLOTTER, - BeatEntity.PLOTTERPARAMETER, - ] - - if be in user_and_name: - for user in file_tree['children']: - entity_tree[user['name']] = {} - for obj in user['children']: - entity_tree[user['name']][obj['name']] = list() - for f in obj['children']: - fname, fext = os.path.splitext(f['name']) - if fext != '.json': - continue - parent_names = [user['name'], obj['name']] - json_obj = generate_json_entity(f, parent_names) - entity_tree[user['name']][obj['name']].append(json_obj) - - elif be == BeatEntity.DATABASE: - for obj in file_tree['children']: - entity_tree[obj['name']] = list() - for f in obj['children']: - fname, fext = os.path.splitext(f['name']) - if fext != '.json': - continue - parent_names = [obj['name']] - json_obj = generate_json_entity(f, parent_names) - entity_tree[obj['name']].append(json_obj) - - elif be == BeatEntity.EXPERIMENT: - for user in file_tree['children']: - uname = user['name'] - entity_tree[uname] = {} - for tc_user in user['children']: - tcuname = tc_user['name'] - entity_tree[uname][tcuname] = {} - for tc_name in tc_user['children']: - tcname = tc_name['name'] - entity_tree[uname][tcuname][tcname] = {} - for tc_version in tc_name['children']: - tcv = tc_version['name'] - entity_tree[uname][tcuname][tcname][tcv] = list() - for exp_name in tc_version['children']: - fname, fext = os.path.splitext(exp_name['name']) - if fext != '.json': - continue - parent_names = [uname, tcuname, tcname, tcv] - json_obj = generate_json_entity( - exp_name, parent_names) - entity_tree[uname][tcuname][tcname][tcv].append( - json_obj) - - return entity_tree - - -def generate_python_template(be, name, **kwargs): - """Generates a template for a certain beat entity type with the given named arguments""" - template_func = None - if be == BeatEntity.DATABASE: - template_func = templates.generate_database - elif be == BeatEntity.LIBRARY: - template_func = templates.generate_library - elif be == BeatEntity.ALGORITHM: - template_func = templates.generate_algorithm - else: - raise TypeError('Cannot create template for beat entity type "%s"' % be.value) - - - s = template_func(**kwargs) - - resource_path = os.path.join(get_prefix(), be.value) - file_path = os.path.join(resource_path, name) + '.py' - with open(file_path, 'w') as f: - f.write(s) - return s - - -class WriteMode(Enum): - """Write modes for requests from the web app""" - CREATE = 0 - UPDATE = 1 - DELETE = 2 - - -def write_json(be, obj, mode, copy_obj_name='', **kwargs): - """writes JSON from a webapp request to the prefix using the specified mode""" - resource_path = os.path.join(get_prefix(), be.value) - name = obj['name'] - name_segs = name.split('/') - contents = obj['contents'] - stringified = simplejson.dumps(contents, indent=4, sort_keys=True) - - folder_path = os.path.join(resource_path, '/'.join(name_segs[:-1])) - file_subpath = os.path.join(resource_path, name) - file_path = file_subpath + '.json' - - if mode == WriteMode.UPDATE: - os.makedirs(folder_path, exist_ok=True) - with open(file_path, 'w') as f: - f.write(stringified) - elif mode == WriteMode.CREATE: - if not os.path.isfile(file_path): - os.makedirs(folder_path, exist_ok=True) - if copy_obj_name != '': - copy_obj_path = os.path.join(resource_path, copy_obj_name) - if os.path.isfile(copy_obj_path + '.json'): - files_to_copy = glob.glob('%s.*' % copy_obj_path) - copy_locations = ['%s%s' % (file_subpath, os.path.splitext(f)[1]) for f in files_to_copy] - for i in range(0, len(files_to_copy)): - if files_to_copy[i].endswith('.json'): continue - copy_file(files_to_copy[i], copy_locations[i]) - with open(file_path, 'w') as f: - f.write(stringified) - elif mode == WriteMode.DELETE: - if os.path.isfile(file_path): - files_to_delete = glob.glob('%s.*' % file_subpath) - for f in files_to_delete: - os.remove(f) - # taken from https://stackoverflow.com/a/23488980 - - def remove_empty_dirs(path): - """Remove directories now made empty by deleting an object from the prefix""" - for root, dirnames, filenames in os.walk(path, topdown=False): - for dirname in dirnames: - remove_empty_dirs( - os.path.realpath( - os.path.join(root, dirname) - ) - ) - if not os.listdir(path): - os.rmdir(path) - - remove_empty_dirs(folder_path) - else: - raise TypeError('Invalid WriteMode %s' % mode) - - -class Home(Resource): - """The base resource path with subroutes""" - def get(self): - """Returns the available sub-routes""" - return { - 'routes': [ - 'databases', - 'dataformats', - 'libraries', - 'algorithms', - 'toolchains', - 'experiments', - 'plotters', - 'plotterparameters', - 'settings', - 'layout', - 'environments', - ] - } - -class Layout(Resource): - """Exposes toolchain layout functionality""" - - def post(self): - data = request.get_json() - if data != None and 'toolchain' in data: - return get_tc_layout(data['toolchain']) - else: - print(data) - raise Exception('Invalid post content for tc layout!') - -class Environments(Resource): - """Exposes local environment info""" - - def get(self): - return get_environment_info() - -class Settings(Resource): - """Exposes user settings""" - - def get(self): - """Returns the settings""" - return get_user_conf() - - def put(self): - """Overwrites the settings""" - new_conf = request.get_json() - with open('./user_conf.json', 'w') as f: - try: - json.dump(new_conf, f) - except json.JSONDecodeError: - print('Invalid new_conf %s' % new_conf) - raise SystemExit - return get_user_conf() - - -class Templates(Resource): - """Endpoint for generating template files""" - def post(self): - data = request.get_json() - entity = BeatEntity(data.pop('entity')) - name = data.pop('name') - generate_python_template(entity, name, **data) - -def gen_beat_endpoint(entity): - """Generates an endpoint for the given BEAT entity, exposing actions to perform on the prefix""" - class BeatEndpoint(Resource): - """A class representing the template for an endpoint for a BEAT entity""" - be = entity - - def refresh(self): - """Regenerates the entity tree""" - try: - return generate_entity_tree(self.be) - except NotADirectoryError: - return {} - - def get(self): - """Returns the entity tree""" - return self.refresh() - - def post(self): - """Creates a new object""" - obj_list = request.get_json() - if not isinstance(obj_list, list): - obj_list = [obj_list] - for o in obj_list: - # two fields: - # - "obj" field (the object to create) - # - "copyObjName" field (the object that was copied, blank if not copied) - obj = o['obj'] - copy_obj_name = o['copiedObjName'] - write_json(self.be, obj, WriteMode.CREATE, copy_obj_name) - return self.refresh() - - def put(self): - """Updates an already-existing object""" - obj_list = request.get_json() - if not isinstance(obj_list, list): - obj_list = [obj_list] - for obj in obj_list: - write_json(self.be, obj, WriteMode.UPDATE) - return self.refresh() - - def delete(self): - """Deletes an object""" - obj = request.get_json() - write_json(self.be, obj, WriteMode.DELETE) - return self.refresh() - - BeatEndpoint.__name__ = entity.value - - return BeatEndpoint - - -api.add_resource(Home, '/') -api.add_resource(Settings, '/settings') -api.add_resource(Layout, '/layout') -api.add_resource(Templates, '/templates') -api.add_resource(Environments, '/environments') -for entity in BeatEntity: - val = entity.value - api.add_resource(gen_beat_endpoint(entity), '/' + val) - -if __name__ == '__main__': - app.run(debug=True) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..3b9ccffd1f26ce5e0f4347ec04738fc064a2c96d --- /dev/null +++ b/setup.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python +# vim: set fileencoding=utf-8 : + +############################################################################### +# # +# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ # +# Contact: beat.support@idiap.ch # +# # +# This file is part of the beat.editor module of the BEAT platform. # +# # +# Commercial License Usage # +# Licensees holding valid commercial BEAT licenses may use this file in # +# accordance with the terms contained in a written agreement between you # +# and Idiap. For further information contact tto@idiap.ch # +# # +# Alternatively, this file may be used under the terms of the GNU Affero # +# Public License version 3 as published by the Free Software and appearing # +# in the file LICENSE.AGPL included in the packaging of this file. # +# The BEAT platform is distributed in the hope that it will be useful, but # +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # +# or FITNESS FOR A PARTICULAR PURPOSE. # +# # +# You should have received a copy of the GNU Affero Public License along # +# with the BEAT platform. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + + +from setuptools import setup, find_packages + +def load_requirements(f): + retval = [str(k.strip()) for k in open(f, 'rt')] + return [k for k in retval if k and k[0] not in ('#', '-')] + +# The only thing we do in this file is to call the setup() function with all +# parameters that define our package. +setup( + + name='beat.editor', + version=open("version.txt").read().rstrip(), + description='Local editor for BEAT objects', + url='https://gitlab.idiap.ch/beat/beat.editor', + license='AGPLv3', + author='Idiap Research Institute', + author_email='beat.support@idiap.ch', + long_description=open('README.rst').read(), + + packages=find_packages(), + include_package_data=True, + zip_safe=False, + install_requires=load_requirements('requirements.txt'), + entry_points={ + 'console_scripts': [ + 'beateditor = beat.editor.scripts.server:main', + ], + }, + + classifiers = [ + 'Framework :: BEAT', + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GNU Affero General Public License v3', + 'Natural Language :: English', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], +) diff --git a/templates.py b/templates.py deleted file mode 100644 index aba5ad2f630ba6ec2f7f91c6c991bf6eab229592..0000000000000000000000000000000000000000 --- a/templates.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Functions for generating templates using Jinja2 template files found in ./templates""" -from jinja2 import Environment, FileSystemLoader -env = Environment(loader=FileSystemLoader('./templates')) - -def generate_database(views=['View']): - """Parameters: - - views : A list of strings that represents the views for the database - """ - template = env.get_template('database.jinja2') - s = template.render(views=views) - return s - -def generate_library(uses={}): - """Parameters: - - uses : A dict of other libraries that the library uses. - Keys are the value to reference the library, values are the library being referenced. - """ - template = env.get_template('library.jinja2') - s = template.render(uses=uses) - return s - -def generate_algorithm(has_parameters=False, uses={}): - """Parameters: - - has_parameters: Whether the algorithm has parameters or not (default: False) - - uses : A dict of libraries that the algorithm uses. - Keys are the value to reference the library, values are the library being referenced. - """ - template = env.get_template('algorithm.jinja2') - s = template.render(uses=uses, has_parameters=has_parameters) - return s diff --git a/version.txt b/version.txt new file mode 100644 index 0000000000000000000000000000000000000000..cdf299159fb0a20cae5dbf62cc74d6c6bb0bc424 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +1.0.0b0