├── .editorconfig ├── .github └── workflows │ └── pythonapp.yml ├── .gitignore ├── .gitlab-ci.yml ├── .prospector.yml ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.rst ├── CONTRIBUTING.rst ├── LICENSE ├── MANIFEST.in ├── NOTICE ├── README.rst ├── ci_for_science ├── __init__.py ├── __version__.py └── ci_for_science.py ├── cpp ├── CMakeLists.txt ├── include │ └── scientific_module.hpp └── scientific_module.cpp ├── project_setup.rst ├── requirements.txt ├── setup.cfg ├── setup.py └── tests ├── __init__.py ├── test_ci_for_science.py └── test_lint.py /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | charset = utf-8 12 | 13 | # 4 space indentation 14 | [*.{py,java,r,R}] 15 | indent_style = space 16 | indent_size = 4 17 | 18 | # 2 space indentation 19 | [*.{js,json,y{a,}ml,html,cwl}] 20 | indent_style = space 21 | indent_size = 2 22 | 23 | [*.{md,Rmd,rst}] 24 | trim_trailing_whitespace = false 25 | indent_style = space 26 | indent_size = 2 27 | -------------------------------------------------------------------------------- /.github/workflows/pythonapp.yml: -------------------------------------------------------------------------------- 1 | name: build with conda 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: Setup conda 13 | uses: s-weigand/setup-conda@v1 14 | with: 15 | update-conda: true 16 | python-version: 3.7 17 | conda-channels: anaconda, conda-forge 18 | - run: conda --version 19 | - run: which python 20 | - run: conda install numpy cython 21 | 22 | - name: Install the package 23 | run: pip install -e . 24 | env: 25 | CONDA_PREFIX: /usr/share/miniconda 26 | 27 | - name: Lint with flake8 28 | env: 29 | CONDA_PREFIX: /usr/share/miniconda 30 | run: | 31 | pip install flake8 32 | # stop the build if there are Python syntax errors or undefined names 33 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 34 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 35 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 36 | 37 | - name: Test with pytest 38 | env: 39 | CONDA_PREFIX: /usr/share/miniconda 40 | run: | 41 | pip install pytest pytest-cov 42 | pytest tests 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | *.egg-info 3 | *.eggs 4 | .ipynb_checkpoints 5 | 6 | build 7 | dist 8 | .cache 9 | __pycache__ 10 | 11 | htmlcov 12 | .coverage 13 | coverage.xml 14 | .pytest_cache 15 | 16 | docs/_build 17 | docs/apidocs 18 | 19 | # ide 20 | .idea 21 | .eclipse 22 | .vscode 23 | 24 | # Mac 25 | .DS_Store 26 | 27 | # emacs 28 | *~ 29 | 30 | # build 31 | bin 32 | build 33 | 34 | # share objects 35 | *.so -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | job build: 2 | image: 3 | "ubuntu:18.04" 4 | variables: 5 | PYTHON_VERSION: "3.7" 6 | script: 7 | - apt-get update && apt-get install -y wget git build-essential 8 | - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh 9 | - bash miniconda.sh -b -p $HOME/miniconda 10 | - export PATH="$HOME/miniconda/bin:$PATH" 11 | - hash -r 12 | - conda config --set always_yes yes --set changeps1 no --set auto_update_conda False 13 | # Useful for debugging any issues with conda 14 | - conda info -a 15 | # Install python env 16 | - conda create --name ci_for_science python=${PYTHON_VERSION} 17 | - source activate ci_for_science 18 | 19 | # Install your conda dependencies 20 | - conda install numpy cython 21 | 22 | # Clone the repo and run the test 23 | - cd $HOME && git clone --branch master --single-branch https://github.com/NLeSC/ci_for_science.git 24 | - cd ci_for_science && pip install -e .[test] 25 | -------------------------------------------------------------------------------- /.prospector.yml: -------------------------------------------------------------------------------- 1 | # prospector configuration file 2 | 3 | --- 4 | 5 | output-format: grouped 6 | 7 | strictness: medium 8 | doc-warnings: false 9 | test-warnings: true 10 | member-warnings: false 11 | 12 | ignore-paths: 13 | - docs 14 | 15 | pyroma: 16 | run: true 17 | 18 | pep8: 19 | full: true 20 | 21 | pep257: 22 | disable: [ 23 | # Disable because not part of PEP257 official convention: 24 | # see http://pep257.readthedocs.io/en/latest/error_codes.html 25 | D203, # 1 blank line required before class docstring 26 | D212, # Multi-line docstring summary should start at the first line 27 | D213, # Multi-line docstring summary should start at the second line 28 | D404, # First word of the docstring should not be This 29 | ] 30 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file for automatic testing at travis-ci.org 2 | dist: xenial 3 | language: generic 4 | 5 | env: 6 | global: 7 | - COMMIT_AUTHOR_EMAIL: "f.zapata@esciencecenter.nl" 8 | matrix: 9 | - PYTHON_VERSION=3.6 10 | - PYTHON_VERSION=3.7 11 | 12 | install: 13 | - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh 14 | - bash miniconda.sh -b -p $HOME/miniconda 15 | - export PATH="$HOME/miniconda/bin:$PATH" 16 | - hash -r 17 | - conda config --set always_yes yes --set changeps1 no --set auto_update_conda False 18 | # Useful for debugging any issues with conda 19 | - conda info -a 20 | 21 | # Install python env 22 | - conda create --name ci_for_science python=${PYTHON_VERSION} 23 | - source activate ci_for_science 24 | 25 | # Install your conda dependencies 26 | - conda install numpy cython 27 | 28 | # Install the package 29 | - pip install -e . 30 | - pip install pytest pytest-cov pycodestyle 31 | 32 | # command to run tests 33 | script: 34 | pytest tests 35 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | # 0.2.0 [25/02/2020] 4 | 5 | # New 6 | * Use [Pybind11](https://github.com/pybind/pybind11) to show minimal C++/Python interface. 7 | * Added a command line interface to receive the number of samples. 8 | * Added a CMake recipe to check the C++ code. 9 | * Added a test for the C++ code. 10 | 11 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.rst: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | Contributor Covenant Code of Conduct 3 | ############################################################################### 4 | 5 | Our Pledge 6 | ********** 7 | 8 | In the interest of fostering an open and welcoming environment, we as 9 | contributors and maintainers pledge to making participation in our project and 10 | our community a harassment-free experience for everyone, regardless of age, body 11 | size, disability, ethnicity, gender identity and expression, level of experience, 12 | education, socio-economic status, nationality, personal appearance, race, 13 | religion, or sexual identity and orientation. 14 | 15 | Our Standards 16 | ************* 17 | 18 | Examples of behavior that contributes to creating a positive environment 19 | include: 20 | 21 | * Using welcoming and inclusive language 22 | * Being respectful of differing viewpoints and experiences 23 | * Gracefully accepting constructive criticism 24 | * Focusing on what is best for the community 25 | * Showing empathy towards other community members 26 | 27 | Examples of unacceptable behavior by participants include: 28 | 29 | * The use of sexualized language or imagery and unwelcome sexual attention or 30 | advances 31 | * Trolling, insulting/derogatory comments, and personal or political attacks 32 | * Public or private harassment 33 | * Publishing others' private information, such as a physical or electronic 34 | address, without explicit permission 35 | * Other conduct which could reasonably be considered inappropriate in a 36 | professional setting 37 | 38 | Our Responsibilities 39 | ******************** 40 | 41 | Project maintainers are responsible for clarifying the standards of acceptable 42 | behavior and are expected to take appropriate and fair corrective action in 43 | response to any instances of unacceptable behavior. 44 | 45 | Project maintainers have the right and responsibility to remove, edit, or 46 | reject comments, commits, code, wiki edits, issues, and other contributions 47 | that are not aligned to this Code of Conduct, or to ban temporarily or 48 | permanently any contributor for other behaviors that they deem inappropriate, 49 | threatening, offensive, or harmful. 50 | 51 | Scope 52 | ***** 53 | 54 | This Code of Conduct applies both within project spaces and in public spaces 55 | when an individual is representing the project or its community. Examples of 56 | representing a project or community include using an official project e-mail 57 | address, posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. Representation of a project may be 59 | further defined and clarified by project maintainers. 60 | 61 | Enforcement 62 | *********** 63 | 64 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 65 | reported by contacting the project team at f.zapata@esciencecenter.nl. All 66 | complaints will be reviewed and investigated and will result in a response that 67 | is deemed necessary and appropriate to the circumstances. The project team is 68 | obligated to maintain confidentiality with regard to the reporter of an incident. 69 | Further details of specific enforcement policies may be posted separately. 70 | 71 | Project maintainers who do not follow or enforce the Code of Conduct in good 72 | faith may face temporary or permanent repercussions as determined by other 73 | members of the project's leadership. 74 | 75 | Attribution 76 | *********** 77 | 78 | This Code of Conduct is adapted from the `Contributor Covenant `_, version 1.4, 79 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 80 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | ############################ 2 | Contributing guidelines 3 | ############################ 4 | 5 | We welcome any kind of contribution to our software, from simple comment or question to a full fledged `pull request `_. Please read and follow our `Code of Conduct `_. 6 | 7 | A contribution can be one of the following cases: 8 | 9 | #. you have a question; 10 | #. you think you may have found a bug (including unexpected behavior); 11 | #. you want to make some kind of change to the code base (e.g. to fix a bug, to add a new feature, to update documentation). 12 | 13 | The sections below outline the steps in each case. 14 | 15 | You have a question 16 | ******************* 17 | 18 | #. use the search functionality `here `__ to see if someone already filed the same issue; 19 | #. if your issue search did not yield any relevant results, make a new issue; 20 | #. apply the "Question" label; apply other labels when relevant. 21 | 22 | You think you may have found a bug 23 | ********************************** 24 | 25 | #. use the search functionality `here `__ to see if someone already filed the same issue; 26 | #. if your issue search did not yield any relevant results, make a new issue, making sure to provide enough information to the rest of the community to understand the cause and context of the problem. Depending on the issue, you may want to include: 27 | - the `SHA hashcode `_ of the commit that is causing your problem; 28 | - some identifying information (name and version number) for dependencies you're using; 29 | - information about the operating system; 30 | #. apply relevant labels to the newly created issue. 31 | 32 | You want to make some kind of change to the code base 33 | ***************************************************** 34 | 35 | #. (**important**) announce your plan to the rest of the community *before you start working*. This announcement should be in the form of a (new) issue; 36 | #. (**important**) wait until some kind of consensus is reached about your idea being a good idea; 37 | #. if needed, fork the repository to your own Github profile and create your own feature branch off of the latest master commit. While working on your feature branch, make sure to stay up to date with the master branch by pulling in changes, possibly from the 'upstream' repository (follow the instructions `here `__ and `here `__); 38 | #. make sure the existing tests still work by running ``python setup.py test``; 39 | #. add your own tests (if necessary); 40 | #. update or expand the documentation; 41 | #. `push `_ your feature branch to (your fork of) the ci_for_science repository on GitHub; 42 | #. create the pull request, e.g. following the instructions `here `__. 43 | 44 | In case you feel like you've made a valuable contribution, but you don't know how to write or run tests for it, or how to generate the documentation: don't let this discourage you from making the pull request; we can help you! Just go ahead and submit the pull request, but keep in mind that you might be asked to append additional commits to your pull request. 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "{}" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2019 Netherlands eScience Center, Vrije Universiteit Amsterdam 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | 205 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.rst 3 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | This product includes ci_for_science, software developed by 2 | . 3 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | .. image:: https://travis-ci.com/NLESC-JCER/ci_for_science.svg?branch=master 2 | :target: https://travis-ci.com/NLESC-JCER/ci_for_science 3 | .. image:: https://github.com/NLESC-JCER/ci_for_science/workflows/build%20with%20conda/badge.svg 4 | :target: https://github.com/NLESC-JCER/ci_for_science/actions 5 | .. image:: https://gitlab.com/nlesc-jcer/ci_for_science/badges/master/pipeline.svg 6 | :target: https://gitlab.com/nlesc-jcer/ci_for_science/badges/master/pipeline.svg 7 | 8 | ################################################################################ 9 | 👩‍🚀 📡 🔬 Continuous Integration for Scientific Applications 10 | ################################################################################ 11 | This repository contains a brief example of Continuous integration for scientific applications, 12 | using miniconda_ and Python3. 13 | 14 | Overview 15 | ******** 16 | `Continuous Integration `_ (**CI**) helps to automate the testing and delivery of scientific software tools. A **CI** is just a workflow that runs automatically 🤖 as a result of a certain action 17 | taken in the source code (e.g. a push, pull-request, etc.). 18 | 19 | This repository contains 3 different configuration files for *Github Actions*, *Travis* and *Gitlab CI*. These configuration files encode the actions to perform with the code on a given architecture, like installing the library from scratch in a Ubuntu machine. 20 | 21 | ########################### 22 | 🛠️ Setting up a CI workflow 23 | ########################### 24 | 25 | |octocat| GitHub actions 26 | ************************ 27 | The *Github actions* configuration can be found at `Python actions file <.github/workflows/pythonapp.yml>`_. There is comprehensive documentation of what `Github actions`_ are and how to use them. 28 | 29 | .. |octocat| raw:: html 30 | 31 | 32 | 33 | |Travis| Travis CI 34 | ****************** 35 | The `Travis configuration file <.travis.yml>`_ contains the configuration to call a **CI** workflow using *Travis*. See `Travis tutorial`_. 36 | 37 | .. |Travis| raw:: html 38 | 39 | 40 | 41 | |gitlab| GitLab CI 42 | ********* 43 | The `GitLabCI configuration file <.gitlab-ci.yml>`_ contains the configuration to call a **CI** workflow using the *Gitlab CI*. A comprehensive documentation is available for the `GitLab CI`_ tool. 44 | 45 | .. |gitlab| raw:: html 46 | 47 | 48 | 49 | Azure pipelines 50 | *************** 51 | If you want to use `Azure pipelines, `_ have a look at `Tania Allard's great tutorial `_. 52 | 53 | ################################## 54 | 🚀 Running on your own infrascture 55 | ################################## 56 | Sometimes you want to have more control over the hardware infrascture, compilers, etc. when performing 57 | continuous integration. *GitHub Actions* and *GitLab CI/CD* allow you to set up your infrascture. 58 | The following links contains a guide to help you run a **CI** workflow on your own infrascture: 59 | 60 | - `GitLab CI/CD self-hosted runner `_ 61 | - `GitHub Actions self-hosted runnner `_ 62 | 63 | 64 | ############################### 65 | 🎮 Running the package examples 66 | ############################### 67 | This package contains a toy example to estimate the value of π using the `Monte Carlo method`_. 68 | To run the Monte Carlo calculator, you will need to have python install. We recommend you 69 | create a `conda virtual environment `_ by following the instructions below, 70 | 71 | 1. Get a copy of `miniconda `_ 72 | 2. Create a new environment by running the following command: 73 | ``conda create --name ci_for_science python=3.7 -y -q`` 74 | 3. Activate the environment: 75 | ``conda activate ci_for_science`` 76 | 77 | Now to install this package, 78 | 79 | 4. `Fork and clone this repo `_ 80 | 5. install cython: 81 | ``pip install cython`` 82 | 6. install the library from the repo root folder: 83 | ``cd ci_for_science && pip install -e .`` 84 | 7. run the command line interface like: 85 | ``compute_pi -n 1000`` 86 | The previous command will estimate π using 1000 random points. 87 | 88 | Contributing 89 | ************ 90 | 91 | If you want to contribute to the development of ci_for_science, 92 | have a look at the `contribution guidelines `_. 93 | 94 | License 95 | ******* 96 | 97 | Copyright (c) 2019-2020, 98 | 99 | Licensed under the Apache License, Version 2.0 (the "License"); 100 | you may not use this file except in compliance with the License. 101 | You may obtain a copy of the License at 102 | 103 | http://www.apache.org/licenses/LICENSE-2.0 104 | 105 | Unless required by applicable law or agreed to in writing, software 106 | distributed under the License is distributed on an "AS IS" BASIS, 107 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 108 | See the License for the specific language governing permissions and 109 | limitations under the License. 110 | 111 | 112 | 113 | Credits 114 | ******* 115 | 116 | This package was created with `Cookiecutter `_ and the `NLeSC/python-template `_. 117 | 118 | .. _miniconda: https://docs.conda.io/en/latest/miniconda.html 119 | .. _`Github actions`: https://help.github.com/en/actions/automating-your-workflow-with-github-actions 120 | .. _`GitLab CI`: https://docs.gitlab.com/ee/ci/ 121 | .. _`Tania Allard great tutorial`: https://github.com/trallard/ci-research 122 | .. _`Travis tutorial`: https://docs.travis-ci.com/user/tutorial/ 123 | .. _`Monte Carlo method`: https://en.wikipedia.org/wiki/Monte_Carlo_method 124 | -------------------------------------------------------------------------------- /ci_for_science/__init__.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | from .ci_for_science import compute_pi 4 | 5 | logging.getLogger(__name__).addHandler(logging.NullHandler()) 6 | 7 | __author__ = "Felipe Zapata" 8 | __email__ = 'f.zapata@esciencecenter.nl' 9 | 10 | __all__ = ["compute_pi"] 11 | -------------------------------------------------------------------------------- /ci_for_science/__version__.py: -------------------------------------------------------------------------------- 1 | __version__ = '0.2.0' 2 | -------------------------------------------------------------------------------- /ci_for_science/ci_for_science.py: -------------------------------------------------------------------------------- 1 | """Module to do some awesome scientific simulations.""" 2 | 3 | import argparse 4 | import numpy as np 5 | from compute_pi_cpp import compute_pi_cpp 6 | 7 | __all__ = ["compute_pi"] 8 | 9 | parser = argparse.ArgumentParser( 10 | description="run_simulation -n number_of_samples") 11 | parser.add_argument('-n', '--number', required=True, type=int, 12 | help="Number of samples") 13 | parser.add_argument( 14 | '-m', '--mode', choices=["numpy", "cpp"], default="numpy") 15 | 16 | 17 | def main(): 18 | """Call an awesome scientific package.""" 19 | # read the command line arguments 20 | args = parser.parse_args() 21 | samples = args.number 22 | mode = args.mode 23 | # perform the simulation 24 | print(f'Do some awesome science in {mode}!') 25 | if mode == "numpy": 26 | serial_pi = compute_pi(samples) 27 | print(f"Pi Numpy calculation: {serial_pi:0.8f}") 28 | else: 29 | parallel_pi = compute_pi_cpp(samples) 30 | print(f"Pi C++ calculation: {parallel_pi:0.8f}") 31 | 32 | 33 | def compute_pi(samples: int) -> float: 34 | """Compute the pi number using the Monte-Carlo method. 35 | 36 | Measure the ratio between points that are inside a circle of radius 1 37 | and a square of size 1. 38 | """ 39 | # Take random x and y cartesian coordinates 40 | xs = np.random.uniform(size=samples) 41 | ys = np.random.uniform(size=samples) 42 | 43 | # Count the points inside the circle 44 | rs = np.sqrt(xs**2 + ys**2) 45 | inside = rs[rs < 1.0] 46 | 47 | # compute pi 48 | approx_pi = (float(inside.size) / samples) * 4 49 | 50 | return approx_pi 51 | 52 | 53 | if __name__ == "__main__": 54 | main() 55 | -------------------------------------------------------------------------------- /cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Specify the minimum version for CMake 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | # Project's name 5 | project(compute_pi LANGUAGES CXX) 6 | 7 | ############################################################################### 8 | # build setup 9 | ############################################################################### 10 | 11 | # Set the output folder where your program will be created 12 | set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin) 13 | set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) 14 | set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) 15 | 16 | ############################################################################### 17 | # Compiler flags 18 | ############################################################################### 19 | 20 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS) 21 | #release comes with -O3 by default 22 | set(CMAKE_BUILD_TYPE Release CACHE STRING 23 | "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) 24 | endif(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS) 25 | 26 | ############################################################################### 27 | # dependencies 28 | ############################################################################### 29 | 30 | 31 | # Search for pybind11 32 | find_package(pybind11 REQUIRED) 33 | 34 | ############################################################################### 35 | # targets 36 | ############################################################################### 37 | add_library(scientific_module scientific_module) 38 | 39 | target_include_directories(scientific_module 40 | PUBLIC 41 | ${PROJECT_SOURCE_DIR}/include 42 | ) 43 | 44 | set_target_properties(scientific_module 45 | PROPERTIES 46 | CXX_STANDARD 14 47 | CXX_STANDARD_REQUIRED ON 48 | ) 49 | 50 | target_compile_options(scientific_module 51 | PUBLIC 52 | "-Wall" 53 | ) 54 | 55 | target_link_libraries(scientific_module 56 | PRIVATE 57 | pybind11::module 58 | ) 59 | -------------------------------------------------------------------------------- /cpp/include/scientific_module.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SCIENTIFIC_CODE_H_ 2 | #define SCIENTIFIC_CODE_H_ 3 | #include 4 | #include 5 | 6 | double compute_pi_parallel(int samples); 7 | std::vector create_random_vector(int samples); 8 | 9 | #endif // SCIENTIFIC_CODE -------------------------------------------------------------------------------- /cpp/scientific_module.cpp: -------------------------------------------------------------------------------- 1 | #include "scientific_module.hpp" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | namespace py = pybind11; 8 | 9 | double compute_pi_cpp(int samples) { 10 | // Take random x and y cartesian coordinates 11 | 12 | auto xs = create_random_vector(samples); 13 | auto ys = create_random_vector(samples); 14 | 15 | auto inside = 0.0; 16 | for (auto i = 0; i < samples; i++) { 17 | auto x = sqrt(pow(xs[i], 2.0) + pow(ys[i], 2.0)); 18 | if (x < 1.0) { 19 | inside += 1.0; 20 | } 21 | } 22 | // return approx_pi 23 | return 4 * inside / static_cast(samples); 24 | } 25 | 26 | std::vector create_random_vector(int samples) { 27 | // Will be used to obtain a seed for the random number engine 28 | std::random_device rd; 29 | // Standard mersenne_twister_engine seeded with rd() 30 | std::mt19937 gen(rd()); 31 | std::uniform_real_distribution<> dist(0.0, 1.0); 32 | std::vector xs(samples); 33 | std::generate(xs.begin(), xs.end(), [&]() { return dist(gen); }); 34 | return xs; 35 | } 36 | 37 | // Python interface definition 38 | PYBIND11_MODULE(compute_pi_cpp, m) { 39 | m.doc() = "Compute the pi number using the Monte Carlo method"; 40 | 41 | m.def("compute_pi_cpp", &compute_pi_cpp, 42 | R"pdoc(Compute pi using the Monte Carlo method 43 | 44 | Args: 45 | samples (int): Number of samples 46 | )pdoc", 47 | py::arg("samples")); 48 | } 49 | -------------------------------------------------------------------------------- /project_setup.rst: -------------------------------------------------------------------------------- 1 | Project Setup 2 | ************* 3 | 4 | Here we provide some details about the project setup. Most of the choices are explained in the `guide `_. Links to the relevant sections are included below. 5 | Feel free to remove this text when the development of the software package takes off. 6 | 7 | For a quick reference on software development, we refer to `the software guide checklist `_. 8 | 9 | Version control 10 | --------------- 11 | 12 | Once your Python package is created, put it under 13 | `version control `_! 14 | We recommend using `git `_ and `github `_. 15 | 16 | .. code-block:: console 17 | 18 | cd ci_for_science 19 | git init 20 | git add -A 21 | git commit 22 | 23 | To put your code on github, follow `this tutorial `_. 24 | 25 | Python versions 26 | --------------- 27 | 28 | This repository is set up with Python versions: 29 | 30 | * 3.6 31 | * 3.7 32 | 33 | Add or remove Python versions based on project requirements. See `the guide `_ for more information about Python versions. 34 | 35 | Package management and dependencies 36 | ----------------------------------- 37 | 38 | You can use either `pip` or `conda` for installing dependencies and package management. This repository does not force you to use one or the other, as project requirements differ. For advice on what to use, please check `the relevant section of the guide `_. 39 | 40 | * Dependencies should be added to `setup.py` in the `install_requires` list. 41 | 42 | Packaging/One command install 43 | ----------------------------- 44 | 45 | You can distribute your code using pipy or conda. Again, the project template does not enforce the use of either one. `The guide `_ can help you decide which tool to use for packaging. 46 | 47 | If you decide to use pypi for distributing you code, you can configure travis to upload to pypi when you make a release. If you specified your pypi user name during generation of this package, the ``.travis.yml`` file contains a section that looks like: 48 | 49 | .. code-block:: yaml 50 | 51 | deploy: 52 | provider: pypi 53 | user: no_pypi_travis_deployment 54 | password: 55 | secure: FIXME; see README for more info 56 | on: 57 | tags: true 58 | branch: master 59 | 60 | Before this actually works, you need to add an encrypted password for your pypi account. The `travis documentation `_ specifies how to do this. 61 | 62 | Testing and code coverage 63 | ------------------------- 64 | 65 | * Tests should be put in the ``tests`` folder. 66 | * The ``tests`` folder contains: 67 | 68 | - Example tests that you should replace with your own meaningful tests (file: ``test_ci_for_science``) 69 | - A test that checks whether your code conforms to the Python style guide (PEP 8) (file: ``test_lint.py``) 70 | 71 | * The testing framework used is `PyTest `_ 72 | 73 | - `PyTest introduction `_ 74 | 75 | * Tests can be run with ``python setup.py test`` 76 | 77 | - This is configured in ``setup.py`` and ``setup.cfg`` 78 | 79 | * Use `Travis CI `_ to automatically run tests and to test using multiple Python versions 80 | 81 | - Configuration can be found in ``.travis.yml`` 82 | - `Getting started with Travis CI `_ 83 | 84 | * TODO: add something about code quality/coverage tool? 85 | * `Relevant section in the guide `_ 86 | 87 | Documentation 88 | ------------- 89 | 90 | * Documentation should be put in the ``docs`` folder. The contents have been generated using ``sphinx-quickstart`` (Sphinx version 1.6.5). 91 | * We recommend writing the documentation using Restructured Text (reST) and Google style docstrings. 92 | 93 | - `Restructured Text (reST) and Sphinx CheatSheet `_ 94 | - `Google style docstring examples `_. 95 | 96 | * The documentation is set up with the Read the Docs Sphinx Theme. 97 | 98 | - Check out the `configuration options `_. 99 | 100 | * To generate html documentation run ``python setup.py build_sphinx`` 101 | 102 | - This is configured in ``setup.cfg`` 103 | - Alternatively, run ``make html`` in the ``docs`` folder. 104 | 105 | * The ``docs/_templates`` directory contains an (empty) ``.gitignore`` file, to be able to add it to the repository. This file can be safely removed (or you can just leave it there). 106 | * To put the documentation on `Read the Docs `_, log in to your Read the Docs account, and import the repository (under 'My Projects'). 107 | 108 | - Include the link to the documentation in this README_. 109 | 110 | * `Relevant section in the guide `_ 111 | 112 | Coding style conventions and code quality 113 | ----------------------------------------- 114 | 115 | * Check your code style with ``prospector`` 116 | * You may need run ``pip install .[dev]`` first, to install the required dependencies 117 | * You can use ``yapf`` to fix the readability of your code style and ``isort`` to format and group your imports 118 | * `Relevant section in the guide `_ 119 | 120 | Package version number 121 | ---------------------- 122 | 123 | * We recommend using `semantic versioning `_. 124 | * For convenience, the package version is stored in a single place: ``ci_for_science/__version__.py``. For updating the version number, you only have to change this file. 125 | * Don't forget to update the version number before `making a release `_! 126 | 127 | 128 | Logging 129 | ------- 130 | 131 | * We recommend using the `logging` module for getting useful information from your module (instead of using `print`). 132 | * The project is set up with a logging example. 133 | * `Relevant section in the guide `_ 134 | 135 | CHANGELOG.rst 136 | ------------- 137 | 138 | * Document changes to your software package 139 | * `Relevant section in the guide `_ 140 | 141 | CITATION.cff 142 | ------------ 143 | 144 | * To allow others to cite your software, add a ``CITATION.cff`` file 145 | * It only makes sense to do this once there is something to cite (e.g., a software release with a DOI). 146 | * Follow the `making software citable `_ section in the guide. 147 | 148 | CODE_OF_CONDUCT.rst 149 | ------------------- 150 | 151 | * Information about how to behave professionally 152 | * `Relevant section in the guide `_ 153 | 154 | CONTRIBUTING.rst 155 | ---------------- 156 | 157 | * Information about how to contribute to this software package 158 | * `Relevant section in the guide `_ 159 | 160 | MANIFEST.in 161 | ----------- 162 | 163 | * List non-Python files that should be included in a source distribution 164 | * `Relevant section in the guide `_ 165 | 166 | NOTICE 167 | ------ 168 | 169 | * List of attributions of this project and Apache-license dependencies 170 | * `Relevant section in the guide `_ 171 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ci-for-research/example-python-monte-carlo-pi/2a682763d50b0a160a68db151f5b60fbdace5b9e/requirements.txt -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README.rst 3 | 4 | [aliases] 5 | # Define `python setup.py test` 6 | test=pytest 7 | 8 | [coverage:run] 9 | branch = True 10 | source = ci_for_science 11 | 12 | [tool:pytest] 13 | testpaths = tests 14 | addopts = --cov --cov-report xml --cov-report term --cov-report html 15 | 16 | # Define `python setup.py build_sphinx` 17 | [build_sphinx] 18 | source-dir = docs 19 | build-dir = docs/_build 20 | all_files = 1 21 | builder = html 22 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | 4 | import setuptools 5 | import sys 6 | from setuptools import Extension, setup 7 | 8 | from Cython.Distutils import build_ext 9 | 10 | here = os.path.abspath(os.path.dirname(__file__)) 11 | 12 | # To update the package version number, edit ci_for_science/__version__.py 13 | version = {} 14 | with open(os.path.join(here, 'ci_for_science', '__version__.py')) as f: 15 | exec(f.read(), version) 16 | 17 | with open('README.rst') as readme_file: 18 | readme = readme_file.read() 19 | 20 | 21 | def has_flag(compiler, flagname): 22 | """Return a boolean indicating whether a flag name is supported on the specified compiler. 23 | 24 | As of Python 3.6, CCompiler has a `has_flag` method. 25 | http: // bugs.python.org/issue26689 26 | """ 27 | import tempfile 28 | with tempfile.NamedTemporaryFile('w', suffix='.cc') as f: 29 | f.write('int main (int argc, char **argv) { return 0; }') 30 | try: 31 | compiler.compile([f.name], extra_postargs=[flagname]) 32 | except setuptools.distutils.errors.CompileError: 33 | return False 34 | return True 35 | 36 | 37 | def cpp_flag(compiler): 38 | """Return the -std=c++[11/14] compiler flag. 39 | 40 | The newer version is prefered over c++11 (when it is available). 41 | """ 42 | flags = ['-std=c++14', '-std=c++11'] 43 | 44 | for flag in flags: 45 | if has_flag(compiler, flag): 46 | return flag 47 | 48 | raise RuntimeError('Unsupported compiler -- at least C++11 support ' 49 | 'is needed!') 50 | 51 | 52 | class get_pybind_include: 53 | """Helper class to determine the pybind11 include path. 54 | 55 | The purpose of this class is to postpone importing pybind11 56 | until it is actually installed, so that the ``get_include()`` 57 | method can be invoked. 58 | """ 59 | 60 | def __init__(self, user=False): 61 | self.user = user 62 | 63 | def __str__(self): 64 | import pybind11 65 | return pybind11.get_include(self.user) 66 | 67 | 68 | class BuildExt(build_ext): 69 | """A custom build extension for adding compiler-specific options.""" 70 | 71 | c_opts = { 72 | 'msvc': ['/EHsc'], 73 | 'unix': [], 74 | } 75 | l_opts = { 76 | 'msvc': [], 77 | 'unix': [], 78 | } 79 | 80 | if sys.platform == 'darwin': 81 | darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.7'] 82 | c_opts['unix'] += darwin_opts 83 | l_opts['unix'] += darwin_opts 84 | 85 | def build_extensions(self): 86 | """Actual compilation.""" 87 | ct = self.compiler.compiler_type 88 | opts = self.c_opts.get(ct, []) 89 | link_opts = self.l_opts.get(ct, []) 90 | if ct == 'unix': 91 | opts.append('-DVERSION_INFO="%s"' % 92 | self.distribution.get_version()) 93 | opts.append(cpp_flag(self.compiler)) 94 | if has_flag(self.compiler, '-fvisibility=hidden'): 95 | opts.append('-fvisibility=hidden') 96 | elif ct == 'msvc': 97 | opts.append('/DVERSION_INFO=\\"%s\\"' % 98 | self.distribution.get_version()) 99 | for ext in self.extensions: 100 | ext.extra_compile_args = opts 101 | ext.extra_link_args = link_opts 102 | build_ext.build_extensions(self) 103 | 104 | 105 | ext_pybind = Extension( 106 | 'compute_pi_cpp', 107 | sources=['cpp/scientific_module.cpp'], 108 | include_dirs=[ 109 | "cpp/include", 110 | # Path to pybind11 headers 111 | get_pybind_include(), 112 | get_pybind_include(user=True), 113 | ], 114 | language='c++') 115 | 116 | 117 | setup( 118 | name='ci_for_science', 119 | version=version['__version__'], 120 | description="A introduction to Continuous integration and continuous development for scientific applications", 121 | long_description=readme + '\n\n', 122 | author="Felipe Zapata", 123 | author_email='f.zapata@esciencecenter.nl', 124 | url='https://github.com//ci_for_science', 125 | packages=[ 126 | 'ci_for_science', 127 | ], 128 | include_package_data=True, 129 | license="Apache Software License 2.0", 130 | zip_safe=False, 131 | keywords='ci_for_science', 132 | classifiers=[ 133 | 'Development Status :: 4 - Beta', 134 | 'Intended Audience :: Developers', 135 | 'License :: OSI Approved :: Apache Software License', 136 | 'Natural Language :: English', 137 | 'Programming Language :: Python :: 3', 138 | 'Programming Language :: Python :: 3.6', 139 | 'Programming Language :: Python :: 3.7', 140 | ], 141 | test_suite='tests', 142 | cmdclass={'build_ext': BuildExt}, 143 | ext_modules=[ext_pybind], 144 | install_requires=["cython", "numpy", "pybind11>=2.2.4"], 145 | setup_requires=[ 146 | # dependency for `python setup.py test` 147 | 'pytest-runner', 148 | # dependencies for `python setup.py build_sphinx` 149 | 'sphinx', 150 | 'sphinx_rtd_theme', 151 | 'recommonmark' 152 | ], 153 | tests_require=[ 154 | 'pytest', 155 | 'pytest-cov', 156 | 'pycodestyle', 157 | ], 158 | entry_points={ 159 | 'console_scripts': [ 160 | 'compute_pi=ci_for_science.ci_for_science:main', 161 | ] 162 | }, 163 | extras_require={ 164 | 'test': ['coverage', 'pytest>=3.9', 'pytest-cov', 'pycodestyle', 'codacy-coverage'], 165 | } 166 | ) 167 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /tests/test_ci_for_science.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """Tests for the ci_for_science module.""" 4 | from ci_for_science import compute_pi 5 | from compute_pi_cpp import compute_pi_cpp 6 | 7 | 8 | def test_serial_pi(): 9 | """Check the serial implentation.""" 10 | call_montecarlo(compute_pi) 11 | 12 | 13 | def test_parallel_pi(): 14 | """Check the serial implentation.""" 15 | call_montecarlo(compute_pi_cpp) 16 | 17 | 18 | def call_montecarlo(function: callable, samples: int = 100000): 19 | """Check that the computation approximates pi.""" 20 | approx_pi = function(100000) 21 | print("Approximate value of pi is: ", approx_pi) 22 | 23 | predicate_1 = approx_pi < 3.16 24 | predicate_2 = approx_pi > 3.12 25 | 26 | assert predicate_1 and predicate_2 27 | -------------------------------------------------------------------------------- /tests/test_lint.py: -------------------------------------------------------------------------------- 1 | """ Lint tests """ 2 | import os 3 | import textwrap 4 | 5 | import pycodestyle # formerly known as pep8 6 | 7 | 8 | def test_pep8_conformance(): 9 | """Test that we conform to PEP-8.""" 10 | check_paths = [ 11 | 'ci_for_science', 12 | 'tests', 13 | ] 14 | exclude_paths = [] 15 | 16 | print("PEP8 check of directories: {}\n".format(', '.join(check_paths))) 17 | 18 | # Get paths wrt package root 19 | package_root = os.path.dirname(os.path.dirname(__file__)) 20 | for paths in (check_paths, exclude_paths): 21 | for i, path in enumerate(paths): 22 | paths[i] = os.path.join(package_root, path) 23 | 24 | style = pycodestyle.StyleGuide() 25 | style.options.exclude.extend(exclude_paths) 26 | 27 | success = style.check_files(check_paths).total_errors == 0 28 | 29 | if not success: 30 | print(textwrap.dedent(""" 31 | Your Python code does not conform to the official Python style 32 | guide (PEP8), see https://www.python.org/dev/peps/pep-0008 33 | 34 | A list of warning and error messages can be found above, 35 | prefixed with filename:line number:column number. 36 | 37 | Run `yapf -i yourfile.py` to automatically fix most errors. 38 | Run `yapf -d yourfile.py` to preview what would be changed. 39 | Run `pip install --upgrade yapf` to install the latest version 40 | of yapf. 41 | """)) 42 | 43 | assert success, "Your code does not conform to PEP8" 44 | --------------------------------------------------------------------------------