Comments (15)
I was watching this thread without speaking up. I would also like a way to ensure that a specific version of Python is installed from another action, to simplify the requirements for others who depend on the action.
from setup-python.
It's not particularly pretty, but I think I've found a way to include setup-python
as a dependency and execute it.
Add the repository as a dependency and specify a version.
npm i --save actions/setup-python#v2.0.1
It will get added to package.json like this.
"dependencies": {
"setup-python": "github:actions/setup-python#v2.0.1"
}
Add a script in package.json to build setup-python.
"scripts": {
"build-setup-python": "npm install --prefix node_modules/setup-python && npm run build --prefix node_modules/setup-python"
...
}
Install and build (Add this to CI, too)
npm install
npm run build-setup-python
It should build and be usable as in this example:
import * as core from '@actions/core'
import * as setupPython from 'setup-python/lib/find-python'
async function run(): Promise<void> {
try {
const installed = await setupPython.findPythonVersion('3.x', 'x64')
core.info(`Successfully setup ${installed.impl} (${installed.version})`)
} catch (error) {
core.setFailed(error.message)
}
}
run()
from setup-python.
fwiw I've been pretty disappointed with the reusability of github actions, the design choices of having executable git repos make it really difficult to compose actions (instead they must be copy pasted everywhere) and with a lack of support for template repositories (such as with azure pipelines) means there really isn't any solution for things like this beyond adding more to copy paste
my particular usecase for having an in-process runnable setupPython is to patch a (imo) pretty glaring omission in this action: setting up in-development versions. the current implementation requires copy pasting two actions both with disparate complex conditionals. the ideal case would be a single action which just works (by calling out to setup-python in some way when it cannot handle the particular versions itself): deadsnakes/issues#123
from setup-python.
Or it should support triggering another action from a javascript action, e.g.
import * as actions from '@actions/actions'; // <-- this is new
import * as exec from '@actions/exec';
await actions.run('setup-python', {python-version: '2.x'});
await exec.exec('pip install ...');
from setup-python.
@brcrista It feels a bit hacky so I don't think it's a great solution long term. It would be nice if the logic existed in an actions/tookit module and this action was just a wrapper that called it.
For my own use case, I'm planning to move away from executing Python with actions/exec
and convert to Typescript. So eventually this will be a non-issue for me, but others may still appreciate a better solution in future.
from setup-python.
@brcrista Looks like a good solution to me, and your reasoning makes sense. Composite actions appears to solve this quite well. 👍
As I mentioned here, I did end up rewriting my actions in Typescript, which avoided the problem altogether.
from setup-python.
@brcrista Composite actions do work and it does make sense to not publish an NPM package.
One downside of using composite actions is that afaik inputs have to be duplicated. Is there a way to automatically pass the inputs of the composite action to all sub actions?
from setup-python.
@peter-evans right, npm
supports installing straight from a GitHub repo like you've found.
I think if we were publishing as an NPM package, we would want to do more work around giving the action a proper API and versioning the NPM package around that. So, if the existing path that npm
provides is working well, I think that's a better alternative than taking on the dev and maintenance cost of a full-on package.
from setup-python.
That makes sense -- just a matter of whether the time spent and added complexity is worth it. I'm going to close this as we're not planning on this work right now, but we'll keep this in mind if people keep asking for it.
from setup-python.
FWIW one way in another action we found to compose actions is to simply download the resulting dist/index.js
file: ruby/setup-ruby#33 (comment)
from setup-python.
Check out this issue for "composite actions:" actions/runner#438. There's also a working design proposal: actions/runner#554
I think this would address @peter-evans 's and @foolip 's scenarios. @asottile , this isn't the same templating model as Azure Pipelines, but I think that could address your use case also.
from setup-python.
This is currently broken. #306 changed the build to use ncc instead of tsc which bundles everything into one file without any exports.
Add the repository as a dependency and specify a version.
npm i --save actions/setup-python#v2.3.1
It will get added to package.json like this.
"dependencies": {
"setup-python": "github:actions/setup-python#v2.3.1"
}
It should be usable as in this example:
import * as core from '@actions/core'
import * as setupPython from 'setup-python/dist/setup'
async function run(): Promise<void> {
try {
const installed = await setupPython.findPythonVersion('3.x', 'x64')
core.info(`Successfully setup ${installed.impl} (${installed.version})`)
} catch (error) {
core.setFailed(error.message)
}
}
run()
from setup-python.
@peter-evans right,
npm
supports installing straight from a GitHub repo like you've found.I think if we were publishing as an NPM package, we would want to do more work around giving the action a proper API and versioning the NPM package around that. So, if the existing path that
npm
provides is working well, I think that's a better alternative than taking on the dev and maintenance cost of a full-on package.
I think it would make sense to revisit this issue. The workaround broke and because there are no tests it wasn't noticed. If there was a NPM package this wouldn't have happened. I'd be happy to help, please let me know if there's anything I can do.
from setup-python.
I just put together an example using composite actions to set up a version of Python before running some other steps. @bexnoss @peter-evans does this help with what you're trying to do?
name: 'setup-python-composite'
description: 'Sample code for a composite action that requires some version of Python'
runs:
using: "composite"
steps:
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- run: python --version
shell: bash
- uses: ./javascript-action
Here's an example workflow run with the action.
There's a few reasons I'd prefer to stick with composite actions rather than publishing an NPM package:
- Composite actions is a first-class concept that should work with all actions. (Not all actions are implemented in JS.) If the first-class reusability concept isn't working we should improve it.
- Avoid multiplying concepts unnecessarily
- Avoid the extra maintenance cost of making sure the NPM package works edit: and keeping the versioning accurate
from setup-python.
@bexnoss you do need to pass inputs to the sub-actions manually using ${{ inputs.xxx }}
(docs).
I'm going to close out this issue since it sounds like we're all set on the topic of the NPM package.
from setup-python.
Related Issues (20)
- Version not found when using new arm-based linux runners (ubuntu 22.04) HOT 4
- Add Python 3.12.4 (released 2 days ago) HOT 6
- [Feature Request] Add Python debug builds with `Py_DEBUG` flag HOT 1
- Python 3.12.4: Extract downloaded archive; gzip: stdin: not in gzip format HOT 22
- is python 3.12.4 download assets broken HOT 7
- Python 3.13 fails to install on windows: Offset to Central Directory cannot be held in an Int64. HOT 6
- Verify checksum of downloaded version archive HOT 1
- Support os-release standard HOT 5
- setup-python CI workflows have been broken for more than 2 months HOT 1
- Sporadically missing patch versions on python-versions for arm64 HOT 5
- `python-version-file` does not support multiple versions HOT 2
- Cannot parse version number from TOML 1.0.0 pyproject.toml file HOT 5
- Associate .py with python on Windows HOT 1
- Ability to set desired version of pip, or to not update it at all HOT 3
- Python version '3.12.x' with architecture 'arm64' was not found for Ubuntu 24.04 HOT 3
- Occasionally getting `candidates is not iterable` error HOT 5
- Self-hosted Windows Runner Fails to Install Python HOT 6
- Python 3.9/3.10 on Darwin runners fails: Error: dyld[78135]: Library not loaded: /usr/local/opt/gettext/lib/libintl.8.dylib HOT 6
- Poetry cache is not invalidated while cached virtual environment's name / location is not correct HOT 6
- The version '3.11.6' with architecture 'x64' was not found for this operating system HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from setup-python.