Skip to content

Commit

Permalink
Merge pull request #50 from ferraith/feature/drop_parent_init_files
Browse files Browse the repository at this point in the history
Dropped generation of __init__.py files in parent folders
  • Loading branch information
ferraith authored Jan 27, 2019
2 parents dcb0b8c + 6a20e0f commit 97285db
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
### Added
- Python 3.7 support.
- Equality comparison and hashing of grammars.
### Removed
- Generation of parent Python packages.

## [0.3.0] - 2018-07-29
### Changed
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
coveralls
pytest
pytest>=3.6
pytest-cov
twine
wheel
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
]
},
python_requires='>=3.5',
tests_require=['pytest'],
tests_require=['pytest>=3.6'],
setup_requires=pytest_runner_opt + setuptools_lint_opt + flake8_opt,
url='https://github.com/ferraith/setuptools-antlr',
license='MIT',
Expand Down
9 changes: 1 addition & 8 deletions setuptools_antlr/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,9 @@ def run(self):
else:
distutils.log.info('generating {} parser -> {}'.format(grammar.name, package_dir))

# create Python package including parent packages if don't exist
# create Python package if don't exist
self._create_init_file(package_dir)

base_dir = pathlib.Path('.').resolve()
parent_dir = package_dir.resolve().parent

while base_dir < parent_dir:
self._create_init_file(parent_dir)
parent_dir = parent_dir.parent

# call ANTLR for parser generation
result = subprocess.run(run_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True, cwd=str(grammar_dir))
Expand Down
18 changes: 5 additions & 13 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,19 +780,16 @@ def test_run_package_not_exists(self, mock_find_grammars, mock_run, mock_find_an
mock_run.return_value = unittest.mock.Mock(returncode=0)

base_dir = str(tmpdir.mkdir('base'))
parent_dir = pathlib.Path(base_dir, 'parent')
package_dir = pathlib.Path(parent_dir, 'some_grammar')
package_dir = pathlib.Path(base_dir, 'some_grammar')

package_init_file = pathlib.Path(package_dir, '__init__.py')
parent_init_file = pathlib.Path(parent_dir, '__init__.py')

command.output['default'] = parent_dir
command.output['default'] = base_dir
os.chdir(str(base_dir))

command.run()

assert package_init_file.exists()
assert parent_init_file.exists()

@unittest.mock.patch('setuptools_antlr.command.find_java')
@unittest.mock.patch.object(AntlrCommand, '_find_antlr')
Expand All @@ -810,23 +807,18 @@ def test_run_package_exists(self, mock_find_grammars, mock_run, mock_find_antlr,
mock_run.return_value = unittest.mock.Mock(returncode=0)

base_dir = str(tmpdir.mkdir('base'))
parent_dir = pathlib.Path(base_dir, 'parent')
package_dir = pathlib.Path(parent_dir, 'some_grammar')
package_dir.mkdir(parents=True)
package_dir = pathlib.Path(base_dir, 'some_grammar')
package_dir.mkdir()

package_init_file = pathlib.Path(package_dir, '__init__.py')
package_init_file.touch()
parent_init_file = pathlib.Path(parent_dir, '__init__.py')
parent_init_file.touch()

origin_package_init_mtime_ns = package_init_file.stat().st_mtime_ns
origin_parent_init_mtime_ns = parent_init_file.stat().st_mtime_ns

command.output['default'] = parent_dir
command.output['default'] = base_dir
command.run()

assert package_init_file.stat().st_mtime_ns == origin_package_init_mtime_ns
assert parent_init_file.stat().st_mtime_ns == origin_parent_init_mtime_ns

@unittest.mock.patch('setuptools_antlr.command.find_java')
@unittest.mock.patch.object(AntlrCommand, '_find_antlr')
Expand Down

0 comments on commit 97285db

Please sign in to comment.