Deploy Python app to Heroku with extra pip install - python

I'm trying to implement Deploy to Heroku functionality for my Python application:
https://github.com/jet-admin/jet-bridge/tree/heroku
It woks OK if just use requirements.txt to install dependencies, but it require me to modify my requirements.txt to include some extra packages that i normally don't need (psycopg2, mysqlclient).
Is it possible not to include all requirements in requirements.txt, but install it with some extra command? I've tried adding postdeploy script which will perform pip install command, but after deploy succed my application says that psycopg2 is not installed (thought i installed it in postdeploy command).

The Heroku Python buildpack has a hook where you can execute extra commands after the initial slug compilation.
To use it, you can add a bin/post_compile file, putting inside the shell commands for installing the extra packages.
You can even make it depend on an environment variable, like:
# assuming you have files mysql-requirements.txt and postgres-requirements.txt
if [ "$JET_BRIDGE_DB" == "mysql" ]; then
echo "Installing Python dependencies for MySQL support"
pip install -r mysql-requirements.txt
else
echo "Assuming Postgres database, installing Python dependencies"
pip install -r postgres-requirements.txt
fi
Read more:
Buildpacks: https://devcenter.heroku.com/articles/buildpacks
Heroku Python Buildpack: https://github.com/heroku/heroku-buildpack-python
Slug compilation: https://devcenter.heroku.com/articles/slug-compiler

Related

How to install local python packages when building jobs under Github Actions?

I am building a python project -- potion. I want to use Github actions to automate some linting & testing before merging a new branch to master.
To do that, I am using a slight modification of a Github recommended python actions starter workflow -- Python Application.
During the step of "Install dependencies" within the job, I am getting an error. This is because pip is trying to install my local package potion and failing.
The code that is failing if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
The corresponding error is:
ERROR: git+https#github.com:<github_username>/potion.git#82210990ac6190306ab1183d5e5b9962545f7714#egg=potion is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with bzr+http, bzr+https, bzr+ssh, bzr+sftp, bzr+ftp, bzr+lp, bzr+file, git+http, git+https, git+ssh, git+git, git+file, hg+file, hg+http, hg+https, hg+ssh, hg+static-http, svn+ssh, svn+http, svn+https, svn+svn, svn+file).
Error: Process completed with exit code 1.
Most likely, the job is not able install the package potion because it is not able to find it. I installed it on my own computer using pip install -e . and later used pip freeze > requirements.txt to create the requirements file.
Since I use this package for testing therefore I need to install this package so that pytest can run its tests properly.
How can I install a local package (which is under active development) on Github Actions?
Here is part of the Github workflow file python-app.yml
...
steps:
- uses: actions/checkout#v2
- name: Set up Python 3.8
uses: actions/setup-python#v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
...
Note 1: I have already tried changing from git+git#github.com:<github_username>... to git_git#github.com/<github_username>.... Pay attention to / instead of :.
Note 2: I have also tried using other protocols such as git+https, git+ssh, etc.
Note 3: I have also tried to remove the alphanumeric #8221... after git url ...potion.git
The "package under test", potion in your case, should not be part of the requirements.txt. Instead, simply add your line
pip install -e .
after the line with pip install -r requirements.txt in it. That installs the already checked out package in development mode and makes it available locally for an import.
Alternatively, you could put that line at the latest needed point, i.e. right before you run pytest.

CKAN docker compose with custom extensions

