Skip to content

Commit

Permalink
Merge pull request #312 from Anaconda-Platform/projectignore
Browse files Browse the repository at this point in the history
Do not create projectignore if gitignore is present
  • Loading branch information
mcg1969 committed Feb 10, 2021
2 parents d3a2e29 + 096622e commit 7db5338
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
7 changes: 5 additions & 2 deletions anaconda_project/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def _load_ignore_file(project_directory, frontend):

def _git_ignored_files(project_directory, frontend):
if not os.path.exists(os.path.join(project_directory, ".git")):
if os.path.exists(os.path.join(project_directory, ".gitignore")):
frontend.error(
"Warning: the .gitignore file is being ignored because this directory is not a Git repository.")
return []

# It is pretty involved to parse .gitignore correctly. Lots of
Expand Down Expand Up @@ -215,9 +218,9 @@ def _enumerate_archive_files(project_directory, frontend, requirements):
if git_filter is None or ignore_file_filter is None:
return None

plugin_patterns = set()
plugin_patterns = {'/anaconda-project-local.yml'}
for req in requirements:
plugin_patterns = plugin_patterns.union(req.ignore_patterns)
plugin_patterns.update(req.ignore_patterns)
plugin_patterns = [_FilePattern(s) for s in plugin_patterns]

def is_plugin_generated(info):
Expand Down
23 changes: 14 additions & 9 deletions anaconda_project/projectignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@
import codecs

_default_projectignore = """
# project-local contains your personal configuration choices and state
/anaconda-project-local.yml
# This file contains a list of match patterns that instructs
# anaconda-project to exclude certain files or directories when
# building a project archive. The file format is a simplfied
# version of Git's .gitignore file format. In fact, if the
# project is hosted in a Git repository, these patterns can be
# merged into the .gitignore file and this file removed.
# See the anaconda-project documentation for more details.
# Files autocreated by Python
__pycache__/
# Python caching
*.pyc
*.pyo
*.pyd
*.pyo
__pycache__/
# Notebook stuff
# Jupyter & Spyder stuff
.ipynb_checkpoints/
# Spyder stuff
.Trash-*/
/.spyderproject
""".lstrip()


def add_projectignore_if_none(project_directory):
"""Add .projectignore if not found in project directory."""
filename = os.path.join(project_directory, ".projectignore")
if not os.path.exists(filename):
gfilename = os.path.join(project_directory, ".gitignore")
if not os.path.exists(filename) and not os.path.exists(gfilename):
try:
with codecs.open(filename, 'w', 'utf-8') as f:
f.write(_default_projectignore)
Expand Down
7 changes: 3 additions & 4 deletions anaconda_project/test/test_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def check(dirname):

pattern_strings = [pattern.pattern for pattern in patterns]

assert pattern_strings == [
assert set(pattern_strings) == {
'bar', '/baz', 'whitespace_surrounding', 'foo # this comment will be part of the pattern',
'#patternwithhash', 'hello'
]
}

with_directory_contents(
{
Expand Down Expand Up @@ -99,8 +99,7 @@ def check(dirname):
pattern_strings = [pattern.pattern for pattern in patterns]

assert pattern_strings == [
'/anaconda-project-local.yml', '__pycache__/', '*.pyc', '*.pyo', '*.pyd', '.ipynb_checkpoints/',
'/.spyderproject'
'*.pyc', '*.pyd', '*.pyo', '__pycache__/', '.ipynb_checkpoints/', '.Trash-*/', '/.spyderproject'
]

with_directory_contents(dict(), check)
Expand Down
20 changes: 3 additions & 17 deletions anaconda_project/test/test_project_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3785,14 +3785,7 @@ def check(dirname):
assert os.path.exists(archivefile)
_assert_tar_contains(
archivefile,
[
'.projectignore',
'a/b/c/d.py',
'a/b/c/e.py',
'emptydir',
'foo.py',
'anaconda-project.yml' # , 'anaconda-project-local.yml'
])
['.projectignore', 'a/b/c/d.py', 'a/b/c/e.py', 'emptydir', 'foo.py', 'anaconda-project.yml'])

# overwriting should work
status = project_ops.archive(project, archivefile)
Expand All @@ -3801,14 +3794,7 @@ def check(dirname):
assert os.path.exists(archivefile)
_assert_tar_contains(
archivefile,
[
'.projectignore',
'a/b/c/d.py',
'a/b/c/e.py',
'emptydir',
'foo.py',
'anaconda-project.yml' # , 'anaconda-project-local.yml'
])
['.projectignore', 'a/b/c/d.py', 'a/b/c/e.py', 'emptydir', 'foo.py', 'anaconda-project.yml'])

with_directory_contents_completing_project_file(
{
Expand Down Expand Up @@ -3985,7 +3971,7 @@ def check(dirname):

assert status
assert os.path.exists(archivefile)
_assert_zip_contains(archivefile, ['foo.py', '.gitignore', 'anaconda-project.yml', '.projectignore'])
_assert_zip_contains(archivefile, ['foo.py', '.gitignore', 'anaconda-project.yml'])

with_directory_contents_completing_project_file(
_add_empty_git({
Expand Down
13 changes: 11 additions & 2 deletions docs/source/user-guide/tasks/create-project-archive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ files, you might not want to include those either.

The ``anaconda-project archive`` command automatically omits the
files that Project can reproduce automatically, which includes
the ``envs/default`` directory and any downloaded data.
the ``envs/default`` directory and any downloaded data. It also
excludes ``anaconda-project-local.yml``, which is intended to
hold local configuration state only.

To manually exclude any other files that you do not want to be
in the archive, create a ``.projectignore`` file.
in the archive, create a ``.projectignore`` file or a
``.gitignore`` file.

.. note::

If you anticipate that this project will be managed as a Git
repository, use of ``.gitignore`` is preferred over
``.projectignore``. However, use of ``.gitignore`` outside
of a Git repository is not supported.

Creating the archive file
=========================
Expand Down

0 comments on commit 7db5338

Please sign in to comment.