Skip to content
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
24 changes: 18 additions & 6 deletions openc3/lib/openc3/models/plugin_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ def self.install_phase2(plugin_hash, scope:, gem_file_path: nil, validate_only:
needs_dependencies = pkg.spec.runtime_dependencies.length > 0
needs_dependencies = true if Dir.exist?(File.join(gem_path, 'lib'))

# Handle python requirements.txt
if File.exist?(File.join(gem_path, 'requirements.txt'))
# Handle python dependencies (pyproject.toml or requirements.txt)
pyproject_path = File.join(gem_path, 'pyproject.toml')
requirements_path = File.join(gem_path, 'requirements.txt')

if File.exist?(pyproject_path) || File.exist?(requirements_path)
begin
pypi_url = get_setting('pypi_url', scope: scope)
if pypi_url
Expand All @@ -226,11 +229,20 @@ def self.install_phase2(plugin_hash, scope:, gem_file_path: nil, validate_only:
end
end
unless validate_only
Logger.info "Installing python packages from requirements.txt with pypi_url=#{pypi_url}"
if ENV['PIP_ENABLE_TRUSTED_HOST'].nil?
pip_args = "--no-warn-script-location -i #{pypi_url} -r #{File.join(gem_path, 'requirements.txt')}"
if File.exist?(pyproject_path)
Logger.info "Installing python packages from pyproject.toml with pypi_url=#{pypi_url}"
if ENV['PIP_ENABLE_TRUSTED_HOST'].nil?
pip_args = "--no-warn-script-location -i #{pypi_url} #{gem_path}"
else
pip_args = "--no-warn-script-location -i #{pypi_url} --trusted-host #{URI.parse(pypi_url).host} #{gem_path}"
end
else
pip_args = "--no-warn-script-location -i #{pypi_url} --trusted-host #{URI.parse(pypi_url).host} -r #{File.join(gem_path, 'requirements.txt')}"
Logger.info "Installing python packages from requirements.txt with pypi_url=#{pypi_url}"
if ENV['PIP_ENABLE_TRUSTED_HOST'].nil?
pip_args = "--no-warn-script-location -i #{pypi_url} -r #{requirements_path}"
else
pip_args = "--no-warn-script-location -i #{pypi_url} --trusted-host #{URI.parse(pypi_url).host} -r #{requirements_path}"
end
end
puts `/openc3/bin/pipinstall #{pip_args}`
end
Expand Down
12 changes: 11 additions & 1 deletion openc3/lib/openc3/utilities/cli_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@ def self.generate_target(args)
end
gemspec_filename = Dir['*.gemspec'][0]
gemspec = File.read(gemspec_filename)
gemspec.gsub!('plugin.txt', 'plugin.txt requirements.txt')
gemspec.gsub!(/s\.files = Dir\.glob.*\n/) do |match|
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird formatting but needed to get the indentation in the generated file right.

<<RUBY
# Prefer pyproject.toml over requirements.txt
python_dep_file = if File.exist?('pyproject.toml')
'pyproject.toml'
else
'requirements.txt'
end
s.files = Dir.glob("{targets,lib,tools,microservices}/**/*") + %w(Rakefile README.md LICENSE.txt plugin.txt) + [python_dep_file]
RUBY
end
File.write(gemspec_filename, gemspec)

target_txt_filename = "targets/#{target_name}/target.txt"
Expand Down
Loading