I have been trying to customize the default CKAN docker image to include my prefered extensions. The problem is that the precedence of installing pip packages, configuring the ini files and, building and running the main CKAN image is not clear for me.
I have tried adding a layer to the Dockerfile (see below) but extensions are not available after running docker-compose up. The add-extensions.sh file contains pip install commands for each extension.
RUN sh $CKAN_VENV/src/ckan/contrib/docker/add-extensions.sh
I have also tried to include my commands in the docker-compose file itself, inside the ckan service, as follows.
command: >
sh -c "
pip install ckanext-geoview &&
pip install ckanext-datarequests &&
ckan config-tool "/etc/ckan/production.ini" -f "/etc/ckan/custom-config.ini" &&
ckan config-tool "/etc/ckan/production.ini" -s app:main -e ckan.plugins='stats text_view image_view recline_view datastore datapusher resource_proxy geo_view datarequests' &&
ckan -c /etc/ckan/production.ini run --host 0.0.0.0"
But this is not working either. So what is the recommended way of including custom plugins inside the default CKAN image?

Pip install from git repository without local files

I am trying to install a python module from a git repository, however it seems that the only way to successfully do this is to add -e to the command which leaves behind local files. When I remove the -e it says it installs, but I am left without any files and it fails to import. Here is my command:
pip install -e git+http://gitlab.valk.net/operations/cilib.git#egg=cilib
Further note, when the -e is left off, there is only an egg-info file in site-packages but not files. Is anyone aware of how you do this?
Thanks

Heroku: Run a Rails application with a Python script on the same instance

I have a Python script in the /app/bin directory of my Rails app that contains a requirements.txt file that includes all of the dependencies it relies on.
How do I get it to run on the same Heroku instance that my Rails app currently runs on (my Rails app call the python script occasionally).
Here's what I've tried so far:
Put the requirements.txt file in the / dir. Didn't install any python dependencies
Tried running heroku run bash and then running pip install -r requirements.txt. Got the message pip command not found.
Tried installing pip through the bash interface using sudo python get-pip.py after curling the script as suggested on the pip installation site. Didn't work -- not surprisingly, they don't support sudo commands on the instance.
I know Heroku is supposed to support pip out of the box, but it doesn't seem to do anything with the requirements.txt file once it's detected a Ruby app.
You can use the Heroku Buildpack Multi to run both the python and the ruby application on the same instance using their respective buildpacks.
keep requirements.txt file in project folder. In my case project name is stock09. so requirements.txt file in side of stock09
heroku login
heroku buildpacks:set heroku/ruby
heroku buildpacks.set heroku/python
heroku buildpacks
git add .
git commit -m " "
git push heroku master
now it work

How to point pip at a Mercurial branch?

I'm trying to install my application via pip to a virtualenv for testing.
Works fine for installing the default or tip like so:
pip install -e hg+https://username#bitbucket.org/username/app_name#egg=app_name
But is there any way to point to a branch, rather than just getting the tip. Not sure if this would be a mercurial thing, bitbucket, or pip.
Bitbucket allows for downloading of a tagged version of the code, but I can only get it to work while logged into the browser. I tried installing from a tag tar.gz like so:
pip install https://username#bitbucket.org/username/app_name/get/bbc4286a75db.tar.gz
but even after entering my password it returns a 401 Unauthorized (Its a Private Repo)
In official pip documentation in section VCS Support:
Mercurial
The supported schemes are: hg+http, hg+https, hg+static-http and
hg+ssh:
-e hg+http://hg.myproject.org/MyProject/#egg=MyProject
-e hg+https://hg.myproject.org/MyProject/#egg=MyProject
-e hg+ssh://hg#myproject.org/MyProject/#egg=MyProject
You can also specify a revision number, a revision hash, a tag name or
a local branch name:
-e hg+http://hg.myproject.org/MyProject/#da39a3ee5e6b#egg=MyProject
-e hg+http://hg.myproject.org/MyProject/#2019#egg=MyProject
-e hg+http://hg.myproject.org/MyProject/#v1.0#egg=MyProject
-e hg+http://hg.myproject.org/MyProject/#special_feature#egg=MyProject
The syntax is the same when specifying repo at the command line
pip install -e hg+http://hg.myproject.org/MyProject/#special_feature#egg=MyProject
and it works when not using -e option starting from version 0.8.2.

Categories

Resources