def testSetCwd(self, restore_cwd): initial_wd = os.getcwd() fileName = os.path.join(os.path.dirname(__file__),"loader_sample.py") cwd = os.path.join(os.path.dirname(__file__), "data") assert cwd != initial_wd # make sure test is not too easy get_module(fileName, cwd) assert os.getcwd() == cwd, os.getcwd() assert doit.get_initial_workdir() == initial_wd
def _generate_env(): """ See https://github.com/pydoit/doit/issues/171 for CmdAction anvironment usage To get it working right, you need to copy the current environment or nothing will work right """ S = doit.get_initial_workdir() + "/config/sonarqube" my_env = os.environ.copy() my_env['PING_HOST'] = '127.0.0.1' my_env['S'] = S return my_env
def task_make_grafana_preconf_volume(): GRAFANA_BUILD = doit.get_initial_workdir() + "/config/grafana_build" return { 'actions': [ "docker volume create %s_grafana-storage" % (SERVICE_NAME), # id is 104,group is 107 "docker run --rm -v %s_grafana-storage:/data -v %s:/to_copy alpine cp /to_copy/grafana.db /data/grafana.db" % (SERVICE_NAME, GRAFANA_BUILD), "docker run --rm -v %s_grafana-storage:/data -v %s:/to_copy alpine chown 104:107 /data/grafana.db" % (SERVICE_NAME, GRAFANA_BUILD), "docker run --rm -v %s_grafana-storage:/data -v %s:/to_copy alpine ls -l /data/grafana.db" % (SERVICE_NAME, GRAFANA_BUILD), ], 'verbosity': 2 }
def task_original_script(): env1 = os.environ.copy() shared_packages = os.path.join(doit.get_initial_workdir(), "dist") env1["PIP_FIND_LINKS"] = shared_packages env2 = os.environ.copy() env2['PYTHONPATH'] = os.getcwd() # TODO win return { 'getargs': { 'git_version': ('get_git_version', 'git_version') }, 'params': [example, example_pkgname], 'actions': [ # 1. verify package generation & installation action.CmdAction('tox -e py -- %(git_version)s', env=env1), # dev install, then... # TODO: need prerelease param just now; remove pre & index urls after release action.CmdAction( 'pip install -f ' + shared_packages + ' --pre --index-url=https://test.pypi.org/simple/ --extra-index-url=https://pypi.org/simple -e .', env=env2), # 2. ...verify in git repo (TODO: could just be "tmpverify %(example)s", I think) action.CmdAction(lambda example, example_pkgname: 'python ' + _x( example, example_pkgname) + '/tests/__init__.py ' + _x( example, example_pkgname), env=env2), # 3. ...verify outside git repo action.CmdAction(lambda example, example_pkgname: 'mkdir /tmp/9k && cd /tmp/9k && tmpverify ' + _x(example, example_pkgname) + ' %(git_version)s', env=env2), # TODO: should be some kind of clean up option action.CmdAction( lambda example, example_pkgname: 'pip uninstall -y ' + _x( example, example_pkgname)) ] }
def task_demo_with_args(): """Runs nikola_libcst_fix.theme_config_adjustments.demo(...): default path_to_custom_site will map to where the doit.run call was issued from. """ theme_name_param = dict( name="name_of_theme", long="theme_name", short="t", default="canterville", type=str, help= "\nA string giving the name of the theme we should find the `conf.py.sample` file in.\n" ) path_to_site_param = dict( name="path_to_custom_site", long="site_path", short="p", type=str, help= "\nA string or pl.Path object that defines the path to a Nikola site's root folder;" ) reset_conf_param = dict( name="reset_conf", long="reset_conf", short="r", default=False, type=bool, help= "\nA bool specifying if we should reset the conf.py file to match it's saved backup" "\n(the backup is automatically generated and stored the first time this function runs)\n" ) path_to_site_param["default"] = doit.get_initial_workdir() path_to_site_param["help"] += "\ndefaults to doit.get_initial_workdir()\n" return dict( actions=[demo], params=[theme_name_param, path_to_site_param, reset_conf_param], verbosity=2)
# Better to let Phrasal pipeline run sequentially so that # each task can use all cores. 'num_process': 1 } # Get conf file from command-line arguments ARGS = {"conf": get_var('conf', None)} err = lambda x: sys.stderr.write(x + os.linesep) if not ARGS['conf']: err('Usage: %s conf=<file>' % (basename(sys.argv[2]))) sys.exit(-1) conf_file = ARGS['conf'] if not os.path.exists(conf_file): # Relative path conf_file = os.path.join(doit.get_initial_workdir(), conf_file) if not os.path.exists(conf_file): err('Configuration file not found: ' + conf_file) sys.exit(-1) # Conf file format is YAML. Parse it. with open(conf_file) as fd: CONFIG = yaml.load(fd) # Experiment naming DATE = datetime.now().strftime('%a_%b_%d_%Y_%H_%M_%S') EXPERIMENT_NAME = CONFIG[k.EXPERIMENT].get( k.EXPERIMENT_NAME, DATE) if k.EXPERIMENT in CONFIG else DATE # Constants for the files and folders generated by this script # during execution
### README # Sample to test doit.get_initial_workdir # First create a folder named 'sub1'. # Invoking doit from the root folder will execute both tasks 'base' and 'sub1'. # Invoking 'doit -k' from path 'sub1' will execute only task 'sub1' ################## import os import doit DOIT_CONFIG = { 'verbosity': 2, 'default_tasks': None, # all by default } # change default tasks based on dir from where doit was run sub1_dir = os.path.join(os.path.dirname(__file__), 'sub1') if doit.get_initial_workdir() == sub1_dir: DOIT_CONFIG['default_tasks'] = ['sub1'] def task_base(): return {'actions': ['echo root']} def task_sub1(): return {'actions': ['echo sub1']}
# Better to let Phrasal pipeline run sequentially so that # each task can use all cores. 'num_process': 1 } # Get conf file from command-line arguments ARGS = {"conf": get_var('conf', None)} err = lambda x : sys.stderr.write(x + os.linesep) if not ARGS['conf']: err('Usage: %s conf=<file>' % (basename(sys.argv[2]))) sys.exit(-1) conf_file = ARGS['conf'] if not os.path.exists(conf_file): # Relative path conf_file = os.path.join(doit.get_initial_workdir(), conf_file) if not os.path.exists(conf_file): err('Configuration file not found: ' + conf_file) sys.exit(-1) # Conf file format is YAML. Parse it. with open(conf_file) as fd: CONFIG = yaml.load(fd) # Constants for the files and folders generated by this script # during execution SYSTEM_DIR_LOC = 'system-dir' SYSTEM_DIR = CONFIG[k.SYSTEM_DIR] p = lambda x : os.path.join(SYSTEM_DIR, x) CHECKPOINT_DIR = p('checkpoints') LOGS_DIR = p('logs')
def initial_dir(): return doit.get_initial_workdir()
def copy_example(example): from_ = os.path.join(doit.get_initial_workdir(), "examples", example) copy_tree(from_, '.')