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

Update flow for signac 1.8.0 #693

Merged
merged 7 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 1 addition & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,12 @@ jobs:
path: test-reports
destination: test-reports

linux-python-310-signac-16:
<<: *test-template
environment:
DEPENDENCIES: "NEWEST"
SIGNAC_VERSION: "signac~=1.6.0"
PYTHON: python
linux-python-310-signac-15:
<<: *test-template
environment:
DEPENDENCIES: "NEWEST"
SIGNAC_VERSION: "signac~=1.5.0"
PYTHON: python
linux-python-310-signac-latest:
<<: *test-template
environment:
DEPENDENCIES: "NEWEST"
SIGNAC_VERSION: "git+ssh://git@github.com/glotzerlab/signac.git"
PYTHON: python
linux-python-310-signac-next:
<<: *test-template
environment:
DEPENDENCIES: "NEWEST"
SIGNAC_VERSION: "git+ssh://git@github.com/glotzerlab/signac.git@next"
PYTHON: python
linux-python-39:
<<: *test-template
docker:
Expand All @@ -95,7 +77,7 @@ jobs:
- image: cimg/python:3.8
environment:
DEPENDENCIES: "OLDEST"
SIGNAC_VERSION: "signac==1.3.0"
SIGNAC_VERSION: "signac==1.8.0"
PYTHON: python

test-install-pip-python-310: &test-install-pip
Expand Down Expand Up @@ -225,16 +207,6 @@ workflows:
- linux-python-38-oldest:
post-steps:
- codecov/upload
- linux-python-310-signac-16:
requires:
- linux-python-310
post-steps:
- codecov/upload
- linux-python-310-signac-15:
requires:
- linux-python-310
post-steps:
- codecov/upload
- check-metadata:
filters:
branches:
Expand All @@ -248,8 +220,6 @@ workflows:
- linux-python-39
- linux-python-38
- linux-python-38-oldest
- linux-python-310-signac-16
- linux-python-310-signac-15
nightly:
triggers:
- schedule:
Expand All @@ -260,7 +230,6 @@ workflows:
- master
jobs:
- linux-python-310-signac-latest
# - linux-python-310-signac-next
- test-install-pip-python-310
- test-install-pip-python-39
- test-install-pip-python-38
Expand Down
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Version 0.23

[0.23.0] -- 20xx-xx-xx

Changed
+++++++

