Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bengioe committed Feb 24, 2022
0 parents commit 14aa05f
Show file tree
Hide file tree
Showing 24 changed files with 648 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**Note: Do not attempt to use this directly unless you
know what you are doing. The happy path is to let `roadie` interact with this
template for you.**

This is a template repository. It will be used by `roadie` to instantiate
instances. We will make an initial commit on those repos with this boilerplate,
so there is traceability as to the version of this template the repo was created
with. This could be useful in figuring out later upgrades necessary to keep
a repo up-to-date with compliance standards.
10 changes: 10 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"repo_name": "Repository name (use hyphens)",
"description": "Project summary description",
"package": "package? (y/n)",
"type": "dash/package/service/task",
"yapf": "yapf configuration",
"flake8": "flake8 configuration",
"cli": "cli? (y/n)",
"python_name": "{{cookiecutter.repo_name|replace('-', '_')|lower}}"
}
28 changes: 28 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import shutil


def move_files(files_to_move):
for f in files_to_move:
shutil.move(f['src'], f['dest'])


def main():
have_cli = {{cookiecutter.cli == 'y'}}
python_name = '{{cookiecutter.python_name}}'


files_to_delete = set()
dirs_to_delete = set()

if not have_cli:
files_to_delete = files_to_delete.union({f'{python_name}/cli.py'})

for f in files_to_delete:
os.remove(f)

for d in dirs_to_delete:
shutil.rmtree(d)


main()
1 change: 1 addition & 0 deletions template-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test-package/*
8 changes: 8 additions & 0 deletions template-tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--index-url https://${PYPI_DOWNLOAD_USERNAME}:${PYPI_DOWNLOAD_PASSWORD}@nexus.rxrx.io/repository/pypi-all/simple
bandit
cookiecutter
flake8
mypy
roadie[cli]>=2.3.9
safety
yapf
52 changes: 52 additions & 0 deletions template-tests/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

set -e
set -x

python3.9 -m pip install -r requirements.txt

################################################################################
#### Test Case: Package With CLI
rm -rf test-package || true
python3.9 test_generate.py y

pushd test-package

python3.9 -m roadie.cli.main yapf dump -o ./style.yapf
python3.9 -m roadie.cli.main lock -u ${PYPI_DOWNLOAD_USERNAME} -p ${PYPI_DOWNLOAD_PASSWORD} --all
python3.9 -m roadie.cli.main venv -u ${PYPI_DOWNLOAD_USERNAME} -p ${PYPI_DOWNLOAD_PASSWORD} --use-venv
source venv/bin/activate

flake8
yapf --style ./style.yapf --parallel --diff -r .
mypy
bandit -r . -x /tests/,/venv/
safety check $(ls requirements/*.txt | xargs -i echo -n ' -r {}')
CONFIGOME_ENV=test pytest
pip install --upgrade tox
tox --parallel

popd

################################################################################
#### Test Case: Package Without a CLI
rm -rf test-package || true
python3.9 test_generate.py n

pushd test-package

python3.9 -m roadie.cli.main yapf dump -o ./style.yapf
python3.9 -m roadie.cli.main lock -u ${PYPI_DOWNLOAD_USERNAME} -p ${PYPI_DOWNLOAD_PASSWORD} --all
python3.9 -m roadie.cli.main venv -u ${PYPI_DOWNLOAD_USERNAME} -p ${PYPI_DOWNLOAD_PASSWORD} --use-venv
source venv/bin/activate

flake8
yapf --style ./style.yapf --parallel --diff -r .
mypy
bandit -r . -x /tests/,/venv/
safety check $(ls requirements/*.txt | xargs -i echo -n ' -r {}')
CONFIGOME_ENV=test pytest
pip install --upgrade tox
tox --parallel

popd
26 changes: 26 additions & 0 deletions template-tests/test_generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from cookiecutter.main import cookiecutter
from roadie.constants import FLAKE8_STYLE, YAPF_STYLE
import sys


def main():

yapf_configuration = ''
for k, v in YAPF_STYLE.items():
yapf_configuration += f'{k.lower()} = {str(v).lower()}\n'
flake8_configuration = ''
for k, v in FLAKE8_STYLE.items():
flake8_configuration += f'{k.lower()} = {str(v).lower()}\n'

cookiecutter_context = {
'repo_name': "test-package",
'description': "words go here",
'type': 'package',
'yapf': yapf_configuration,
'flake8': flake8_configuration,
'cli': sys.argv[1],
}
cookiecutter('..', no_input=True, extra_context=cookiecutter_context)


main()
129 changes: 129 additions & 0 deletions {{cookiecutter.repo_name}}/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# 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

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
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__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
4 changes: 4 additions & 0 deletions {{cookiecutter.repo_name}}/.yapfignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
venv*/
build/
dist/
.tox
6 changes: 6 additions & 0 deletions {{cookiecutter.repo_name}}/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM gcr.io/eng-infrastructure/rxrx-pyenv as test
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

