Skip to content
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

Install into existing venv #161

Merged
merged 6 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"cookiecutter>=2.2.3",
"gcovr>=6.0",
"urllib3<2.0.0",
"requests>=2.31.0",
],
extras_require={
"dev": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
{
"__default_branch": "devel",
"project_name": "MyProject",
"fprime_branch_or_tag": "{{ cookiecutter.__default_branch }}",
"install_venv": ["yes", "no"],
"venv_install_path": "{% if cookiecutter.install_venv == 'yes' %}./venv{% else %}None{% endif %}",
"__prompts__": {
"project_name": "Project name",
"fprime_branch_or_tag": "F´ version (select branch or tag)",
"install_venv": "Install virtual environment?",
"venv_install_path": "Virtual environment install path"
"install_venv": "Install F´ development tools in current virtual environment?"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,68 @@
It does the following:
- Initializes a git repository
- Adds F' as a submodule
- Checks out the requested branch/tag
- Checks out the latest release of F'
- Installs the virtual environment if requested

@author thomas-bc
"""
import subprocess
import sys
import requests
from pathlib import Path

# Fail-safe in case user input is invalid branch/tag
DEFAULT_BRANCH = "{{ cookiecutter.__default_branch }}"
response = requests.get("https://api.github.com/repos/nasa/fprime/releases/latest")
latest_tag_name = response.json()["tag_name"]

PRINT_VENV_WARNING = False

# Add F' as a submodule
subprocess.run(["git", "init"])
print(f"[INFO] Checking out F' submodule at latest release: {latest_tag_name}")
subprocess.run(
[
"git",
"submodule",
"add",
"-b",
DEFAULT_BRANCH,
"--depth",
"1",
"https://github.com/nasa/fprime.git",
]
)

subprocess.run(
["git", "fetch", "origin", "--depth", "1", "tag", latest_tag_name],
cwd="./fprime",
capture_output=True,
)
# Checkout requested branch/tag
res = subprocess.run(
["git", "checkout", "{{cookiecutter.fprime_branch_or_tag}}"],
["git", "checkout", latest_tag_name],
cwd="./fprime",
capture_output=True,
)

if res.returncode != 0:
print(
"[WARNING] Unable to checkout branch/tag: {{cookiecutter.fprime_branch_or_tag}}"
)
print(f"[WARNING] Reverted to default branch: {DEFAULT_BRANCH}")
else:
print(
"[INFO] F' submodule checked out to branch/tag: {{cookiecutter.fprime_branch_or_tag}}"
)
print(f"[ERROR] Unable to checkout tag: {latest_tag_name}. Exit...")
sys.exit(1) # sys.exit(1) indicates failure to cookiecutter

# Install venv if requested
if "{{cookiecutter.install_venv}}" == "yes":
subprocess.run([sys.executable, "-m", "venv", "{{cookiecutter.venv_install_path}}"])
subprocess.run(
[
"{{cookiecutter.venv_install_path}}/bin/pip",
"install",
"-r",
"fprime/requirements.txt",
]
if sys.prefix != sys.base_prefix:
subprocess.run(
[
Path(sys.prefix) / "bin" / "pip",
"install",
"-Ur",
Path("fprime") / "requirements.txt",
]
)
else:
# Print warning after the following message so users do not miss it
PRINT_VENV_WARNING = True
else:
print(
"[INFO] requirements.txt has not been installed because you did not request it.",
"Install with `pip install -Ur fprime/requirements.txt`",
)

print(
Expand All @@ -67,9 +79,6 @@

Get started with your F' project:

-- Activate the virtual environment --
Linux/MacOS: source venv/bin/activate

-- Generate a new component --
fprime-util new --component

Expand All @@ -80,12 +89,8 @@
"""
)

if res.returncode != 0:
print(
"[WARNING] Unable to checkout branch/tag: {{cookiecutter.fprime_branch_or_tag}}"
)
print(f"[WARNING] Reverted to default branch: {DEFAULT_BRANCH}")
else:
if PRINT_VENV_WARNING:
print(
"[INFO] F' submodule checked out to branch/tag: {{cookiecutter.fprime_branch_or_tag}}"
"[WARNING] requirements.txt has not been installed because you are not running in a virtual environment.",
"Install with `pip install -Ur fprime/requirements.txt`",
)
1 change: 0 additions & 1 deletion src/fprime/util/cookiecutter_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ def new_project(parsed_args):
file=sys.stderr,
)
return 1
print(f"[INFO] New project successfully created: {gen_path}")
return 0


Expand Down
Loading