- Require ``signac`` version 1.8.0 (#693).
- Deprecated ``alias`` CLI argument to ``flow init`` (#693).

Fixed
+++++

Expand Down
2 changes: 1 addition & 1 deletion doc/doc-project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class DocumentationProject(flow.FlowProject):


if __name__ == "__main__":
DocumentationProject.init_project("DocumentationProject").main()
DocumentationProject.init_project().main()
30 changes: 13 additions & 17 deletions flow/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from signac import get_project, init_project

from . import __version__, environment, template
from .util.misc import _deprecated_warning

logger = logging.getLogger(__name__)

Expand All @@ -28,22 +29,20 @@ def main_init(args):

The available templates are defined in the template module.
"""
if not args.alias.isidentifier():
raise ValueError(
"The alias '{}' is not a valid Python identifier and can therefore "
"not be used as a FlowProject alias.".format(args.alias)
)
try:
get_project()
except LookupError:
init_project(name=args.alias)
print(
"Initialized signac project with name '{}' in "
"current directory.".format(args.alias),
file=sys.stderr,
)
if args.alias != "":
_deprecated_warning(
deprecation="alias",
alternative="",
deprecated_in="0.23.0",
removed_in="0.24.0",
)
init_project()
print("Initialized signac project in current directory.", file=sys.stderr)
try:
return template.init(alias=args.alias, template=args.template)
return template.init(template=args.template)
except OSError as error:
raise RuntimeError(
f"Error occurred while trying to initialize a flow project: {error}"
Expand Down Expand Up @@ -120,11 +119,8 @@ def main():
"alias",
type=str,
nargs="?",
default="project",
help="Name of the FlowProject module to initialize. "
"This name will also be used to initialize a signac project if "
"no signac project was initialized prior to calling 'init'. "
"Default value: 'project'.",
default="",
help="Unused, will be removed in flow 0.24.0.",
)
parser_init.add_argument(
"-t",
Expand Down
13 changes: 6 additions & 7 deletions flow/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
{template_dir}

All template variables can be placed within a template using the standard jinja2
syntax, e.g., the project root directory can be written as: {{{{ project.root_directory() }}}}.
syntax, e.g., the project root directory can be written as: {{{{ project.path }}}}.
The available template variables are:
{template_vars}

Expand Down Expand Up @@ -984,9 +984,8 @@ def _generate_id(self, aggregate, operation_name=None):
else:
op_string = operation_name

root_directory = project.root_directory()
aggregate_id = get_aggregate_id(aggregate)
full_name = f"{root_directory}%{aggregate_id}%{op_string}"
full_name = f"{project.path}%{aggregate_id}%{op_string}"
# The job_op_id is a hash computed from the unique full name.
job_op_id = md5(full_name.encode("utf-8")).hexdigest()

Expand Down Expand Up @@ -1569,7 +1568,7 @@ def decorated(*jobs):
with jobs[0] as job:
if getattr(func, "_flow_cmd", False):
return (
f'trap "cd $(pwd)" EXIT && cd {job.ws} && {func(job)}'
f'trap "cd $(pwd)" EXIT && cd {job.path} && {func(job)}'
)
else:
return func(job)
Expand Down Expand Up @@ -1761,7 +1760,7 @@ def __init__(self, config=None, environment=None, entrypoint=None):
# the project root directory. This directory may be specified with the 'template_dir'
# configuration variable.
self._template_dir = os.path.join(
self.root_directory(), self._config.get("template_dir", "templates")
self.path, self._config.get("template_dir", "templates")
)
self._template_environment_ = {}

Expand Down Expand Up @@ -2134,7 +2133,7 @@ def _alias(cls, name):

def _fn_bundle(self, bundle_id):
"""Return the canonical name to store bundle information."""
return os.path.join(self.root_directory(), ".bundles", bundle_id)
return os.path.join(self.path, ".bundles", bundle_id)

def _store_bundled(self, operations):
"""Store operation-ids as part of a bundle and return bundle id.
Expand Down Expand Up @@ -4838,7 +4837,7 @@ def _main_run(self, args):

if args.switch_to_project_root:
with _add_cwd_to_environment_pythonpath():
with _switch_to_directory(self.root_directory()):
with _switch_to_directory(self.path):
run()
else:
run()
Expand Down
6 changes: 3 additions & 3 deletions flow/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

TEMPLATES = {
"minimal": [
("{alias}.py", "project_minimal.pyt"),
("project.py", "project_minimal.pyt"),
],
"example": [
("{alias}.py", "project_example.pyt"),
("project.py", "project_example.pyt"),
],
"testing": [
("{alias}.py", "project_testing.pyt"),
("project.py", "project_testing.pyt"),
],
}

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
signac>=1.3.0
signac>=1.8.0
jinja2>=3.0.0
cloudpickle>=1.6.0
deprecation>=2.0.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

requirements = [
# The core package.
"signac>=1.3.0",
"signac>=1.8.0",
# For the templated generation of (submission) scripts.
"jinja2>=3.0.0",
# To enable the parallelized execution of operations across processes.
Expand Down
6 changes: 2 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ def setUp(self, request):
MockScheduler.reset()
self._tmp_dir = tempfile.TemporaryDirectory(prefix="signac-flow_")
request.addfinalizer(self._tmp_dir.cleanup)
self.project = self.project_class.init_project(
name="FlowTestProject", root=self._tmp_dir.name
)
self.project = self.project_class.init_project(root=self._tmp_dir.name)
self.cwd = os.getcwd()

def switch_to_cwd(self):
Expand Down Expand Up @@ -134,7 +132,7 @@ def call_subcmd(self, subcmd, stderr=subprocess.DEVNULL):
_cmd = f"python {fn_script} {subcmd}"
try:
with _add_path_to_environment_pythonpath(os.path.abspath(self.cwd)):
with _switch_to_directory(self.project.root_directory()):
with _switch_to_directory(self.project.path):
return subprocess.check_output(_cmd.split(), stderr=stderr)
except subprocess.CalledProcessError as error:
print(error, file=sys.stderr)
Expand Down
2 changes: 1 addition & 1 deletion tests/define_status_test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def b_is_even(job):
@_TestProject.pre(b_is_even)
@_TestProject.post.isfile("world.txt")
def op1(job):
return f'echo "hello" > {job.ws}/world.txt'
return f'echo "hello" > {job.path}/world.txt'


@group1
Expand Down
2 changes: 1 addition & 1 deletion tests/define_test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def b_is_even(job):
@_TestProject.pre(b_is_even)
@_TestProject.post.isfile("world.txt")
def op1(job):
return f'echo "hello" > {job.ws}/world.txt'
return f'echo "hello" > {job.path}/world.txt'


def _need_to_fork(job):
Expand Down
2 changes: 1 addition & 1 deletion tests/extract_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def main(args):
else:
return

p = signac.init_project(name=gen.STATUS_OPTIONS_PROJECT_NAME, root=PROJECT_DIR)
p = signac.init_project(root=PROJECT_DIR)
p.import_from(origin=gen.ARCHIVE_PATH)


Expand Down
2 changes: 1 addition & 1 deletion tests/extract_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def main(args):
else:
return

p = signac.init_project(name=gen.PROJECT_NAME, root=PROJECT_DIR)
p = signac.init_project(root=PROJECT_DIR)
p.import_from(origin=gen.ARCHIVE_DIR)


Expand Down
2 changes: 1 addition & 1 deletion tests/generate_status_reference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def main(args):
) as status_pr:
init(p)
init_status_options(status_pr)
fp = _TestProject.get_project(root=p.root_directory())
fp = _TestProject.get_project(root=p.path)
env = flow.environment.TestEnvironment
# We need to set the scheduler manually. The FakeScheduler
# won't try to call any cluster executable (e.g. squeue)
Expand Down
10 changes: 5 additions & 5 deletions tests/generate_template_reference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ def _store_bundled(self, operations):
def get_masked_flowproject(p, environment=None):
"""Mock environment-dependent attributes and functions. Need to mock
sys.executable before the FlowProject is instantiated, and then modify the
root_directory and project_dir elements after creation."""
path and project_dir elements after creation."""
try:
old_executable = sys.executable
sys.executable = MOCK_EXECUTABLE
fp = TestProject.get_project(root=p.root_directory())
fp = TestProject.get_project(root=p.path)
if environment is not None:
fp._environment = environment
fp._entrypoint.setdefault("path", "generate_template_reference_data.py")
Expand All @@ -190,10 +190,10 @@ def wrapped_generate_id(self, aggregate, *args, **kwargs):
mocking has to happen within this method to avoid affecting other
methods called during the test that access the project root directory.
"""
old_root_directory = fp.root_directory
fp.root_directory = lambda: PROJECT_DIRECTORY
old_path = fp.path
fp._path = PROJECT_DIRECTORY
operation_id = old_generate_id(self, aggregate, *args, **kwargs)
fp.root_directory = old_root_directory
fp._path = old_path
return operation_id

flow.project.FlowGroup._generate_id = wrapped_generate_id
Expand Down
2 changes: 1 addition & 1 deletion tests/interactive_template_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Project(flow.FlowProject):
with signac.TemporaryProject() as tmp_project:
for i in range(num_jobs):
tmp_project.open_job(dict(foo=i)).init()
flow_project = Project.get_project(root=tmp_project.root_directory())
flow_project = Project.get_project(root=tmp_project.path)
flow_project._entrypoint.setdefault("path", entrypoint)

partition = ""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def test_evaluate_directive_valid_job(
self, available_directives_list, non_default_directive_values
):
_tmp_dir = TemporaryDirectory(prefix="flow-directives_")
FlowProject.init_project(name="DirectivesTest", root=_tmp_dir.name)
FlowProject.init_project(root=_tmp_dir.name)
project = FlowProject.get_project(root=_tmp_dir.name)
for i in range(5):
project.open_job(dict(i=i)).init()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setup_project_subprocess_execution(project, stderr_output=sys.stderr):
Optionally capture stderr with a passed in output or by default output to stderr like normal.
"""
with _add_cwd_to_environment_pythonpath(), _switch_to_directory(
project.root_directory()
project.path
), redirect_stderr(stderr_output):
yield

Expand Down Expand Up @@ -349,7 +349,7 @@ class A(FlowProject):

@A.operation(with_job=True)
def test_context(job):
assert os.path.realpath(os.getcwd()) == os.path.realpath(job.ws)
assert os.path.realpath(os.getcwd()) == os.path.realpath(job.path)

project = self.mock_project(A)
with setup_project_subprocess_execution(project):
Expand Down Expand Up @@ -2297,7 +2297,7 @@ def call_subcmd(self, subcmd, stderr=subprocess.DEVNULL):
_cmd = f"python {fn_script} {subcmd} --debug"
with _add_path_to_environment_pythonpath(os.path.abspath(self.cwd)):
try:
with _switch_to_directory(self.project.root_directory()):
with _switch_to_directory(self.project.path):
return subprocess.check_output(_cmd.split(), stderr=stderr)
except subprocess.CalledProcessError as error:
print(error, file=sys.stderr)
Expand Down Expand Up @@ -2452,7 +2452,7 @@ def call_subcmd(self, subcmd, stderr=subprocess.STDOUT):
_cmd = f"python {fn_script} {subcmd} --debug"
with _add_path_to_environment_pythonpath(os.path.abspath(self.cwd)):
try:
with _switch_to_directory(self.project.root_directory()):
with _switch_to_directory(self.project.path):
return subprocess.check_output(_cmd.split(), stderr=stderr)
except subprocess.CalledProcessError as error:
return str(error.output)
Expand Down
Loading