ENV CONFIGOME_ENV=test
ENTRYPOINT [ "tox", "--parallel" ]
Empty file.
31 changes: 31 additions & 0 deletions {{cookiecutter.repo_name}}/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# {{cookiecutter.repo_name}}

{{cookiecutter.description}}

## Installation

### PIP

This package is installable via [Nexus](nexus.rxrx.io). You should configure your PIP using the instructions listed at
[roadie: PIP Configuration](https://github.com/recursionpharma/roadie#pip-configuration). Then, execute the following:

```bash
pip install {{cookiecutter.python_name}}
```

### Conda

You will need [anaconda cloud setup](https://github.com/recursionpharma/drug-discovery/wiki/Anaconda-Setup#setup-anaconda-cloud-locally)
in order to access the Recursion conda packages. Once that is setup you can install this library like so:

```
conda config --add channels conda-forge
conda config --add channels defaults
conda config --add channels recursion
conda install {{cookiecutter.python_name}}
```

## Developing

Please refer to [Developing Python at Recursion](https://github.com/recursionpharma/roadie/blob/trunk/Developing.md)
for all tasks related to development of this codebase.
2 changes: 2 additions & 0 deletions {{cookiecutter.repo_name}}/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MAJOR="0"
MINOR="0"
53 changes: 53 additions & 0 deletions {{cookiecutter.repo_name}}/conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{# raw is for ignoring templating with cookiecutter, leaving it for use with conda-build #}
{% raw -%}
{% set data = load_setup_py_data() %}
{%- endraw %}

package:
name: {{cookiecutter.python_name}}
{# raw is for ignoring templating with cookiecutter, leaving it for use with conda-build #}
{% raw -%}
version: {{ data['version'] }}
{%- endraw %}

source:
path: ..

build:
# If the installation is complex, or different between Unix and Windows, use
# separate bld.bat and build.sh files instead of this key. Add the line
# "skip: True # [py<35]" (for example) to limit to Python 3.5 and newer, or
# "skip: True # [not win]" to limit to Windows.
script: python setup.py install --single-version-externally-managed --record=record.txt
noarch: python
{%- if cookiecutter.cli == 'y' %}
entry_points:
- {{cookiecutter.python_name}} = {{cookiecutter.python_name}}.cli:cli
{%- endif %}

requirements:
build:
- python>=3.6
- setuptools
- roadie
run:
- python>=3.6
{% raw -%}
# dependencies are defined in setup.py
{% for dep in data['install_requires'] %}
- {{ dep.lower() }}
{% endfor %}
{# raw is for ignoring templating with cookiecutter, leaving it for use with conda-build #}
{%- endraw %}

test:
source_files:
- tests
requires:
- pytest
commands:
- pytest tests

about:
home: https://github.com/recursionpharma/{{cookiecutter.repo_name}}
summary: {{cookiecutter.description}}
23 changes: 23 additions & 0 deletions {{cookiecutter.repo_name}}/requirements/dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# These are the minimum specifications required to set up a development
# environment and includes things like depedencies required for testing, tools
# for ensuring security, formatting, and static checking compliance. Feel free
# to add anything that improves your developer experience.
#
# Do you like to test things in a notebook? Then, add `notebook` here. Do you
# find yourself inspecting objects a lot in the REPL? May I suggest `pdir2`. Do
# you like lots of colors and formatting options in your REPL, then get `rich`.
# Remember, it doesn't pay to be too specific here, roadie can be used to
# resolve your environment and make it reproducible for others.

-c main

bandit
flake8<4; python_version<'3.8'
flake8; python_version>='3.8'
mypy
pytest
pytest-cov
roadie
safety
types-pkg_resources
yapf
Loading

0 comments on commit 14aa05f

Please sign in to comment.