Git Product home page Git Product logo

google-apputils's Introduction

Google Application Utilities for Python
=======================================

This project is a small collection of utilities for building Python
applications.  It includes some of the same set of utilities used to build and
run internal Python apps at Google.

Features:

  * Simple application startup integrated with python-gflags.
  * Subcommands for command-line applications.
  * Option to drop into pdb on uncaught exceptions.
  * Helper functions for dealing with files.
  * High-level profiling tools.
  * Timezone-aware wrappers for datetime.datetime classes.
  * Improved TestCase with the same methods as unittest2, plus helpful flags for
    test startup.
  * google_test setuptools command for running tests.
  * Helper module for creating application stubs.


Installation
============

To install the package, simply run:
  python setup.py install


Google-Style Tests
==================

Google-style tests (those run with basetest.main()) differ from setuptools-style
tests in that test modules are designed to be run as __main__. Setting up your
project to use Google-style tests is easy:

1. Create one or more test modules named '*_test.py' in a directory. Each test
module should have a main block that runs basetest.main():
  # In tests/my_test.py
  from google.apputils import basetest

  class MyTest(basetest.TestCase):
    def testSomething(self):
      self.assertTrue('my test')

  if __name__ == '__main__':
    basetest.main()

2. Add a setup requirement on google-apputils and set the test_dir option:
  # In setup.py
  setup(
      ...
      setup_requires = ['google-apputils>=0.2'],
      test_dir = 'tests',
      )

3. Run your tests:
  python setup.py google_test


Google-Style Stub Scripts
=========================

Google-style binaries (run with app.run()) are intended to be executed directly
at the top level, so you should not use a setuptools console_script entry point
to point at your main(). You can use distutils-style scripts if you want.

Another alternative is to use google.apputils.run_script_module, which is a
handy wrapper to execute a module directly as if it were a script:

1. Create a module like 'stubs.py' in your project:
  # In my/stubs.py
  from google.apputils import run_script_module

  def RunMyScript():
    import my.script
    run_script_module.RunScriptModule(my.script)

  def RunMyOtherScript():
    import my.other_script
    run_script_module.RunScriptModule(my.other_script)

2. Set up entry points in setup.py that point to the functions in your stubs
module:
  # In setup.py
  setup(
      ...
      entry_points = {
          'console_scripts': [
              'my_script = my.stubs:RunMyScript',
              'my_other_script = my.stubs.RunMyOtherScript',
              ],
          },
      )

There are also useful flags you can pass to your scripts to help you debug your
binaries; run your binary with --helpstub to see the full list.

google-apputils's People

Contributors

craigcitro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

google-apputils's Issues

Bad permissions on google_apputils.egg-info

ls -la google_apputils.egg-info
total 56
drwxr-x---   9 schwehr  eng   306 Feb 29  2012 .
drwxr-x---  11 schwehr  eng   374 Feb 29  2012 ..
-rw-r-----   1 schwehr  eng   247 Feb 29  2012 PKG-INFO
-rw-r-----   1 schwehr  eng  1032 Feb 29  2012 SOURCES.txt
-rw-r-----   1 schwehr  eng     1 Feb 29  2012 dependency_links.txt
-rw-r-----   1 schwehr  eng   175 Feb 29  2012 entry_points.txt
-rw-r-----   1 schwehr  eng    23 Feb 29  2012 namespace_packages.txt
-rw-r-----   1 schwehr  eng    53 Feb 29  2012 requires.txt
-rw-r-----   1 schwehr  eng     7 Feb 29  2012 top_level.txt


Missing r-x and r-- for dir and files.  So python's install process can write 
into a tree as one user (e.g. root) and block other setup.py's from working.



What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?


