From 650fd81ce1e5b5c439c22d0ed9e4d726572b8c6c Mon Sep 17 00:00:00 2001 From: Elizabeth Sall Date: Tue, 20 Apr 2021 22:32:12 -0700 Subject: [PATCH] Add boilerplate Fixes most of #1 [ branch restrictions needs to be done in repo settings ] --- .github/ISSUE_TEMPLATE/bug_report.md | 39 +++++ .github/ISSUE_TEMPLATE/feature_request.md | 32 ++++ .github/pull_request_template.md | 27 +++ .github/workflows/publish.yml | 43 +++++ .github/workflows/test.yml | 35 ++++ .gitignore | 122 +++++++++++++ CHANGELOG.md | 6 + CONTRIBUTING.md | 2 + Dockerfile | 31 ++++ LICENSE | 201 ++++++++++++++++++++++ README.md | 50 ++++++ dev-requirements.txt | 8 + docs/Makefile | 20 +++ docs/README.md | 35 ++++ docs/_templates/my-class-template.rst | 33 ++++ docs/_templates/my-module-template.rst | 67 ++++++++ docs/autodoc.rst | 6 + docs/conf.py | 90 ++++++++++ docs/index.rst | 27 +++ docs/make.bat | 35 ++++ docs/starting.md | 74 ++++++++ examples/README.md | 3 + manifest.in | 12 ++ notebooks/README.md | 4 + pre-commit-config.yaml | 17 ++ pytest.ini | 4 + requirements.txt | 1 + setup.cfg | 14 ++ setup.py | 44 +++++ tests/README.md | 51 ++++++ tests/test_tests.py | 14 ++ tm2py/__init__.py | 2 + tm2py/_api.py | 3 + tm2py/_version.py | 1 + tm2py/template.py | 71 ++++++++ 35 files changed, 1224 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 dev-requirements.txt create mode 100644 docs/Makefile create mode 100644 docs/README.md create mode 100644 docs/_templates/my-class-template.rst create mode 100644 docs/_templates/my-module-template.rst create mode 100644 docs/autodoc.rst create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat create mode 100644 docs/starting.md create mode 100644 examples/README.md create mode 100644 manifest.in create mode 100644 notebooks/README.md create mode 100644 pre-commit-config.yaml create mode 100644 pytest.ini create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 tests/README.md create mode 100644 tests/test_tests.py create mode 100644 tm2py/__init__.py create mode 100644 tm2py/_api.py create mode 100644 tm2py/_version.py create mode 100644 tm2py/template.py diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..d014b4f5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,39 @@ +--- +name: Bug report +about: Create a report to help us improve +title: "[BUG] Description of problem" +labels: bug +assignees: '' + +--- + +## Describe the bug +A clear and concise description of what the bug is or the error code you got. e.g. +```python +KeyError: 'Passing list-likes to .loc or [] with any missing labels is no longer supported, see https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike' +``` + +## To Reproduce +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +### Failing tests +- [ ] No applicable test failed, need to create. +- [ ] + +### Triggering line of code + + +### Thoughts on resolution + +### Full stack trace + + +### Environment + +Operating system: +Context (conda, jupyter, etc): +Environment (e.g. output from `conda list`): diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..51151615 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,32 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: "[FEATURE]" +labels: enhancement +assignees: '' + +--- + +### User Story +*As a ...insert type of user... I'd like to ...insert desired feature or behavior...* + +### Priority + +### Level of Effort + +### Resolution Ideas + +### Project +*Is there a funder or project associated with this feature?* + +### Who should be involved? +Implementer: +Commenters: +Users: +Reviewers: + +### Risk +*Will this potentially break anything?* + +#### Tests +*What are relevant tests or what tests need to be created in order to determine that this issue is complete?* diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..4d1efa8f --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,27 @@ +## What existing problem does the pull request solve and why should we include it? + + +## What is the testing plan? + +*Demonstrate the code is solid by discussing how results are verified and covered by tests* + + - [ ] Code for this PR is covered in tests + - [ ] Code passes all existing tests + +## Code formatting +*Code should be PEP8 compliant before merging by running a package like [`black`](https://pypi.org/project/black/)* + + - [ ] Code linted + +## Applicable Issues +*Please do not create a Pull Request without creating an issue first.* + +*Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes.* + + +#### Issues List + + - closes... + - closes... + + diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..35fa9f53 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,43 @@ +# This workflow will upload a Python Package using Twine when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Upload Python Package + +on: + release: + types: [created] + +jobs: + + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.7' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + python setup.py sdist bdist_wheel + twine upload dist/* + - name: Build Sphinx docs + run: | + cd docs + make html + - name: Deploy + if: success() + uses: peaceiris/actions-gh-pages@v3 + with: + publish_branch: gh-pages + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: _build/html/ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..d1e42991 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,35 @@ +name: Python package + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.7, 3.8] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r dev-requirements.txt + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Install package + run: | + pip install -e .[test] + - name: Test with pytest + run: | + pytest -s -m "not skipci" diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..7802e737 --- /dev/null +++ b/.gitignore @@ -0,0 +1,122 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# System Errata +.DS_Store +.DS_Store? + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Logs +pip-log.txt +pip-delete-this-directory.txt +*.log +# except logs in the example +!examples/**/*.log + +#temp files +tests/scratch/* +!tests/scratch/readme.md +scratch/* +.temp +.pytest_cache +*.bak +.cache +.hubstorinfo + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Sphinx documentation +docs/_build/ +docs/_generated/* +docs/_autosummary/* + +# Jupyter +.ipynb_checkpoints +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# IDE files +.idea +.spyderproject +.spyproject +.project +.pydevproject +.settings +.vscode + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..5d57fef3 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# Changelog + +## Version (date) +- a list +- of things +- that have changed \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..5eee1c80 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,2 @@ +# Contribution Guide + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..283229c3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +# docker build -t mypackage . +# docker run --rm -v "$PWD":/home/jovyan/work mypackage /bin/bash +FROM jupyter/minimal-notebook + +COPY ../requirements.txt /tmp/requirements.txt + +# configure conda and install packages in one RUN to keep image tidy +RUN conda config --set show_channel_urls true && \ + conda config --set channel_priority strict && \ + conda config --prepend channels conda-forge && \ + conda update --yes -n base conda && \ + conda install --update-all --force-reinstall --yes --file /tmp/requirements.txt + +#RUN rm -f -r -v /opt/conda/share/jupyter/kernels/python3 && \ +# python -m ipykernel install && + +COPY . /tmp/src +RUN pip install /tmp/src + +RUN conda clean --all --yes && \ + conda info --all && \ + conda list && \ + jupyter kernelspec list && \ + ipython -c "import tm2py; print('Installed version: ', tm2py.__version__)" + +# copy default jupyterlab settings, then set jupyter working directory to map to mounted volume +# COPY overrides.json /opt/conda/share/jupyter/lab/settings/ +WORKDIR /home/jovyan/work + +# set default command to launch when container is run +CMD ["jupyter", "lab", "--ip='0.0.0.0'", "--port=8888", "--no-browser", "--NotebookApp.token=''", "--NotebookApp.password=''"] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..261eeb9e --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 00000000..068ab1e2 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# Travel Model 2 Python Package + +## Installation + +If you are managing multiple python versions, we suggest using [`virtualenv`](https://virtualenv.pypa.io/en/latest/) or [`conda`](https://conda.io/en/latest/) virtual environments. + +The following instructions create and activate a conda environment (recommended) in which you can install: + +```bash +conda config --add channels conda-forge +conda create python=3.7 -n +conda activate +``` + +Basic installation instructions are as follows: + +```bash +pip install tm2py +``` + +#### Bleeding Edge +If you want to install a more up-to-date or development version, you can do so by installing it from the `develop` branch as follows: + +```bash +conda config --add channels conda-forge +conda create python=3.7 -n +conda activate +pip install git+https://github.com/bayareametro/tm2py@develop +``` + +#### Developers (from clone) +If you are going to be working on Lasso locally, you might want to clone it to your local machine and install it from the clone. The -e will install it in [editable mode](https://pip.pypa.io/en/stable/reference/pip_install/?highlight=editable#editable-installs). + + +```bash +conda config --add channels conda-forge +conda create python=3.7 -n +conda activate +git clone https://github.com/bayareametro/tm2py +cd tm2py +pip install -e . +``` + + +## Basic Usage + + +## Contributing + +Details can be found in [CONTRIBUTING] \ No newline at end of file diff --git a/dev-requirements.txt b/dev-requirements.txt new file mode 100644 index 00000000..f840628d --- /dev/null +++ b/dev-requirements.txt @@ -0,0 +1,8 @@ +black +flake8 +pre-commit +pytest +recommonmark +sphinx +sphinx-autodoc-typehints +sphinx_rtd_theme diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..d4bb2cbb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..6706a0ea --- /dev/null +++ b/docs/README.md @@ -0,0 +1,35 @@ +# Documentation + +Documentation is developed using the Python package [Sphinx](https://www.sphinx-doc.org/). + +## Installing + +1. Along with all over development tools ( recommended ) +```sh +pip install -r dev-requirements.txt +``` + +2. Using pip +```sh +pip install sphinx sphinx-autodoc-typehints sphinx_rtd_theme +``` + +2. Using conda +```sh +conda install sphinx sphinx-autodoc-typehints sphinx_rtd_theme +``` + +## Developing + +... + +## Building + +Sphinx documentation webpages can be built using the following shell command from the `docs` folder: +```sh +make html +``` + +## Deploying + +Documentation is built and deployed to {EDITME} upon the master branch successfully passing continuous integration tests. diff --git a/docs/_templates/my-class-template.rst b/docs/_templates/my-class-template.rst new file mode 100644 index 00000000..5a91b231 --- /dev/null +++ b/docs/_templates/my-class-template.rst @@ -0,0 +1,33 @@ +{{ fullname | escape | underline}} + +.. currentmodule:: {{ module }} + +.. autoclass:: {{ objname }} + :members: + :show-inheritance: + :inherited-members: + + {% block methods %} + .. automethod:: __init__ + + {% if methods %} + .. rubric:: {{ _('Methods') }} + + .. autosummary:: + {% for item in methods %} + ~{{ name }}.{{ item }} + {%- endfor %} + {% endif %} + {% endblock %} + + {% block attributes %} + {% if attributes %} + .. rubric:: {{ _('Attributes') }} + + .. autosummary:: + {% for item in attributes %} + ~{{ name }}.{{ item }} + {%- endfor %} + {% endif %} + {% endblock %} + \ No newline at end of file diff --git a/docs/_templates/my-module-template.rst b/docs/_templates/my-module-template.rst new file mode 100644 index 00000000..c552fc33 --- /dev/null +++ b/docs/_templates/my-module-template.rst @@ -0,0 +1,67 @@ +{{ fullname | escape | underline}} + +{% block modules %} +{% if modules %} +.. rubric:: Modules + +.. autosummary:: + :toctree: + :template: my-module-template.rst + :recursive: +{% for item in modules %} + {{ item }} +{%- endfor %} +{% endif %} +{% endblock %} + +.. automodule:: {{ fullname }} + + {% block attributes %} + {% if attributes %} + .. rubric:: Module Attributes + + .. autosummary:: + :toctree: + {% for item in attributes %} + {{ item }} + {%- endfor %} + {% endif %} + {% endblock %} + + {% block functions %} + {% if functions %} + .. rubric:: {{ _('Functions') }} + + .. autosummary:: + :toctree: + {% for item in functions %} + {{ item }} + {%- endfor %} + {% endif %} + {% endblock %} + + {% block classes %} + {% if classes %} + .. rubric:: {{ _('Classes') }} + + .. autosummary:: + :toctree: + :template: my-class-template.rst + {% for item in classes %} + {{ item }} + {%- endfor %} + {% endif %} + {% endblock %} + + {% block exceptions %} + {% if exceptions %} + .. rubric:: {{ _('Exceptions') }} + + .. autosummary:: + :toctree: + {% for item in exceptions %} + {{ item }} + {%- endfor %} + {% endif %} + {% endblock %} + diff --git a/docs/autodoc.rst b/docs/autodoc.rst new file mode 100644 index 00000000..9eab5881 --- /dev/null +++ b/docs/autodoc.rst @@ -0,0 +1,6 @@ +.. autosummary:: + :toctree: _autosummary + :template: my-module-template.rst + :recursive: + + tm2py \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..9eb89747 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,90 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys + +# Get the project root dir, which is the parent dir of this +cwd = os.getcwd() +project_root = os.path.dirname(cwd) + +# Insert the project root dir as the first element in the PYTHONPATH. +# This lets us ensure that the source package is imported, and that its +# version is used. +sys.path.insert(0, project_root) + +import tm2py + +# -- Project information ----------------------------------------------------- + +project = 'tm2py' +copyright = '2021, Bay Area Metro' +authors = 'TBD' +version = tm2py.__version__ + +# -- General configuration --------------------------------------------------- + +# 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.autodoc", + "sphinx.ext.doctest", + "sphinx_autodoc_typehints", + "sphinx.ext.ifconfig", + "sphinx.ext.inheritance_diagram", + "sphinx.ext.intersphinx", + "sphinx.ext.todo", + "sphinx.ext.coverage", + "sphinx.ext.autosummary", + "sphinx.ext.viewcode", + "sphinx.ext.napoleon", + "recommonmark", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = "sphinx_rtd_theme" + +# 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'] + +intersphinx_mapping = { +} + +autodoc_default_options = { + "members": True, + "undoc-members": True, + "inherited-members": True, + "imported-members": True, + "show-inheritance": True, + "member-order": "groupwise", +} + +autoclass_content = "class" +# classes should include both the class' and the __init__ method's docstring + +autosummary_generate = True diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..fcc7575e --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,27 @@ +.. tm2py documentation master file, created by + sphinx-quickstart on Mon Apr 19 14:20:11 2021. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to tm2py's documentation! +======================================== + +This package ....ADDME + +It aims to have the following functionality: +1. ADDME + +.. toctree:: + :maxdepth: 1 + :caption: Contents: + + starting + API reference <_autosummary/tm2py> + + +Indices and tables +=================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 00000000..2119f510 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/starting.md b/docs/starting.md new file mode 100644 index 00000000..afa95b4c --- /dev/null +++ b/docs/starting.md @@ -0,0 +1,74 @@ +# Starting Out + +## Installation + +If you are managing multiple python versions, we suggest using [`virtualenv`](https://virtualenv.pypa.io/en/latest/) or [`conda`](https://conda.io/en/latest/) virtual environments. + +The following instructions create and activate a conda environment (recommended) in which you can install: + +```bash +conda config --add channels conda-forge +conda create python=3.7 -n +conda activate +``` + +Basic installation instructions are as follows: + +```bash +pip install tm2py +``` + +#### Bleeding Edge +If you want to install a more up-to-date or development version, you can do so by installing it from the `develop` branch as follows: + +```bash +conda config --add channels conda-forge +conda create python=3.7 -n +conda activate +pip install git+https://github.com/bayareametro/tm2py@develop +``` + +#### Developers (from clone) +If you are going to be working on Lasso locally, you might want to clone it to your local machine and install it from the clone. The -e will install it in [editable mode](https://pip.pypa.io/en/stable/reference/pip_install/?highlight=editable#editable-installs). + + +```bash +conda config --add channels conda-forge +conda create python=3.7 -n +conda activate +git clone https://github.com/bayareametro/tm2py +cd tm2py +pip install -e . +``` + +Notes: + +1. The -e installs it in editable mode. +2. If you are not part of the project team and want to contribute code bxack to the project, please fork before you clone and then add the original repository to your upstream origin list per [these directions on github](https://help.github.com/en/articles/fork-a-repo). +3. if you wanted to install from a specific tag/version number or branch, replace `@main` with `@` or `@tag` +4. If you want to make use of frequent developer updates for network wrangler as well, you can also install it from clone by copying the instructions for cloning and installing Lasso for Network Wrangler + +If you are going to be doing development, we also recommend: + - a good IDE such as [VS Code](https://code.visualstudio.com/), Sublime Text, etc. + with Python syntax highlighting turned on. + - [GitHub Desktop](https://desktop.github.com/) to locally update your clones + +## Brief Intro + + +### Typical Workflow + + + +## Running Quickstart Jupyter Notebooks + +To learn basic lasso functionality, please refer to the following jupyter notebooks in the `/notebooks` directory: + +- ADDME + + Jupyter notebooks can be started by activating the lasso conda environment and typing `jupyter notebook`: + + ```bash + conda activate + jupyter notebook + ``` diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000..f384b492 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,3 @@ +# Examples + +This repository comes with the following example data... diff --git a/manifest.in b/manifest.in new file mode 100644 index 00000000..700b57d7 --- /dev/null +++ b/manifest.in @@ -0,0 +1,12 @@ +include LICENSE +include README.md +include requirements.txt +include dev-requirements.txt + +recursive-include examples * +recursive-include tests * + +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] + +recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif diff --git a/notebooks/README.md b/notebooks/README.md new file mode 100644 index 00000000..8c2f7d1e --- /dev/null +++ b/notebooks/README.md @@ -0,0 +1,4 @@ +# Notebooks + +Repository for storing useful [Jupyter Notebooks](https://jupyter-notebook.readthedocs.io/en/stable/) + diff --git a/pre-commit-config.yaml b/pre-commit-config.yaml new file mode 100644 index 00000000..ed28d5b0 --- /dev/null +++ b/pre-commit-config.yaml @@ -0,0 +1,17 @@ +repos: + - repo: https://github.com/psf/black + rev: 19.10b0 + hooks: + - id: black + language_version: python3.7 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 + hooks: + - id: flake8 + types: + - python + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: check-json diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..2247cea0 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +markers = + skipci: Marker to skip if running continuous integration. Useful for lengthy tests. + menow: Marker indicating a test you are currently working on addressing. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..f2944db7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pandas > 1.0 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..99b0bfcd --- /dev/null +++ b/setup.cfg @@ -0,0 +1,14 @@ +[flake8] +max-line-length = 99 +extend-ignore = + E203, + W503, + E231, + E265, + E266, + F401, + F541 +exclude = + build, + docs/**, + __pycache__ diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..be37de81 --- /dev/null +++ b/setup.py @@ -0,0 +1,44 @@ +from setuptools import setup + +version = "0.0.1" + +classifiers = [ + "Development Status :: 1 - Planning", + "License :: OSI Approved :: Apache Software License", + "Natural Language :: English", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", +] + +with open("README.md") as f: + long_description = f.read() + +with open("requirements.txt") as f: + requirements = f.readlines() +install_requires = [r.strip() for r in requirements] + +with open("dev-requirements.txt") as f: + dev_requirements = f.readlines() +install_requires_dev = [r.strip() for r in dev_requirements] + +# While version is in active development, install both development and base requirements. +major_version_number = int(version.split('.')[0]) +if major_version_number < 1: + install_requires = install_requires + install_requires_dev + +setup( + name="tm2py", + version=version, + description="", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/BayAreaMetro/tm2py", + license="Apache 2", + platforms="any", + packages=["tm2py"], + include_package_data=True, + install_requires=install_requires, +) diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..7c341bdf --- /dev/null +++ b/tests/README.md @@ -0,0 +1,51 @@ +# Testing + +Tests are run with the [pyTest](pytest.org)/ + +## Test structure + +- Tests marked with `@pytest.mark.skipci` will not run by the continuous integration tests + +## Setup + +Pytest can be installed using one of the following options. + +Install along with all development requirements (recommended): +```sh +pip install -r dev-requirements.txt +``` +Install using PIP: +```sh +pip install pytest +``` +Install using Conda: +```sh +conda install pytest +``` + +## Running tests + +1. Run all tests +```sh +pytest +``` + +2. Run tests in `test_basic.py` +```sh +pytest tests/test_basic.py +``` + +3. Run tests decorated with @pytest.mark.favorites decorator +```sh +pytest -m favorites +``` + +4. Run all tests and print out stdout +```sh +pytest -s +``` + +5. Run all tests which are run on the CI server +```sh +pytest -v -m "not skipci" +``` diff --git a/tests/test_tests.py b/tests/test_tests.py new file mode 100644 index 00000000..56e31af2 --- /dev/null +++ b/tests/test_tests.py @@ -0,0 +1,14 @@ +import pytest + +@pytest.mark.skipci +def test_skipci(): + """Shouldn't be run on CI server. + """ + print("If this is a CI server, the marker isn't working!!!") + + +def test_testing(): + """Tests that tests are run. + """ + print("Tests are being run!") + import tm2py diff --git a/tm2py/__init__.py b/tm2py/__init__.py new file mode 100644 index 00000000..fa3b4604 --- /dev/null +++ b/tm2py/__init__.py @@ -0,0 +1,2 @@ +from ._api import * +from ._version import __version__ diff --git a/tm2py/_api.py b/tm2py/_api.py new file mode 100644 index 00000000..bc5e6a52 --- /dev/null +++ b/tm2py/_api.py @@ -0,0 +1,3 @@ +"Exposes api in direct package namespace" + +from .template import TemplateClass \ No newline at end of file diff --git a/tm2py/_version.py b/tm2py/_version.py new file mode 100644 index 00000000..b3c06d48 --- /dev/null +++ b/tm2py/_version.py @@ -0,0 +1 @@ +__version__ = "0.0.1" \ No newline at end of file diff --git a/tm2py/template.py b/tm2py/template.py new file mode 100644 index 00000000..dbc5a1ab --- /dev/null +++ b/tm2py/template.py @@ -0,0 +1,71 @@ +"""Example Google style docstrings. + +This module demonstrates documentation as specified by the `Google Python +Style Guide`_. Docstrings may extend over multiple lines. Sections are created +with a section header and a colon followed by a block of indented text. + +Example: + Examples can be given using either the ``Example`` or ``Examples`` + sections. Sections support any reStructuredText formatting, including + literal blocks:: + + $ python example_google.py + +Section breaks are created by resuming unindented text. Section breaks +are also implicitly created anytime a new section starts. + +Attributes: + module_level_variable1 (int): Module level variables may be documented in + either the ``Attributes`` section of the module docstring, or in an + inline docstring immediately following the variable. + + Either form is acceptable, but the two should not be mixed. Choose + one convention to document module level variables and be consistent + with it. + +Todo: + * For module TODOs + * You have to also use ``sphinx.ext.todo`` extension + +.. _Google Python Style Guide: + https://google.github.io/styleguide/pyguide.html +""" + +module_level_variable_module_doc = 12345 + +module_level_variable_inline = 98765 +"""int: Module level variable documented inline. + +The docstring may span multiple lines. The type may optionally be specified +on the first line, separated by a colon. +""" + +class TemplateClass: + """The summary line for a class docstring should fit on one line. + + If the class has public attributes, they may be documented here + in an ``Attributes`` section and follow the same formatting as a + function's ``Args`` section. Alternatively, attributes may be documented + inline with the attribute's declaration (see __init__ method below). + + Properties created with the ``@property`` decorator should be documented + in the property's getter method. + + Attributes: + attr1 (str): Description of `attr1`. + attr2 (:obj:`int`, optional): Description of `attr2`. + + """ + def __init__(self,var1: int,var2: str = "default") -> None: + """One-line summary of what method does. + + Args: + var1: Description of var1. + var2: Description of var2. Defaults to "default". + """ + pass + + @property + def my_readonly_property(self): + """int: Double of var1.""" + return self.var1*2 \ No newline at end of file