Skip to content

Commit

Permalink
Pull request for #131: Change provenance to state_of_inputs (#132)
Browse files Browse the repository at this point in the history
* #128 binding file limit on directory walk

* #131 purge provenance

* #131 first pass dir recording system

* #131 an SCons -> a SCons

* #131 change default log location

* #131 better naming, load into __init__, better prereq check

* #131 change default name for log

* #132 #131 change default log name

* #132 #131 gslab-econ/template#87 new log headding

* #132 #131 better path checks, fix walk-break rule, new path names

* #132 #131 fix heading creation of heading with hash
  • Loading branch information
arosenbe authored Sep 7, 2017
1 parent 53d4026 commit 8dff317
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 302 deletions.
12 changes: 3 additions & 9 deletions gslab_scons/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Notes on release.py

Make a release from an SCons directory by running the module `release`.
Make a release from a SCons directory by running the module `release`.

A user can either run the following from the command line within the directory of interest (e.g. `/paper_slides`) or write a Python script to call the module (see "Python wrapper" section below). If using the command line, run the following:

Expand Down Expand Up @@ -46,20 +46,14 @@ you can store it in `config_user.yaml` as
github_token: <your token here>
```

## Provenance

Making a release using this tool will automatically call `make_provenance()` from the module `provenance` to create a `provenance` file (for more details, please see our [RA manual](https://github.com/gslab-econ/ra-manual/wiki/Data-Storage)).

While calling the `release` module from the command line, one can specify the `detail_limit` argument of `make_provenance()` by adding `detail_limit=<###>` (default to 500).

## Python wrapper

If you wish to wrap the `release` module in a Python script to pass arguments to `make_provenance()`, use the following syntax:
If you wish to wrap the `release` module in a Python script to help pass arguments, use the syntax

```python
from gslab_scons import release
release.main(version = '<version name here>',
readme = '../readme.md')
```

For a complete list of arguments that you can pass to `release.main()` and `make_provenance()`, visit `release.py` and `provenance.py` respectively.
For a complete list of arguments that you can pass to `release.main()`, visit `release.py`.
2 changes: 1 addition & 1 deletion gslab_scons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'''
import os
import misc
import provenance
import record_dir
import size_warning
from .log import start_log, log_timestamp
from .builders.build_r import build_r
Expand Down
6 changes: 2 additions & 4 deletions gslab_scons/_release_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def release(vers, org, repo,
local_release = '',
target_commitish = '',
zip_release = True,
github_token = None,
provenance_path = './release/provenance.log'):
github_token = None):
'''Publish a release
Parameters
Expand Down Expand Up @@ -141,8 +140,7 @@ def release(vers, org, repo,
upload_asset(github_token = github_token,
org = org,
repo = repo,
release_id = release_id,
file_name = provenance_path)
release_id = release_id)


def upload_asset(github_token, org, repo, release_id, file_name,
Expand Down
23 changes: 15 additions & 8 deletions gslab_scons/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,19 @@ def scons_debrief(args):

def state_of_repo(maxit, outfile = 'state_of_repo.log'):
with open(outfile, 'wb') as f:
f.write("WARNING: Information about .sconsign.dblite may be misleading \n" +
f.write("WARNING: Information about .sconsign.dblite may be misleading\n" +
"as it can be edited after state_of_repo.log finishes running\n\n" +
"===================================\n\n GIT STATUS" +
"\n\n===================================\n")
make_heading("GIT STATUS"))
f.write("Last commit:\n\n")

# https://stackoverflow.com/questions/876239/how-can-i-redirect-and-append-both-stdout-and-stderr-to-a-file-with-bash
os.system("git log -n 1 >> state_of_repo.log 2>&1")
with open(outfile, 'ab') as f:
f.write("\n\nFiles changed since last commit:\n\n")
f.write("\n\nFiles changed since last commit:\n\n\n")
os.system("git diff --name-only >> state_of_repo.log 2>&1")

with open(outfile, 'ab') as f:
f.write("\n===================================\n\n FILE STATUS" +
"\n\n===================================\n")
f.write('\n%s' % make_heading("FILE STATUS"))
for root, dirs, files in os.walk(".", followlinks = True):
i = 1
for name in files:
Expand All @@ -70,6 +68,15 @@ def state_of_repo(maxit, outfile = 'state_of_repo.log'):
return None


def make_heading(s):
'''
Wrap s in a bunch of equals signs for nice heading printing
'''
equals_signs = '=' * 35
out = '%s\n\n *** %s ***\n\n%s\n' % (equals_signs, s, equals_signs)
return out


def command_line_args(env):
'''
Return the content of env['CL_ARG'] as a string
Expand Down Expand Up @@ -287,7 +294,7 @@ def load_yaml_value(path, key):

def check_and_expand_path(path):
error_message = " The directory provided, '%s', cannot be found. " % path + \
"Please manually create before running\n" + \
"Please manually create before running " + \
"or fix the path in config_user.yaml.\n"
try:
path = os.path.expanduser(path)
Expand Down Expand Up @@ -350,4 +357,4 @@ def finder(rel_parent_dir, pattern, excluded_dirs = []):
except subprocess.CalledProcessError:
out_paths = []

return out_paths
return out_paths
246 changes: 0 additions & 246 deletions gslab_scons/provenance.py

This file was deleted.

Loading

0 comments on commit 8dff317

Please sign in to comment.