bigquery-2.0.12/table_formatter.py
sudo -u fink-bld [ENV] sh -c /tmp/fink.4ugD2
perl -pi -e "s/'google-api-python-client==.*',//" setup.py
perl -pi -e "s/'oauth2client==.*',//" setup.py
/sw/bin/python2.7 setup.py build
Traceback (most recent call last):
  File "setup.py", line 22, in <module>
    use_setuptools()
  File "/sw/src/fink.build/bigquery-py27-2.0.12-1/bigquery-2.0.12/ez_setup.py", line 74, in use_setuptools
    import pkg_resources
  File "/sw/lib/python2.7/site-packages/pkg_resources.py", line 2825, in <module>
    add_activation_listener(lambda dist: dist.activate())
  File "/sw/lib/python2.7/site-packages/pkg_resources.py", line 710, in subscribe
    callback(dist)
  File "/sw/lib/python2.7/site-packages/pkg_resources.py", line 2825, in <lambda>
    add_activation_listener(lambda dist: dist.activate())
  File "/sw/lib/python2.7/site-packages/pkg_resources.py", line 2257, in activate
    self.insert_on(path)
  File "/sw/lib/python2.7/site-packages/pkg_resources.py", line 2364, in insert_on
    self.check_version_conflict()
  File "/sw/lib/python2.7/site-packages/pkg_resources.py", line 2401, in check_version_conflict
    nsp = dict.fromkeys(self._get_metadata('namespace_packages.txt'))
  File "/sw/lib/python2.7/site-packages/pkg_resources.py", line 2251, in _get_metadata
    for line in self.get_metadata_lines(name):
  File "/sw/lib/python2.7/site-packages/pkg_resources.py", line 1219, in get_metadata_lines
    return yield_lines(self.get_metadata(name))
  File "/sw/lib/python2.7/site-packages/pkg_resources.py", line 1211, in get_metadata
    return self._get(self._fn(self.egg_info,name))
  File "/sw/lib/python2.7/site-packages/pkg_resources.py", line 1326, in _get
    stream = open(path, 'rb')
IOError: [Errno 13] Permission denied: 
'/sw/lib/python2.7/site-packages/google_apputils-0.3.0-py2.7.egg-info/namespace_
packages.txt'
### execution of /sw/bin/python2.7 failed, exit code 1
### execution of /tmp/fink.4ugD2 failed, exit code 1

What version of the product are you using? On what operating system?

fink mac osx 10.8

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 15 May 2013 at 9:37

__init__.py needs declare_namespace

What steps will reproduce the problem?
1. Install distribute and pip directly:
sudo bash -c "wget -O - http://python-distribute.org/distribute_setup.py | 
python"
sudo bash -c "wget -O - 
https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python"
2. 'pip install google-apputils'
3. Get a warning:
Running setup.py install for google-apputils
    WARNING: google is a namespace package, but its __init__.py does
    not declare_namespace(); setuptools 0.7 will REQUIRE this!
    (See the setuptools manual under "Namespace Packages" for details.)

    WARNING: google.apputils is a namespace package, but its __init__.py does
    not declare_namespace(); setuptools 0.7 will REQUIRE this!
    (See the setuptools manual under "Namespace Packages" for details.)

What is the expected output? What do you see instead?
No warnings.

What version of the product are you using? On what operating system?
Ubuntu 10.04

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 28 Mar 2012 at 12:44

python3 support

Fails to build with python3. 2to3 works. Not sure if it's output is backwards compatible.

Provide a migration strategy from google-apputils to absl-py

https://pypi.python.org/pypi/absl-py/ (https://github.com/abseil/abseil-py) replaces this library. We need to document the migration strategy.

Also consider if there is even more we could do such as having google-apputils depend on absl-py or even push a version implemented on top of it? Though it'd be a lot better to not provide such a crutch and just reach out to anything with a google-apputils dep to have them update to absl-py directly.

Debian packaging

It would be nice to have the bits necessary to build Debian package included in 
the tree, similar to how python-gflags does it.

I've attached a patch that will accomplish this.  I may submit this package to 
Debian proper at some point.

(the end result of this should be a debian directory inside your source tree)

Original issue reported on code.google.com by [email protected] on 7 Sep 2010 at 11:17

Attachments:

Move to Git?

Just became an Xoogler, but still loving this library and using it in my new 
project. Currently, I'm including it as a submodule in Git, and in order to do 
that I need this package to be available in a Git repo.

I've just forked it to https://github.com/grow/google-apputils-python on 
GitHub, and I'll try to keep it up to date, however, it'd obviously be best if 
it were maintained by Google. :)

