简体   繁体   English

在Github中,我可以从存储库之外的其他仓库运行python脚本吗?

[英]In Github, can I run a python script from a different repo than where it's stored?

Let's say I have aa repo that has a python script stored in it, then another repo where I want to run that script, such as below within repo1. 假设我有一个存储了python脚本的存储库,然后是另一个我想运行该脚本的存储库,例如repo1中的以下代码。

sh "python repo2/src/python.py --arg value --arg2 value2"

I'm sorry. 对不起。 I know this seems like a simple question, but I either don't know how to phrase my question or else it's just not possible. 我知道这似乎是一个简单的问题,但是我要么不知道如何表达我的问题,要么就不可能。

Thank you. 谢谢。

More info: The script is part of a repo and this is where it needs to live, especially to stay modular. 更多信息:脚本是回购的一部分,这是脚本存在的地方,尤其是保持模块化的地方。 The other repo is a for a pipeline and it has a groovy Jenkinsfile. 另一个存储库是用于管道的,它具有一个普通的Jenkinsfile。 This is where I want to pull that script and run in within the Jenkinsfile 这是我要提取该脚本并在Jenkinsfile中运行的地方

You can write a bash script that moves into the desired directory for you and executes the file from there. 您可以编写一个bash脚本,该脚本将移至所需的目录并从该目录执行文件。 Let's say you want to execute program2.py in another directory from where you actually want to call it, then you could write a simple bash script to do this for you: 假设您要在另一个实际要调用它的目录中执行program2.py,那么您可以编写一个简单的bash脚本来为您执行此操作:

#!/bin/sh
cd path/to/dir/where/program2.py/is/stored
python program2.py --arg value

Save this bash script with a .sh file ending. 保存此bash脚本,并以.sh文件结尾。 Then just make it executable with chmod +x and make sure it's in the same directory as the directory where you want to execute it, of course, and you should be good to go! 然后,只需使用chmod +x使它可执行,并确保它与您要执行该目录的目录位于同一目录中,那么您应该一切顺利!

假设您有一个正在读取文本文件的python脚本,您可以按照以下代码执行代码,它将起作用

python /dir/to/your/file.py /dir/to/another_file.txt 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何简单地从 github 回购中运行 python 脚本并执行操作 - How do I simply run a python script from github repo with actions 如何从他们的 GitHub 存储库中获取 Helm 的二进制文件? - How can I get Helm's binary from their GitHub repo? 从Github存储库中检出jenkinsfile时,jenkinsfile可以从同一存储库中调用/启动python脚本吗? - When checking out a jenkinsfile from a Github repo, can the jenkinsfile call/start a python script from that same Repo? 如何从不同的脚本在 python 中运行 3 个函数? - How can I run 3 functions in python from a different script? 如何调用存储在我的网络上的不同 python 脚本? - How can I call a different python script that is stored on my network? 如何通过 python 脚本从现有分支克隆 github 回购分支 - How to clone github repo branch from existing branch by python script 我从 Github 将 repo 导入到 Colab 当我运行它时没有响应 - I import repo from Github to Colab When I run it there is no response 我无法运行来自 github 的微软 python 扩展代码 - I can not run the microsoft python extension code from github 如何直接将文件从 colab 复制到 github 存储库? (可以将笔记本保存在 Github 存储库中) - How can I copy a file from colab to github repo directly? (It is possible to save the notebook in the Github repo) 将硒与python结合使用,如何从JS中声明的HTML中获取Var <script> element - Using selenium with python, how can I get Var from HTML where it's declared in a JS <script> element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM