-
Notifications
You must be signed in to change notification settings - Fork 264
[pip] Add pip support (via venv) DEV-1146 #147
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
fd0c67d
[nginx][WIP] Add nginx static file planner
mikeland73 9c27cc4
Merge branch 'main' into landau/nginx-support
mikeland73 6fc2c47
Merge branch 'main' into landau/nginx-support
mikeland73 ce004d7
Merge branch 'main' into landau/nginx-support
mikeland73 c6b7e1e
Make nginx work on shell
mikeland73 5d6988a
Merge branch 'main' into landau/nginx-support
mikeland73 52ad9b3
Add readme, shell config, welcome message
mikeland73 000f6f7
Fix test
mikeland73 c59c142
Use correct config
mikeland73 6e619d0
Fix link
mikeland73 dbd0dbb
Bold
mikeland73 d9b4fc1
Fix test
mikeland73 23df777
Merge remote-tracking branch 'origin' into landau/nginx-support
mikeland73 81d62cd
Use same nginx for shell and build
mikeland73 0733406
Use shellrc for welcome message
mikeland73 5954fb1
Fix test
mikeland73 39b829d
Trim message
mikeland73 13cc813
Fix shell tests
mikeland73 7498191
Make sure the config runs from the nginx conf directory
mikeland73 0a1e6f9
Fix test
mikeland73 299d38b
Merge remote-tracking branch 'origin/main' into landau/nginx-support
gcurtis 4e8f765
planner/nginx: use os.TempDir() in shell helper
gcurtis 097065a
[pip] Add pip support (via venv) DEV-1146
mikeland73 09b0ebc
Add docs
mikeland73 cdc6a83
Remove extra space
mikeland73 95f1dd9
Merge branch 'landau/nginx-support' into landau/pip-support
mikeland73 8e3d4c4
Fix tests
mikeland73 31dd901
Fix test
mikeland73 6445f17
Merge branch 'landau/nginx-support' into landau/pip-support
mikeland73 f0c5c66
Merge branch 'main' into landau/pip-support
mikeland73 a20a04d
Fix tests
mikeland73 7c4c682
Merge branch 'main' into landau/pip-support
mikeland73 f033506
Merge branch 'main' into landau/pip-support
mikeland73 bca6633
Merge branch 'main' into landau/pip-support
mikeland73 dd73095
Requested changes
mikeland73 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Python Planner | ||
|
||
* We currently support shell and build using poetry and pip. We generally recommend using poetry, but will do our best to support both. | ||
|
||
# Python Poetry Planner | ||
|
||
## Detection | ||
|
||
* This planner looks for `poetry.lock` or `pyproject.toml` in your devbox.json directory. | ||
|
||
## Shell | ||
|
||
* poetry by default uses virtual environment so there should be no changes to dev workflow. | ||
|
||
## Build | ||
|
||
This planner uses pex to build an executable that has all dependencies. It looks for an entrypoint in the following order: | ||
|
||
* If there's a module with same name as the project, it uses that as the entrypoint. | ||
* If there's a script with same name as project, it uses that as the entrypoint. | ||
* Use first script in alphabetical order as the entrypoint. | ||
|
||
# Python Pip Planner | ||
|
||
## Detection | ||
|
||
* Looks for `requirements.txt` in your devbox.json directory. We default to python3 as provided by nix packages. | ||
|
||
## Shell | ||
|
||
* Uses venv (automatically created in .venv) to create a virtual environment. | ||
|
||
## Build | ||
|
||
* Uses pex to build an executable that has all dependencies. | ||
* Requires barebones `setup.py` | ||
* Uses `__main__` module in package that matches the lowercase `setup.py` name. Any dashes in the name are replaced with underscores. | ||
|
||
# Limitations | ||
|
||
Currently `build` does not support projects that depend on libraries with native extensions (e.g. `pandas`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2022 Jetpack Technologies Inc and contributors. All rights reserved. | ||
// Use of this source code is governed by the license in the LICENSE file. | ||
|
||
package python | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
"go.jetpack.io/devbox/boxcli/usererr" | ||
"go.jetpack.io/devbox/planner/plansdk" | ||
) | ||
|
||
// TODO: Doesn't work with libraries like Pandas that have C extensions | ||
// We get error | ||
// ImportError: libstdc++.so.6: cannot open shared object file: No such file or directory | ||
// possible solution is to set $LD_LIBRARY_PATH | ||
// https://nixos.wiki/wiki/Packaging/Quirks_and_Caveats | ||
type PIPPlanner struct{} | ||
|
||
// PythonPoetryPlanner implements interface Planner (compile-time check) | ||
var _ plansdk.Planner = (*PIPPlanner)(nil) | ||
|
||
func (p *PIPPlanner) Name() string { | ||
return "python.Planner" | ||
} | ||
|
||
func (p *PIPPlanner) IsRelevant(srcDir string) bool { | ||
return plansdk.FileExists(filepath.Join(srcDir, "requirements.txt")) | ||
} | ||
func (p *PIPPlanner) GetPlan(srcDir string) *plansdk.Plan { | ||
plan := &plansdk.Plan{ | ||
DevPackages: []string{ | ||
"python3", | ||
}, | ||
RuntimePackages: []string{ | ||
`python3`, | ||
}, | ||
ShellInitHook: p.shellInitHook(srcDir), | ||
} | ||
if err := p.isBuildable(srcDir); err != nil { | ||
return plan.WithError(err) | ||
} | ||
plan.InstallStage = &plansdk.Stage{ | ||
Command: "python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt", | ||
InputFiles: plansdk.AllFiles(), | ||
} | ||
plan.BuildStage = &plansdk.Stage{Command: pipBuildCommand} | ||
plan.StartStage = &plansdk.Stage{ | ||
Command: "python ./app.pex", | ||
InputFiles: []string{"app.pex"}, | ||
} | ||
return plan | ||
} | ||
|
||
func (p *PIPPlanner) isBuildable(srcDir string) error { | ||
if plansdk.FileExists(filepath.Join(srcDir, "setup.py")) { | ||
return nil | ||
} | ||
|
||
return usererr.New( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must be case-insen.... |
||
"setup.py not found. Please create a setup.py file to build your project." + | ||
" The distribution name must be a case-insensitive match of the package" + | ||
" (dir) name. Dashes are converted to underscores.", | ||
) | ||
} | ||
|
||
func (p *PIPPlanner) shellInitHook(srcDir string) string { | ||
venvPath := filepath.Join(srcDir, ".venv") | ||
venvActivatePath := filepath.Join(srcDir, ".venv", "bin", "activate") | ||
script := strings.TrimSpace(` | ||
echo "Creating/Using virtual environment in %[1]s"; | ||
python -m venv "%[1]s"; | ||
source "%[2]s";`) | ||
return fmt.Sprintf(script, venvPath, venvActivatePath) | ||
} | ||
|
||
var pipBuildCommand = strings.TrimSpace(` | ||
source .venv/bin/activate && \ | ||
pip install pex && \ | ||
PACKAGE_NAME=$(python setup.py --name | tr '[:upper:]-' '[:lower:]_') && \ | ||
pex . -o app.pex -m $PACKAGE_NAME -r requirements.txt | ||
`, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.venv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"packages": [], | ||
"shell": { | ||
"init_hook": null | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try adding
gcc
orbinutils
nix package when building with pandas.