Skip to content

Commit

Permalink
path from commandline, conda and py 3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zrisher committed Aug 15, 2015
1 parent b11d2a6 commit 257d6a4
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
*.log
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,56 @@
# se_mod_builder
Space Engineers Mod Building & Deployment Tool
# SE Mod Helpers - Build Script
This script assists with the deployment of Space Engineers mods from their
source/development locations to the SE mods directory for testing and
publishing.

## Requirements
* Python 2.7 or greater

## Installation
* Include SEModHelpers as a submodule into your repo, as per its install guide.
* Copy build_config.yml.example to the top-level directory of your mod
* Remove the ".example" from its name and fill in your own configuration details

## Usage
Double-click *build.bat* in the SEModHelpers folder, or run
`python Path/To/SEModHelpers/.build/build.py`.

### File Structure
The build script can work with either a module-based structure or a flat one,
but either way we expect the *Script* dir to **not** be contained within data.

A fully-deployed SE mod will have the file structure:

ModName
- Data
- Scripts
- *.cs
- *.sbc
- Models
- ... various levels and folders ...
- *.mwm
- Textures
- ... various levels and folders ...
- *.dds

With this script, you can use either:

ModName
- Data
- Models
- Scripts
- Textures

Or (using config option has_modules = true):

ModSourceFolder
- Module1
- Data
- Scripts
- Textures
- Module2
- Data
- Textures
... etc ...


52 changes: 38 additions & 14 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,46 @@
import os.path
import sys



import lib

import re
# import re

BUILD_CONFIG_FILENAME = "build_config.yml"


def build_distro():
print("\n\n------- SEModHelpers Python Build Script -------\n")

# === Parse Args

if sys.argv.__len__() < 2:
print("Please supply a path to your mod as the first argument. Aborting.")
return

target_dir = sys.argv[1]

if not os.path.exists(target_dir):
print("Could not find mod directory at \"" + target_dir + "\". Aborting.")
return

print("Running on mod at \"{0}\"".format(target_dir))

# === Get Build Script paths

build_script_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
print("Running from " + build_script_dir)
build_model_path = os.path.join(build_script_dir, 'build_model.py')

build_config_path = lib.paths.find_file_up(
"build_config.yml", build_script_dir, 4
)
if build_config_path:
print("Running from \"{0}\"".format(build_script_dir))

# === Get target mod config

#build_config_path = lib.paths.find_file_up(
# "build_config.yml", build_script_dir, 4
#)

build_config_path = os.path.join(target_dir, BUILD_CONFIG_FILENAME)

if os.path.exists(build_config_path):
print("Config file found at " + build_config_path)
else:
print("build_config.yml is missing. Aborting script.")
Expand Down Expand Up @@ -63,18 +83,20 @@ def build_distro():
#for k,v in dist_config.items():
# print(" {0}: {1}".format(k, v))
print(" {0}: {1}".format('Path', dist_config['path']))
print(" {0}: {1}".format('cleanup_ignores', dist_config['cleanup_ignores']))
print(" {0}: {1}".format('compile_symbols_to_remove', dist_config['compile_symbols_to_remove']))
print(" {0}: {1}".format('cleanup_ignores', ", ".join(dist_config['cleanup_ignores'])))
print(" {0}: {1}".format('compile_symbols_to_remove', ", ".join(dist_config['compile_symbols_to_remove'])))
print("")


print("MWM Builder Path: " + mwm_builder_path)
print("")

# === Run Build

print("----- Running Build ----- \n")

# Start MWM Builder, which runs in parallel
# TODO: Start MWM Builder, which runs in parallel
"""
print("--- Starting MWM Model Builder Threads --- ")
mwm_processes = lib.build.process_models(
source_modules, build_model_path, mwm_builder_path
Expand All @@ -85,6 +107,7 @@ def build_distro():
else:
print("no mwm_processes running")
print("")
"""

# Clean Destinations
print("--- Cleaning Dist Dirs ---")
Expand All @@ -101,7 +124,7 @@ def build_distro():
lib.build.distribute(source_modules, distributions,
[["Scripts"],["Data", "Scripts"]], "cs",
dist_content_path = ["Data", "Scripts"],
squash_modules=False) # , squash_dirs=True)
squash_modules=False, squash_dirs=True)
print("")