Any chance we could see this on https://github.com/google, or at least as a Git 
project on Project Hosting? Thanks, feel free to close this issue if not, and 
I'll just maintain my fork.

Original issue reported on code.google.com by [email protected] on 23 Sep 2013 at 11:39

python-dateutil version restriction

I don't think python-dateutil<2 restriction is necessary anymore, we use 
version 2.2 with Python 2.x just fine.

Additionally the restriction prevents us from installing upstream version of 
google-apputils-python.

Original issue reported on code.google.com by [email protected] on 30 Sep 2014 at 1:26

Transferring mox?

Kind of off topic, but it seems mox hasn't been transferred yet. Is that planned to happen at some point?

[google_test] Trying to access flag test_tmpdir before flags were parsed.

Running:

(venv) $ python setup.py google_test

I get a lot of messages like this:

Testing resources_test
/path/to/google-apputils/google/apputils/basetest.py:1617: RuntimeWarning: Trying to access flag test_tmpdir before flags were parsed. This will raise an exception in the future.
  if not os.path.isdir(FLAGS.test_tmpdir):
ERROR:root:Trying to access flag test_tmpdir before flags were parsed.
Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/gflags/flagvalues.py", line 535, in __getattr__
    raise exceptions.UnparsedFlagAccessError(error_message)
UnparsedFlagAccessError: Trying to access flag test_tmpdir before flags were parsed

After cloning I installed google-apputils in a virtualenv with:

(venv) $ python setup.py install

then ran the google_test command.

I only want to run the unit tests and see them pass or fail.

Do not install ez_setup.py with google-apputils-python

What steps will reproduce the problem?
1. do a proper install of the tool with find
2. ez_setup.py gets installed in /sw/bin/  ACK!
3.

What is the expected output? What do you see instead?

scripts in setup.py should not contain files from other modules

https://code.google.com/p/google-apputils-python/source/browse/trunk/setup.py#56

please delete this line: 
   scripts=["ez_setup.py"],

What version of the product are you using? On what operating system?

writing dependency_links to google_apputils.egg-info/dependency_links.txt
writing entry points to google_apputils.egg-info/entry_points.txt
reading manifest file 'google_apputils.egg-info/SOURCES.txt'
writing manifest file 'google_apputils.egg-info/SOURCES.txt'
Copying google_apputils.egg-info to 
/sw/src/fink.build/root-google-apputils-py27-0.3.0-1/sw/lib/python2.7/site-packa
ges/google_apputils-0.3.0-py2.7.egg-info
Installing 
/sw/src/fink.build/root-google-apputils-py27-0.3.0-1/sw/lib/python2.7/site-packa
ges/google_apputils-0.3.0-py2.7-nspkg.pth
running install_scripts
creating /sw/src/fink.build/root-google-apputils-py27-0.3.0-1/sw/bin
copying build/scripts-2.7/ez_setup.py -> 
/sw/src/fink.build/root-google-apputils-py27-0.3.0-1/sw/bin
changing mode of 
/sw/src/fink.build/root-google-apputils-py27-0.3.0-1/sw/bin/ez_setup.py to 755
sudo -u fink-bld [ENV] sh -c /tmp/fink.2KV27
/bin/rm -f /sw/src/fink.build/root-google-apputils-py27-0.3.0-1/sw/info/dir 
/sw/src/fink.build/root-google-apputils-py27-0.3.0-1/sw/info/dir.old 
/sw/src/fink.build/root-google-apputils-py27-0.3.0-1/sw/share/info/dir 
/sw/src/fink.build/root-google-apputils-py27-0.3.0-1/sw/share/info/dir.old
Reverting ownership of install dir to root
- Depends line is: python27, gflags-py27, darwin (>= 12-1)
Writing control file...
Writing md5sums file...
Validating .deb dir /sw/src/fink.build/root-google-apputils-py27-0.3.0-1...
Error: File in a language-versioned package is neither versioned nor in a 
versioned directory.
    Offending file: /sw/bin/ez_setup.py

Original issue reported on code.google.com by [email protected] on 15 May 2013 at 9:32

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.