Overriding package libraries in Google App Engine project - python-3.x

I am writing a Google App Engine Django REST Framework project that uses external libraries through requirements.txt.
In one of the of files in a module installed in requirements.txt, I am manually editing some code there. How do I get GAP to use this modified version instead of original one.
The way I am doing this is installing the packages in a folder called lib, modifying the package inside it and then creating a file called appengine_config.py which contains this:
from google.appengine.ext import vendor
vendor.add('lib')
But when I deploy it, it still uses the original package in requirements.txt. Any idea how to make this work?

GAE will use requirements.txt and install those libraries in the lib folder when you deploy. That is just how it works.
Nothing prevents you from deploying code outside the lib folder. You can structure your project like this:
GAE_folder:
-- app.yaml
-- requirements.txt
-- lib
-- my_app
-- my_custom_lib

Related

How to download npm packages instead of using the command line

I'm working in a completely offline environment & lately, I've had to code some react applications. I wonder if there is a way to download npmjs packages manually without using the command npm install <package-name>.
For example, while I'm coding with python in the same offline env, I'm downloading everything from PyPi manually & use the .whl in my offline environment using removable devices from one online environment to the offline environment.
I'll appreciate for any help or direction to the solution.
You need to download their source from the github. Find the main file and then include it in your main file.
You need to find the source and go through the package.json file. There you can find which is the main file. So that you can include that in your application.
To include example.js in your app. Copy it into your application folder.
Once you do that, your requirements will just be:
var moduleName = require("path/to/example.js")
It will always look for a node_modules directory at the root of your app (and a few other places as well).
It's important you download the full repo and not just the lib folder if you plan to use it this way since the package.json file is used to find the main entry point. As long as the repository has a valid package.json file it should work.[

node_modules developing dependency package

I am studying an aplication that has some dependencies. I want to make some changes on one dependency locally.
I tryed to make a symbolic link inside the main application's node_modules direct to the dependency folder, where I have the folders with compiled code (es and lib) using this command ln -s dependency_folder main_app/node_modules/dependecy.
It doesn't work and raises an error:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/warnings/invalid-hook-call-warning.html for tips about how to debug and fix this problem.
Is this a right way to develop a dependency package, or I am doing it wrong.
I realize that there is no problem to link to a dependency package. What happened here is that the project source files are out of date. Compiled dependencies are up to date on NPM, on git the sources are outdated.
i will leave this message just for the records.

node or npm: How to see the source code of a package installed

Like in python i install a package using
pip install django
inside a virtualenv,
Then it puts all the files in site-packages folder. and then i can import the package using
from django.core import mail
But i can easily browse the code of django/core in site-packages
Similarly if I install a package using npm can i see the source of that
Eg:
import React, { useEffect } from "react";
Now i want to see the react file and go through the React and useEffect
Is it possible
I do not have background in Python. So, can't explain or compare in Python way. But, yes! You can read or go through the source code in most of the cases.
Now, talking about the specific example you mentioned in question - React. Things are little complicated as we're talking about one of the popular library. You may wouldn't find React.js or react.js file directly. But, that doesn't mean you can read the source code. Let's do it.
Create an application that has react as dependency (You can create an application using create-react-app).
In this application, you'll have node_modules folder. Within this node_modules, you'll have folder after the name of dependency e.g. react. Go inside this folder.
You'll find the package.json file. Open it and look for main. The main is an entry point of the program/package. It mentioned index.js. So, let's open the index.js file.
If you open the index.js, you'll see that based on environment, they're requiring the react.production.min.js or react.development.js file. Open this react.development.js file from cjs folder.
In this file, do a search for useEffect. You will find a function with the same name.
But, I wouldn't recommended you to read the code in this way, if you're planning for React. You may try this solution. Also, if you're planning to read the source code as starting point, why not start with simple and easy to read packages? And don't forget that if not all then most of the packages are there on GitHub and on NPM website, you'll see the link for the Repository.

How to install and configure external modules within React + Webpack

I've got quite some experience in (web) development (Java, ASP.NET and PHP amongst all), and fairly new to React and Node JS.
Although I did multiple tutorials and read multiple articles, I feel like I'm missing some point here and there. Currently I'm working on a React app which implements a nice HTML template I found.
One React tutorial I did used Webpack for building and deploying the app (local). This works nice, does the job of transpiling ES6 (.jsx) and SASS using babel. So far so good :)
My template has an image slider (Owl Carousel), so I installed the react-owl-carousel module.
This gave me quite some problems with jQuery (also installed as a module).
After several attempts to fix this I decided to move on to another slider module, React Awesome slider.
I used the module as the README.md explained. But upon building it (npm run build), I got an error that the .scss file within react-awesome-slider could not be transpiled. A message like "are you missing a loader".
So I installed sass, node-sass, sass-loader etc etc and configured these in my webpack.config.js.
I also noticed the react-awesome-slider module within node-modules contained a webpack.config.js.
Long story so far, sorry, now to the essence of this question.
In what way can the modules installed (like react-awesome-slider) be considered "black boxes"?
It doesn't feel logical that all the modules get build when building the main app. The "exclude: /node_modules/," config in webpack.config.js prevents this, not?
So why does the react-awesome-slider give an error about .scss transpiling? I had no .scss rule in my webpack config then.
Will all dependend modules automatically get installed when installing a new module? So when I run "npm i react-awesome-slider --save-dev", will its dependencies also be installed? Or is this not necessary? And do I need to update (webpack) configuration after installing a new module? Or is it really black box and "self-containing"?
Any help would greatly be appreciated!!! Maybe there is a good react-webpack sample app on Github or something like that?
That also confusing me for a really long time. Here are some answers to your question.
people publish packages to the NPM, so a module your project depends on
can be pre-builded or source code, it depends. I have checked react-awesome-slider, it's main field in package.json is dist/index.js, directly import it won't cause an issue because there are no SCSS files.If you follow the CSS module usage instruction you have import react-awesome-slider/src/styles and you will find src/styles.js file import ../styled.scss,so webpack will load it with SCSS loader which you have not configured, that's why an error occurred.
while you install modules, npm will go
through its dependency tree, install its dependencies, dependencies'
dependencies, until there's no more dependency module to install. before npm 3.0 the node_module folder is tree structure reflects the dependency tree, but it causes problems that many modules relay on the same dependency, npm will download and save too many same files, after version 3.0 it becomes flat(release note here, search flat keyword).
You don't need to update your webpack config after you install a dependency cause webpack build process will handle it with file dependency tree. You have installed a package and import it in your activation code, file there will be handle( with its package.json main field file as an entry), you have installed a package without using it or import it in a dead file(dead file means you cannot find it from webpack entry file), it will be ignored by webpack as it's dead code.
I have too many confuse until I read npm docs. Good luck to you.
Node modules are build to execute packages.When the are compiled they have proper configuration to handle extensions that are imported in it and when you import something like .scss in your main app then it does not know about that extension then your webpack need rules to include that extensions.
It does exclude node_modules as the are pre-converted pr pre build.
More over webpack is bit tough so developers create CRA Have look at it.

How to package python3 modules for google app engine

I'm trying to figure out how to add a internal package to a Google App Engine deployment with Python 3 (standard).
For Python 2 the way to package modules was using a local lib/ folder and appengine_config.py. This seems not to work anymore for Python 3? At least my app cannot find modules which are in the lib/ folder.
For Python 3 it's possible to just pip3 install -t . the package. But this gets really messy as all packages are just installed in the app root and will also be added to the git repository of our app.
We cannot use requirements.txt as the module is internal and will not be available on PyPI.
Is there another way to package modules for Google App Engine using Python 3?
The Python 3.7 Standard runtime is an "idiomatic" Python runtime, which means it doesn't automatically add the special lib directory to the search path for modules.
You should continue "vendoring" your private modules into a lib directory, but you'll need to make a change to how you import them.
If your private package is foobar, and you've done pip install -t lib foobar, then in your project, instead of:
import foobar
you do:
import lib.foobar
(You'll also need to add an empty __init__.py file to your lib directory, to make it a module.)

Resources