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

Make test_ament_virtualenv workable #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion test_ament_virtualenv/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests
gdown==5.2.0
7 changes: 7 additions & 0 deletions test_ament_virtualenv/scripts/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env python3
import sys

from test_ament_virtualenv.test_ament_virtualenv import main

if __name__ == "__main__":
sys.exit(main())
4 changes: 4 additions & 0 deletions test_ament_virtualenv/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/test_ament_virtualenv
[install]
install_scripts=$base/lib/test_ament_virtualenv
20 changes: 11 additions & 9 deletions test_ament_virtualenv/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from setuptools import setup
import setuptools.command.install
import ament_virtualenv.install
Expand All @@ -7,9 +9,11 @@
class InstallCommand(setuptools.command.install.install):
def run(self):
super().run()
ament_virtualenv.install.install_venv(self.install_base, package_name)
# instead of self.install_base we may also use:
# self.config_vars['platbase'] or self.config_vars['base']
scripts_base = os.path.join(self.install_base, "lib/{}".format(package_name))
ament_virtualenv.install.install_venv(install_base = self.install_base,
package_name = package_name,
scripts_base = scripts_base,
)
return

setup(
Expand All @@ -20,7 +24,10 @@ def run(self):
version='0.0.5',
packages=[package_name],
data_files=[
('share/'+package_name, ['package.xml', 'requirements.txt']),
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml', 'requirements.txt']),
('lib/' + package_name, ['scripts/main.py'])
],
install_requires=['setuptools'],
zip_safe=False,
Expand All @@ -38,9 +45,4 @@ def run(self):
description='Example of using ament_virtualenv.',
license='Apache License, Version 2.0',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'test_ament_virtualenv = test_ament_virtualenv.test_ament_virtualenv:main',
],
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,25 @@

import importlib
import sys
import gdown

def main(args=None):
# 1: Test if we're in a virtual environment at all.
is_in_venv = hasattr(sys, 'real_prefix')
if not is_in_venv:
print(
"[test_ament_virtualenv] "
"FAILURE: Python virtual environment not activated."
)
return 1
# 2: Test the Python version.
if sys.version_info.major != 2:
print(
"[test_ament_virtualenv] "
"FAILURE: Wrong Python version."
)
return 1
# 3: Test if proper requirements have been installed
def main(args=None):
# Test if proper requirements have been installed
try:
requests = importlib.import_module("requests")
if requests.__version__ != '2.20.1':
gdown = importlib.import_module("gdown")
if gdown.__version__ != '5.2.0':
print(
"[test_ament_virtualenv] "
"FAILURE: Requirements not provided correctly "
"(expected 'requests==2.20.1', found "+requests.__version__+")"
"(expected 'gdown==5.2.0', found "+gdown.__version__+")"
)
return 1
except:
print(
"[test_ament_virtualenv] "
"FAILURE: Requirements not provided "
"(expected 'requests' to be present but could not find it)"
"(expected 'gdown' to be present but could not find it)"
)
return 1
print("[test_ament_virtualenv] SUCCESS: All checks passed.")
return 0


if __name__ == '__main__':
sys.exit(main())