-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy config with pip install and have config regenerated from anywhere
- Loading branch information
Vasu Jaganath
committed
Aug 12, 2024
1 parent
f4fda35
commit 336ee0f
Showing
2 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import json | ||
from pathlib import Path | ||
from shutil import copytree, ignore_patterns | ||
from setuptools import setup, find_packages | ||
from setuptools.command.install import install | ||
import versioneer | ||
# from sophios import _version, cli, input_output as io | ||
|
||
|
||
class PostInstallCommand(install): | ||
"""Post-installation for installation mode.""" | ||
|
||
def run(self) -> None: | ||
adapters_dir = Path(__file__).parent / 'cwl_adapters' | ||
examples_dir = Path(__file__).parent / 'docs' / 'tutorials' | ||
adapters_target_dir = Path(self.build_lib) / 'sophios/cwl_adapters' | ||
examples_target_dir = Path(self.build_lib) / 'sophios/examples' | ||
extlist = ['*.png', '*.md', '*.rst', '*.pyc', '__pycache__', '*.json'] | ||
copytree(adapters_dir, adapters_target_dir, dirs_exist_ok=True) | ||
copytree(examples_dir, examples_target_dir, ignore=ignore_patterns(*extlist), dirs_exist_ok=True) | ||
install.run(self) | ||
# Custom post-installation actions go here | ||
# Never overwrite user config | ||
if not (Path.home() / 'wic').exists(): | ||
# config_path | ||
config_path = Path.home() / 'wic' | ||
# global config file in ~/wic | ||
global_config_file = config_path / 'global_config.json' | ||
|
||
# setup.py always gets executed in the project_root | ||
config_file = Path(__file__).parent / 'src' / 'sophios' / 'config.json' | ||
config = {} | ||
# config_file can contain absolute or relative paths | ||
with open(config_file, 'r', encoding='utf-8') as f: | ||
config = json.load(f) | ||
conf_tags = ['search_paths_cwl', 'search_paths_wic'] | ||
for tag in conf_tags: | ||
for ns in config[tag]: | ||
abs_paths = [str(Path(path).absolute()) for path in config[tag][ns]] | ||
config[tag][ns] = abs_paths | ||
config_path.mkdir(parents=True, exist_ok=True) | ||
# write out the config file with paths | ||
with open(global_config_file, 'w', encoding='utf-8') as f: | ||
json.dump(config, f) | ||
|
||
|
||
setup( | ||
name='sophios', | ||
version=versioneer.get_version(), | ||
packages=find_packages(where="src"), | ||
package_dir={"": "src"}, | ||
include_package_data=True, | ||
cmdclass={ | ||
'install': PostInstallCommand, | ||
}, | ||
package_data={ | ||
"sophios": ["cwl_adapters/*.cwl", "examples/*.wic"] | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters