Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 088a81c

Browse files
authored
Merge pull request #35 from robotology/feature/setup.cfg
Add `setup.cfg`, enforce code style, multiplatform support
2 parents 2b37db9 + efea3ee commit 088a81c

File tree

80 files changed

+178
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+178
-77
lines changed

.github/workflows/style.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Code Style
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
tags-ignore: ["**"]
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
12+
black:
13+
14+
name: black
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
19+
- name: "🔀 Checkout repository"
20+
uses: actions/checkout@v2
21+
22+
- name: '🐍 Initialize Python'
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: 3.8
26+
27+
- name: "📝 Black Code Formatter"
28+
uses: psf/black@stable
29+
with:
30+
options: --check --diff --color
31+
32+
isort:
33+
34+
name: isort
35+
runs-on: ubuntu-latest
36+
37+
steps:
38+
39+
- name: "🔀 Checkout repository"
40+
uses: actions/checkout@v2
41+
42+
- name: '🐍 Initialize Python'
43+
uses: actions/setup-python@v2
44+
with:
45+
python-version: 3.8
46+
47+
- name: "📝 isort"
48+
uses: isort/isort-action@master
49+
with:
50+
configuration: --check --diff --color

pyproject.toml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT). All rights reserved.
2+
# This software may be modified and distributed under the terms of the
3+
# GNU Lesser General Public License v2.1 or any later version.
14
[build-system]
2-
requires = ["setuptools>=40.8.0", "wheel", "setuptools_scm"]
5+
requires = [
6+
"wheel",
7+
"setuptools>=45",
8+
"setuptools_scm[toml]>=6.0",
9+
]
310
build-backend = "setuptools.build_meta"
11+
12+
[tool.setuptools_scm]
13+
local_scheme = "dirty-tag"
14+
15+
[tool.black]
16+
line-length = 88
17+
18+
[tool.isort]
19+
profile = "black"
20+
multi_line_output = 3

setup.cfg

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT). All rights reserved.
2+
# This software may be modified and distributed under the terms of the
3+
# GNU Lesser General Public License v2.1 or any later version.
4+
5+
[metadata]
6+
name = gym_ignition_models
7+
description = Collection of robot models for the Ignition Gazebo simulator.
8+
long_description = file: README.md
9+
long_description_content_type = text/markdown
10+
author = Diego Ferigo
11+
author_email = dgferigo@gmail.com
12+
license = LGPL
13+
license_file = LICENSE
14+
platforms = any
15+
url = https://github.com/robotology/gym-ignition-models
16+
17+
project_urls =
18+
Changelog = https://github.com/robotology/gym-ignition-models/releases
19+
Tracker = https://github.com/robotology/gym-ignition-models/issues
20+
Source = https://github.com/robotology/gym-ignition-models
21+
22+
keywords =
23+
model
24+
description
25+
urdf
26+
sdf
27+
gazebo
28+
ignition
29+
robot
30+
robotics
31+
panda
32+
icub
33+
simulation
34+
35+
classifiers =
36+
Development Status :: 5 - Production/Stable
37+
Operating System :: POSIX :: Linux
38+
Topic :: Games/Entertainment :: Simulation
39+
Topic :: Scientific/Engineering :: Physics
40+
Framework :: Robot Framework
41+
Intended Audience :: Developers
42+
Intended Audience :: Science/Research
43+
Programming Language :: Python :: 3
44+
Programming Language :: Python :: 3 :: Only
45+
Programming Language :: Python :: 3.7
46+
Programming Language :: Python :: 3.8
47+
Programming Language :: Python :: 3.9
48+
Programming Language :: Python :: 3.10
49+
Programming Language :: Python :: Implementation :: CPython
50+
License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
51+
52+
[options]
53+
zip_safe = False
54+
packages = find:
55+
package_dir =
56+
=src
57+
python_requires = >=3.7
58+
59+
[options.packages.find]
60+
where = src
61+
62+
[options.package_data]
63+
gym_ignition_models =
64+
meshes/*.*
65+
meshes/**/*.*
66+
meshes/**/**/*.*
67+
*/meshes/*.*
68+
*/meshes/**/*.*
69+
*/meshes/**/**/*.*
70+
*/*.sdf
71+
*/*.urdf
72+
*/model.config

setup.py

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
import os
66
import shutil
7-
import platform
7+
8+
import setuptools
89
from setuptools.command.build_ext import build_ext
9-
from setuptools import setup, find_packages, Extension
1010

1111

12-
class CopyMeshes(Extension):
12+
class CopyMeshes(setuptools.Extension):
1313
extension_name = "CopyMeshes"
1414

1515
def __init__(self):
16-
Extension.__init__(self, name=self.extension_name, sources=[])
16+
setuptools.Extension.__init__(self, name=self.extension_name, sources=[])
1717

1818

1919
class BuildExtension(build_ext):
@@ -38,9 +38,6 @@ def run(self) -> None:
3838
if len(self.extensions) != 1 or not isinstance(self.extensions[0], CopyMeshes):
3939
raise RuntimeError("This class can only build one CopyMeshes object")
4040

41-
if platform.system() != "Linux":
42-
raise RuntimeError("Only Linux is currently supported")
43-
4441
for ext in self.extensions:
4542
self.build_extension(ext)
4643

@@ -60,7 +57,9 @@ def build_extension(self, ext) -> None:
6057

6158
# Check that the directory exists
6259
if not os.path.isdir(pkg_dir):
63-
raise RuntimeError(f"The build package directory '{pkg_dir}' does not exist")
60+
raise RuntimeError(
61+
f"The build package directory '{pkg_dir}' does not exist"
62+
)
6463

6564
# Copy the folders
6665
for dest, orig in self.FROM_DEST_TO_ORIG.items():
@@ -84,49 +83,7 @@ def build_extension(self, ext) -> None:
8483
with open(os.path.join(this_directory, "README.md"), encoding="utf-8") as f:
8584
long_description = f.read()
8685

87-
setup(
88-
name="gym-ignition-models",
89-
author="Diego Ferigo",
90-
author_email="diego.ferigo@iit.it",
91-
description="Collection of robot models for the Ignition Gazebo simulator",
92-
long_description=long_description,
93-
long_description_content_type="text/markdown",
94-
url="https://github.com/robotology/gym-ignition-models",
95-
project_urls={
96-
"Bug Tracker": "https://github.com/robotology/gym-ignition-models/issues",
97-
"Source Code": "https://github.com/robotology/gym-ignition-models",
98-
},
99-
keywords=["model", "description", "urdf", "sdf", "gazebo", "ignition", "robot",
100-
"robotics", "panda", "icub", "simulation"],
101-
license="LGPL",
102-
platforms="any",
103-
classifiers=[
104-
"Development Status :: 5 - Production/Stable",
105-
"Operating System :: POSIX :: Linux",
106-
"Topic :: Games/Entertainment :: Simulation",
107-
"Topic :: Scientific/Engineering :: Artificial Intelligence",
108-
"Framework :: Robot Framework",
109-
"Intended Audience :: Developers",
110-
"Intended Audience :: Science/Research",
111-
"Programming Language :: Python :: 3",
112-
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
113-
],
114-
use_scm_version=dict(local_scheme="dirty-tag"),
115-
setup_requires=["setuptools_scm"],
116-
python_requires=">=3.6",
117-
packages=find_packages(),
118-
package_data={"gym_ignition_models": [
119-
"meshes/*.*",
120-
"meshes/**/*.*",
121-
"meshes/**/**/*.*",
122-
"*/meshes/*.*",
123-
"*/meshes/**/*.*",
124-
"*/meshes/**/**/*.*",
125-
"*/*.sdf",
126-
"*/*.urdf",
127-
"*/model.config",
128-
]},
86+
setuptools.setup(
12987
ext_modules=[CopyMeshes()],
13088
cmdclass=dict(build_ext=BuildExtension),
131-
zip_safe=False,
13289
)
Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# This software may be modified and distributed under the terms of the
33
# GNU Lesser General Public License v2.1 or any later version.
44

5-
import os
65
import enum
6+
import os
77
import tempfile
88
from pathlib import Path
99
from typing import IO, List, Union
@@ -17,7 +17,7 @@ def get_models_path() -> str:
1717
A string containing the path of the models.
1818
"""
1919
models_dir = os.path.join(os.path.dirname(__file__))
20-
return models_dir + '/'
20+
return models_dir + "/"
2121

2222

2323
def get_robot_names() -> List[str]:
@@ -114,9 +114,9 @@ def setup_environment() -> None:
114114
raise NotADirectoryError(f"Failed to find path '{model_path}'")
115115

116116
if "IGN_GAZEBO_RESOURCE_PATH" in os.environ:
117-
os.environ["IGN_GAZEBO_RESOURCE_PATH"] += f':{model_path}'
117+
os.environ["IGN_GAZEBO_RESOURCE_PATH"] += f":{model_path}"
118118
else:
119-
os.environ["IGN_GAZEBO_RESOURCE_PATH"] = f'{model_path}'
119+
os.environ["IGN_GAZEBO_RESOURCE_PATH"] = f"{model_path}"
120120

121121

122122
class ResourceType(enum.Enum):
@@ -130,9 +130,9 @@ class ResourceType(enum.Enum):
130130
URDF_STRING = enum.auto()
131131

132132

133-
def get_model_resource(robot_name: str,
134-
resource_type: ResourceType = ResourceType.URDF_PATH) \
135-
-> Union[str, IO]:
133+
def get_model_resource(
134+
robot_name: str, resource_type: ResourceType = ResourceType.URDF_PATH
135+
) -> Union[str, IO]:
136136
"""
137137
Return the resource of the selected robot.
138138
@@ -167,38 +167,41 @@ def get_model_resource(robot_name: str,
167167
with open(file=stored_model, mode="r+") as f:
168168
return f.read()
169169

170-
if resource_type in {ResourceType.SDF_FILE,
171-
ResourceType.SDF_PATH,
172-
ResourceType.SDF_STRING}:
170+
if resource_type in {
171+
ResourceType.SDF_FILE,
172+
ResourceType.SDF_PATH,
173+
ResourceType.SDF_STRING,
174+
}:
173175
try:
174176
from scenario import gazebo as scenario_gazebo
175177
except ImportError:
176178
msg = "URDF to SDF conversion requires the 'scenario' package"
177179
raise RuntimeError(msg)
178180

179181
if resource_type is ResourceType.SDF_FILE:
180-
file_name = Path(stored_model).with_suffix('').name
181-
sdf_file = tempfile.NamedTemporaryFile(mode="w+",
182-
prefix=file_name,
183-
suffix=".sdf")
184-
sdf_string = get_model_resource(robot_name=robot_name,
185-
resource_type=ResourceType.SDF_STRING)
182+
file_name = Path(stored_model).with_suffix("").name
183+
sdf_file = tempfile.NamedTemporaryFile(
184+
mode="w+", prefix=file_name, suffix=".sdf"
185+
)
186+
sdf_string = get_model_resource(
187+
robot_name=robot_name, resource_type=ResourceType.SDF_STRING
188+
)
186189
sdf_file.write(sdf_string)
187190
return sdf_file
188191

189192
if resource_type is ResourceType.SDF_PATH:
190-
file_name = Path(stored_model).with_suffix('').name
191-
fd, sdf_path = tempfile.mkstemp(prefix=file_name,
192-
suffix=".sdf",
193-
text=True)
194-
sdf_string = get_model_resource(robot_name=robot_name,
195-
resource_type=ResourceType.SDF_STRING)
193+
file_name = Path(stored_model).with_suffix("").name
194+
fd, sdf_path = tempfile.mkstemp(prefix=file_name, suffix=".sdf", text=True)
195+
sdf_string = get_model_resource(
196+
robot_name=robot_name, resource_type=ResourceType.SDF_STRING
197+
)
196198
with open(sdf_path, "w") as f:
197199
f.write(sdf_string)
198200
return sdf_path
199201

200202
if resource_type is ResourceType.SDF_STRING:
201203
from scenario import gazebo as scenario_gazebo
204+
202205
return scenario_gazebo.urdffile_to_sdfstring(urdf_file=stored_model)
203206

204207
raise ValueError(resource_type)
@@ -208,9 +211,11 @@ def get_model_resource(robot_name: str,
208211
if resource_type is ResourceType.SDF_PATH:
209212
return stored_model
210213

211-
if resource_type in {ResourceType.URDF_FILE,
212-
ResourceType.URDF_PATH,
213-
ResourceType.URDF_STRING}:
214+
if resource_type in {
215+
ResourceType.URDF_FILE,
216+
ResourceType.URDF_PATH,
217+
ResourceType.URDF_STRING,
218+
}:
214219
raise ValueError("SDF to URDF conversion is not supported")
215220

216221
if resource_type is ResourceType.SDF_STRING:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)