# Copy Textures
Expand All @@ -110,7 +133,8 @@ def build_distro():
print("\n")


# Copy Models once they're built
# TODO: Copy Models once they're built
"""
if mwm_processes_count > 0:
print("waiting for our mwm processes to finish")
for mwm_process in mwm_processes:
Expand All @@ -119,7 +143,7 @@ def build_distro():
print(" --- Distributing Models --- ")
lib.build.distribute(source_modules, distributions, [["Model"]], "mwm")
print("\n")

"""

print("------- SEModHelpers Python Build Complete ------- \n")

Expand Down
50 changes: 50 additions & 0 deletions build_config.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# SE Mod Helpers - build script configuration file
#
# Include this file in your mod's top-level directory.

# `mod_name` is inferred from the location of this file, but can be specified
#mod_name: MyAwesomeMod

# If your code is organized as usual in a flat structure like:
#
# ModSourceFolder
# - Data
# - Scripts
# - Textures
#
# Then `has_modules` should be false. This is default.
#
# If your code is organized into modules, i.e.
#
# ModSourceFolder
# - Module1
# - Data
# - Scripts
# - Textures
# - Module2
# - Data
# - Textures
# ... etc ...
#
# then `has_modules` should be true.
#has_modules: true

# Specify the various distributions you'd like to create in the SE Mods folder
# Distributes besides `production` require a suffix to append to the mod name
# when building their path. If one isn't provided its key will be used.
# Distributions may optionally specify a list of Compilation Symbols to remove
# from their '.cs' files.
distributions:
development:
suffix: " Dev"
production:
compile_symbols_to_remove:
- DEBUG

# the path to SE's client-side mods folder
# this will be automatically inferred from %APPDATA%% unless provided below
#se_mods_dir: 'C:\Users\UserName\AppData\Roaming\SpaceEngineers\Mods'

# if mwm_builder_path points to MwmBuilder.exe, models will be built
#mwm_builder_path: 'C:\Program Files (x86)\Steam\SteamApps\common\SpaceEngineers\Tools\MwmBuilder\MwmBuilder.exe'
9 changes: 9 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: se_mod_builder
channels:
- defaults
dependencies:
- python>=2.7
- pip
- pip:
- chardet
- pyyaml
8 changes: 4 additions & 4 deletions lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ def load(config_file_path):
dist_config['dir_name'] = dir_name
dist_config['path'] = os.path.join(se_mods_dir, dir_name)

# TODO actually pull this from config
# TODO: pull cleanup_ignores from config
dist_config['cleanup_ignores'] = ["^modinfo\.sbmi"]
dist_config['cleanup_ignore_rgx'] = [
re.compile(ignore_str) for ignore_str in dist_config['cleanup_ignores']
]

if not dist_config.get('cleanup_ignore_rgx'):
dist_config['cleanup_ignore_rgx'] = []

compile_symbols_to_remove = dist_config.get('compile_symbols_to_remove')
if not compile_symbols_to_remove:
# clean this up so later code doesn't have to check for existence
dist_config['compile_symbols_to_remove'] = None
dist_config['compile_symbols_to_remove'] = []

# tools
mwm_builder_path = "{0}".format(config.get('mwm_builder_path'))
Expand Down
3 changes: 2 additions & 1 deletion lib/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import fileinput
import codecs
import chardet

special_chars = re.compile("[^a-zA-Z0-9_\-]")
conditional_line = re.compile("\s*\[System.Diagnostics.Conditional\(\"(.*?)\"\)\]")
Expand Down Expand Up @@ -185,7 +186,7 @@ def get_encoding(file_path):
if raw.startswith(codecs.BOM_UTF8):
encoding = 'utf-8-sig'
else:
result = codecs.chardet.detect(raw)
result = chardet.detect(raw)
encoding = result['encoding']

return encoding
Expand Down

0 comments on commit 257d6a4

Please sign in to comment.