Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New project initialization #1

Merged
merged 15 commits into from
Oct 1, 2019
Merged

New project initialization #1

merged 15 commits into from
Oct 1, 2019

Conversation

dongbohu
Copy link
Contributor

@dongbohu dongbohu commented Sep 12, 2019

This PR includes the initialization files for adage backend in Python 3. Most of the files involved are boilerplate code. The files that should be reviewed include:

├── adage
│   ├── adage
│   │   ├── config_template.yml: template config file
│   │   ├── settings.py: django settings
│   │   ├── urls.py: URLs supported by current project  
│   ├── analyze
│   │   ├── models.py: copied from "adage" repo, converted to Python 3
│   │   ├── serializers.py: a simple DJango REST framework serialization demo
│   │   └── views.py: a simple DJango REST framework serialization demo
│   ├── genes
│   │   ├── models.py: copied from `django-genes`, converted to Python 3
│   ├── organisms
│   │   ├── models.py: copied from `django-organisms`, converted to Python 3
│   ├── requirements.txt: PyPI packages
├── deployment
│   ├── nginx.conf: a simple Nginx config file 
│   ├── run.sh: a summary of deployment steps
│   └── supervisor-adage.conf: config file for gunicorn daemon
├── .circleci
│   ├── ci_django.yml: Django config file for CircleCI 
│   ├── config.yml: CircleCI config

Here is a demo site that I built on AWS based on this PR:
https://py3-adage.greenelab.com/api/v1/

Right now it only supports machine learning model API (enabled by Django REST framework):
https://py3-adage.greenelab.com/api/v1/mlmodels/

@dongbohu
Copy link
Contributor Author

@mhuyck: By the way, I copied genes and organisms from django-genes and django-organisms because the PyPI packages are still being used by tribe, which is running Python 2. When Tribe and Adage are both migrated to Python 3, we can factor out genes and organisms as PyPI packages that support Python 3.

Copy link
Collaborator

@mhuyck mhuyck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have lots to say here. You can maybe see the evolution of my thinking as I gradually remember what all of these parts are.

I think the majority of my notes are questions to help make sure I'm on the same page about where we are headed and how we plan to do deployment in this version. I think there are a relatively small number of specific code changes I'm suggesting and only one or two outright errors that I caught.

This is great work. Thank you for bringing us into the Python 3 and Django 2.2 future, @dongbohu!

SECRET_KEY = config.get('secret_key', 'django_secret_key')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config.get('debug', True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: instead of a stern SECURITY WARNING comment in the code that nobody but a developer will see, should we make the codebase secure by default and make DEBUG default to False? To make things a little easier for developers, we could put a comment about setting the 'debug' config parameter to True in the config_template.yml file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I realize this is boilerplate... just wondering if and when we want to uphold certain standards of deployability.

(Also: I know we had this hard-coded to True in adage-server. I'm trying to think through the steps toward our end goal explicitly and make sure we improve our final product this time based upon what we learned with our first effort.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. In the default settings.py (generated by django-admin startproject command), this section was:

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

which is probably where the lines in adage came from. I found it a little annoying when deploying the production server, because I had to modify settings.py directly. That is why I put this option in config.yml now.

This is also the reason why the default is True here, because I try to keep it consistent with the original setting.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm totally fine with defaulting it to True for now. It will be a while before we come to the point of deploying this in production. At the same time, that time delay is why I was thinking it might be good to change the default now so we don't forget. After the code review is done we tend to not revisit questions like this.

Is there a place for us to keep notes about things we want to remember to do before production deployment? If you prefer to leave the development default for now then maybe we should have a list of reminders about this and other things we know we need to come back to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhuyck, I created issue #5 to keep track of the config of production server. Please feel free to comment on it.

adage/adage/config_template.yml Show resolved Hide resolved
adage/adage/config_template.yml Outdated Show resolved Hide resolved
'corsheaders',
'organisms',
'genes',
'analyze',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename this unless you foresee any major trouble arising from that. What I didn't understand when building models initially is that these things are all objects, so the names should all be nouns. Also, analyze or its noun form analysis isn't necessarily the most useful name. I'm going to look through how this is used and see if I can think of something better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I simply copied this line from original Adage settings. analysis is one option, but it seems a little too generic. @cgreene, do you have any preference on the name of this Django app?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this app essentially the place where most of the endpoints live? It's too generic for me to remember what goes in it now. 😭

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgreene: Yes, you are right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a new django project, would this just be called adage? I think the django devs might have changed how apps were named by default a bit after this project was created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Django's jargon, adage is the project's name, analyze, genes, organisms are App's name. The app's name doesn't really matter to the frontend. It only matters to backend development. So we can name it anything, but still we want it to be a reasonable one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really glad we're doing this review. This is the first time for this particular naming decision because the first time around actually predates the GreeneLab code review policy!

I jabbed the original developer in the ribs and asked "what were you thinking?" (We go way back.) He mumbled something about it seeming good at the time because we didn't really know what the data models were going to look like.

The naming is indeed generic because it encompasses everything. I wonder if it makes sense to split the backend into two Django "apps" because there is something of a logical split between the annotated "source data" (Samples, essentially, which we pulled from ArrayExpress queries, along with Experiment, and all of the SampleAnnotation models) and "ADAGE model data" (MLModel, Signature, Activity, and the rest). That separation of concerns would help our system design by giving a stronger core purpose to the two parts of the backend.

We should also keep in mind that the Django framework was not originally written for single page apps. Our goal here should be to make the best use of the capabilities it provides without getting too hung up on parts that are not relevant to us as we aim to build a solid REST API.

Maybe we are wandering outside the scope of this pull request. Does it make sense to resolve this question via an issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I suggest we follow the default Django 2.2 project layout @cgreene points out and dispense with the idea of a separate "app" (currently named analyze). The possibility of separate app modules that Django offers are very useful as reusable modules and they make sense for something portable like genes and organisms, but the bulk of the Adage API is probably inseparable from the rest of the back end code.

adage/adage/settings.py Show resolved Hide resolved
adage/analyze/models.py Show resolved Hide resolved
adage/analyze/models.py Outdated Show resolved Hide resolved
adage/analyze/models.py Show resolved Hide resolved
adage/analyze/models.py Outdated Show resolved Hide resolved
.circleci/config.yml Show resolved Hide resolved
Copy link
Contributor Author

@dongbohu dongbohu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhuyck: I think I've addressed most of your comments. To keep this PR from growing too big, I will add new issues to keep track of some questions that you raised. Please let me know if you have any other comments. Thanks.

Copy link
Collaborator

@mhuyck mhuyck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still need to decide how we're going to proceed with the analyze "app". We should either fold that code into the adage project now or document it as an issue to be fixed in an upcoming PR.

I'm also not clear on the resolution for where to put those regex lines I noted in adage/genes/models.py.

Everything else seems to be addressed.

@dongbohu
Copy link
Contributor Author

dongbohu commented Oct 1, 2019

@mhuyck: I have created a few new issues to keep track of the two questions that I haven't addressed:
https://github.com/greenelab/py3-adage-backend/issues
Please feel free to comment on them (and add new ones if necessary).

@dongbohu
Copy link
Contributor Author

dongbohu commented Oct 1, 2019

I also added a new line in settings.py because I realized that I missed the line of CORS middleware.

@mhuyck
Copy link
Collaborator

mhuyck commented Oct 1, 2019

Looks good. Thanks @dongbohu!

@dongbohu dongbohu merged commit 177bb38 into master Oct 1, 2019
@dongbohu dongbohu deleted the dhu/init branch October 1, 2019 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants