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

Fix local build and install #620

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ description-file = README.md
# need to generate separate wheels for each Python version that you
# support.
universal=1

[options]
zip_safe = False
22 changes: 16 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ def fill_connectors(projects, modules_path):
if not os.path.isfile(os.path.join(modules_path, module, SKIP_ME)):
projects['stix_shifter_modules_' + module] = ['stix_shifter_modules/' + module]

def fill_connectors_mode3(projects, modules_path):
modules = [name for name in os.listdir(modules_path)
if (os.path.isdir(os.path.join(modules_path, name)) and (not name.startswith('__')))]
for module in modules:
if not os.path.isfile(os.path.join(modules_path, module, SKIP_ME)):
projects['stix_shifter_modules'].append('stix_shifter_modules/' + module)

# The mode determines how the stix-shifter is packaged
# 1 = Include everything in 1 whl package
# 3 - 3 whl packages respectively for stix-shifter, stix-shifter-utils and stix-shifter-modules
# N - stix-shifter, stix-shifter-utils, and each connector is packaged separately
# <module name> - package only the specified connector

mode = 'N'
mode = '3'
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should not change the default packaging mode, why are you using mode 3 at all? maybe mode 1 will fit you better?

Copy link
Author

Choose a reason for hiding this comment

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

Agreed. Changing the default mode might be too much depending on the workflow. For the distribution purpose for developers (python setup.py bdist_wheel), it would be good to have separate packages.

But, for local build/install for users (python setup.py install), mode 3 or 1 is needed as the installed packages under site-packages will have the mix of egg zipfiles and directories for each stix_shifter_module, which will cause importing errors. For example, after python setup.py install (with mode N), importing qradar module (import stix_shifter_modules.qradar) from outside of the stix-shifter root directory will cause ModuleNotFoundError due to above issues.

Copy link
Author

Choose a reason for hiding this comment

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

By the way, MODE 1/3 bdist/install fails due to incorrect path resolution for stix_shifter_modules. Proper fill_connectors is needed to support MODE 1/3.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mdazam1942 is looking into it.

if 'MODE' in os.environ:
mode = os.environ['MODE']

Expand All @@ -67,8 +74,9 @@ def fill_connectors(projects, modules_path):
projects = {
"stix_shifter_utils": ["stix_shifter_utils"],
"stix_shifter": ["stix_shifter"],
"stix_shifter_modules": ["stix_shifter_modules"],
"stix_shifter_modules": [],
}
fill_connectors_mode3(projects, "stix_shifter_modules")
elif mode == 'N':
projects = {
"stix_shifter_utils": ["stix_shifter_utils"],
Expand All @@ -88,7 +96,7 @@ def fill_connectors(projects, modules_path):

for project_name in projects.keys():
cleanup_file_list = []
temp_dir = None
temp_dir_list = []
module_dir = None

src_folders = projects[project_name]
Expand Down Expand Up @@ -207,6 +215,7 @@ def fill_connectors(projects, modules_path):
with open(os.path.join(conf_path, 'dialects.json'), 'w', encoding="utf-8") as f:
f.write(json.dumps(dialects_full, indent=4, sort_keys=False))
temp_dir = tempfile.TemporaryDirectory()
temp_dir_list.append([temp_dir, module_dir])
shutil.move(configuration_path, temp_dir.name)
os.rename(conf_path, configuration_path)
cleanup_file_list.append(configuration_path)
Expand Down Expand Up @@ -245,8 +254,9 @@ def fill_connectors(projects, modules_path):
shutil.rmtree(cleanup_file)
else:
os.remove(cleanup_file)
if temp_dir is not None:
shutil.move(os.path.join(temp_dir.name, 'configuration'), module_dir)
temp_dir = None
for temp_dir, module_dir in temp_dir_list:
if temp_dir is not None:
shutil.move(os.path.join(temp_dir.name, 'configuration'), module_dir)
temp_dir.cleanup()
print('---------------------------------')
shutil.rmtree(TMP_MAPPING_DIR)